Introduction to MLflow
Weston Bassler
Senior MLOps Engineer
train.py
mlflow.start_run()
import mlflow
# Start a run
mlflow.start_run()
<ActiveRun: >
# End a run
mlflow.end_run()
import mlflow # Set experiment mlflow.set_experiment("My Experiment") # Start a run run = mlflow.start_run()
# Print run info run.info
<RunInfo: artifact_uri='./mlruns/0/9de5df4d19994546b03dce09aefb58af/artifacts',
end_time=None, experiment_id='31', lifecycle_stage='active',
run_id='9de5df4d19994546b03dce09aefb58af', run_name='big-owl-145',
run_uuid='9de5df4d19994546b03dce09aefb58af', start_time=1676838126924,
status='RUNNING', user_id='user'>
Metrics
log_metric("accuracy", 0.90)
log_metrics({"accuracy": 0.90, "loss": 0.50})
Parameters
log_param("n_jobs", 1)
log_params({"n_jobs": 1, "fit_intercept": False})
Artifacts
log_artifact("file.py")
log_artifacts("./directory/")
import mlflow # Set Experiment mlflow.set_experiment("LR Experiment")
# Start a run mlflow.start_run()
# Model Training Code here lr = LogisticRegression(n_jobs=1) # Model evaluation Code here lr.fit(X, y) score = lr.score(X, y)
# Log a metric
mlflow.log_metric("score", score)
# Log a parameter
mlflow.log_param("n_jobs", 1)
# Log an artifact
mlflow.log_artifact("train_code.py")
Introduction to MLflow