Manual logging is easy to forget. Autologging captures params, metrics, and the model automatically — then compare dozens of runs to find the best one.
Why: manually logging every parameter is tedious and error-prone — mlflow.autolog() hooks into common frameworks and records params, metrics, and the model automatically. When: enable it once at the top of your script; it covers sklearn, PyTorch, XGBoost, and more. Where: you can still add manual logs for anything the framework does not capture.
import mlflow
mlflow.autolog() # one line — captures params, metrics, model, artifacts
mlflow.set_experiment("churn-model")
with mlflow.start_run():
model = RandomForestClassifier(max_depth=6, n_estimators=200)
model.fit(X_train, y_train) # autolog records params + training metrics
model.score(X_test, y_test) # and evaluation metricsWhy: after dozens of runs you need to find the best one programmatically, not by scrolling the UI — search_runs returns runs as a DataFrame you can filter and sort by any metric or param. When: use it to pick the best run for promotion or to analyze a sweep. Where: the same filtering powers the "compare runs" view in the UI.
import mlflow
runs = mlflow.search_runs(
experiment_names=["churn-model"],
filter_string="metrics.accuracy > 0.85",
order_by=["metrics.f1 DESC"],
)
print(runs[["run_id", "params.max_depth", "metrics.accuracy", "metrics.f1"]].head())
best_run_id = runs.iloc[0]["run_id"] # the top run, ready to registerWhy: hundreds of runs become unmanageable without structure — experiments group by project and tags label runs by branch, dataset variant, or purpose, so you can filter to exactly the set you care about. When: tag runs as you create them; retire noise by filtering, not deleting. Where: even failed runs should be logged and tagged, so a dead end is recorded rather than silently repeated.
with mlflow.start_run():
mlflow.set_tags({
"team": "fraud",
"branch": "feature/new-features",
"purpose": "hyperparam-sweep",
})
# ... train ...
# Later, filter to just this slice of work:
mlflow.search_runs(filter_string="tags.branch = 'feature/new-features'")