Skip to content
Snippets Groups Projects
functions.py 789 B
Newer Older
  • Learn to ignore specific revisions
  • Jakub Beránek's avatar
    Jakub Beránek committed
    """
    You don't need to modify this file.
    """
    
    import json
    import random
    import time
    from pathlib import Path
    
    
    def train_model(learning_rate: float, batch_size: float, output_path: Path):
        """
        "Trains" a machine learning model using the given parameters (`learning_rate` and `batch_size`)
        and stores the result into `output_path`.
        """
        print(f"Training model using learning_rate={learning_rate} and batch_size={batch_size}")
        time.sleep(30 / batch_size)
    
        accuracy = 0.9 + (random.random() / 10)
    
        print(f"Model training finished, resulting accuracy: {accuracy}")
        with open(output_path, "w") as f:
            json.dump({
                "parameters": dict(learning_rate=learning_rate, batch_size=batch_size),
                "accuracy": accuracy
            }, f, indent=4)