Skip to content
Learni
View all tutorials
MLOps

How to Manage ML Experiments with MLflow in 2026

18 minINTERMEDIATE
Lire en français

Introduction

MLflow is an open source platform that simplifies the machine learning project lifecycle. In this intermediate tutorial, you will learn to track your experiments, version your models, and deploy them easily. These skills are essential for moving from a prototype to a robust MLOps system in 2026.

Prerequisites

  • Python 3.9+
  • Basic knowledge of scikit-learn or PyTorch
  • A configured virtual environment
  • Understanding of experiment tracking concepts

Installing MLflow

terminal
python -m venv mlflow-env
source mlflow-env/bin/activate
pip install mlflow scikit-learn pandas

This command creates an isolated environment and installs MLflow with the dependencies needed for tracking and model management.

Configuring the MLflow Server

terminal
mlflow ui --backend-store-uri sqlite:///mlflow.db --default-artifact-root ./artifacts --host 0.0.0.0 --port 5000

Launch the MLflow web interface with a local SQLite database and an artifacts folder. Then access http://localhost:5000 to view your runs.

Experiment Tracking Script

train.py
import mlflow
import mlflow.sklearn
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("iris-classification")

with mlflow.start_run():
    iris = load_iris()
    X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2)
    model = RandomForestClassifier(n_estimators=100, max_depth=5)
    model.fit(X_train, y_train)
    preds = model.predict(X_test)
    acc = accuracy_score(y_test, preds)
    
    mlflow.log_param("n_estimators", 100)
    mlflow.log_param("max_depth", 5)
    mlflow.log_metric("accuracy", acc)
    mlflow.sklearn.log_model(model, "model")

This complete script initializes tracking, logs hyperparameters and the accuracy metric, then saves the scikit-learn model to the MLflow registry.

Registering with the Model Registry

register_model.py
import mlflow

model_uri = "runs:/<run_id>/model"
model_version = mlflow.register_model(model_uri, "IrisClassifier")
print(f"Model registered with version {model_version.version}")

Replace with your run identifier. This step versions the model in the centralized registry to simplify future deployments.

Deploying the Model Locally

terminal
mlflow models serve -m "models:/IrisClassifier/1" -p 1234 --env-manager local

Serve version 1 of the model via a local REST API on port 1234. Then test predictions with curl or Postman.

Best Practices

  • Always use descriptive and consistent experiment names
  • Log intermediate artifacts (plots, data)
  • Use the Model Registry for all production models
  • Separate development and production environments
  • Document metadata with MLflow tags

Common Mistakes to Avoid

  • Forgetting to set the tracking URI before runs
  • Not versioning models before deployment
  • Storing overly large artifacts without a remote backend
  • Ignoring dependency management in serving environments

Going Further

Explore integration with Kubernetes and cloud deployments. Discover our complete MLOps courses.