When training runs multiply, a notebook or spreadsheet makes it hard to answer which parameters produced the best model—or to reproduce a result months later. MLflow provides a central place to track experiments, compare runs, retain artifacts, and manage model versions for deployment. section 4.1 section 9.3.4
An MLflow workflow has three connected parts:
- Track runs. Point a notebook at a tracking server, choose an experiment, and wrap each execution in a run. Log parameters, metrics, datasets, and artifacts such as plots or model files; inspect them in the UI. Supported training integrations can autolog results. section 4.1.2
- Select and register a model. Filter runs by a measured metric, retrieve the chosen run’s model URI, and register it under a model name. The registry supports versioning, collaboration, and later retrieval. section 4.1.3
- Serve the registered model. Load a selected version into a BentoML service, or use MLflow’s own serving tools to expose an inference endpoint. section 10.6 section 10.7
From an income-classifier notebook to a registered model
Start a local UI with `mlflow ui`, then set `mlflow.set_tracking_uri("http://localhost:5000")` and `mlflow.set_experiment("income-classifier")`. Use `mlflow.start_run()` while training; an earlier exploratory run can save generated plots with `mlflow.log_artifacts`. After comparing decision-tree, random-forest, and XGBoost runs, search for `metrics.roc_auc_score_test > 0.8`, order by that metric, and register the leading run’s model URI. The run ID links the selected model back to its recorded experiment. section 4.1.2 section 4.1.3
Listing 4.7 Retrieving MLflow runs and registering the model
from mlflow import MlflowClient
mlflow_client = MlflowClient()
experiment_name = "income-classifier"
experiment = mlflow_client.get_experiment_by_name(experiment_name)
run_object = mlflow_client.search_runs(
experiment_ids=experiment.experiment_id,
filter_string="metrics.roc_auc_score_test > 0.8",
max_results=1,
order_by=["metrics.roc_auc_score_test DESC"]
)[0] #1
model_uri = f"runs:/{run_object.info.run_id}/{experiment_name}" #2
mlflow.register_model(
model_uri,
"random-forest-classifier"
) #3
The client listing shows the selection-to-registry handoff: find a qualifying run, construct its `runs:/` model URI, and call `mlflow.register_model`. section 4.1.3
For a production-oriented training pipeline, keep the training and validation metrics with the model. A movie-recommender workflow logs runs, loads a model by run ID for validation, and records metrics against that run. This lineage helps investigate unexpected production behavior; TensorBoard complements MLflow when closer inspection of a single training run is needed. section 9.3.4 section 9.4
Serving choice depends on operational needs. MLflow alone can serve a registered `prod` model with `mlflow models serve -m "models:/recommender_production@prod"` or build a Docker model server. Pairing it with BentoML adds a service layer for deployment and monitoring: the service resolves the registry’s `prod` alias, imports the corresponding run model, and serves it. Prefer the simpler MLflow-only path when it meets requirements; use the combined approach when finer deployment control and monitoring matter. section 10.6 section 10.7


