How to Load a scikit-learn Model from MLflow with mlflow.sklearn.load_model
mlflow.pyfunc.load_model gives every model the same plain interface. When you need the scikit-learn model itself, to read its coefficients, call predict_proba or train it further, mlflow.sklearn.load_model loads it back as exactly the object you logged. This guide does it, with real output from MLflow 3.18.0.
Syntax
model = mlflow.sklearn.load_model(model_uri)
| Part | What it means |
|---|---|
model_uri | Where the model is, such as models:/<model ID> |
model | The scikit-learn estimator or pipeline that was logged, with all its methods and attributes |
Prerequisites
- An MLflow tracking server at
http://127.0.0.1:8080. MLflow's tracking server guide shows how to start one. mlflowandscikit-learnin your project, for example withuv add mlflow scikit-learn pandas.
Step 1: Log a Model to Load
This script logs a linear regression on scikit-learn's diabetes data into the experiment named on the command line, and prints its URI:
import sys
import mlflow
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression
mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment(sys.argv[1])
X, y = load_diabetes(return_X_y=True, as_frame=True)
model = LinearRegression().fit(X, y)
with mlflow.start_run():
model_info = mlflow.sklearn.log_model(model, name="diabetes-model", input_example=X.head(3))
print("Model URI:", model_info.model_uri)
uv run python log_diabetes_model.py sklearn-load-demo
🏃 View run unique-cat-286 at: http://127.0.0.1:8080/#/experiments/13/runs/71a5514f407946449891ff731274a879
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/13
Model URI: models:/m-2c5c5398baf04025b733cbcce83ef5e0
Step 2: Load It as a scikit-learn Model
load_sklearn.py loads the model and uses something only the scikit-learn object has, its coef_ attribute, before predicting:

import sys
import mlflow
from sklearn.datasets import load_diabetes
mlflow.set_tracking_uri("http://127.0.0.1:8080")
model = mlflow.sklearn.load_model(sys.argv[1])
X, _ = load_diabetes(return_X_y=True, as_frame=True)
print(type(model).__name__)
print("bmi coefficient:", model.coef_[list(X.columns).index("bmi")].round(1))
print(model.predict(X.head(3)).round(1))
uv run python load_sklearn.py models:/m-2c5c5398baf04025b733cbcce83ef5e0
LinearRegression
bmi coefficient: 519.8
[206.1 68.1 176.9]

The loaded object is a LinearRegression, with its learned coefficients: the body mass index weighs 519.8 in this model. Its predictions match what the same model gives as a PyFuncModel.
Which Loader to Use
| You want to | Use |
|---|---|
| Predict, in code that shouldn't care which library trained the model | mlflow.pyfunc.load_model |
| Have the input checked against the model's signature first | mlflow.pyfunc.load_model |
Read attributes such as coef_ or feature_importances_, or call predict_proba | mlflow.sklearn.load_model |
The scikit-learn object is the model itself, so MLflow's signature check doesn't run on its predict.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Expecting MLflow's signature check from the scikit-learn model | scikit-learn answers instead, with its own error for a missing column: ValueError: The feature names should match those that were passed during fit. Feature names seen at fit time, yet now missing: - bmi | Use mlflow.pyfunc.load_model when you want MLflow's check |
| Passing the run's artifact path in MLflow 3 | The model isn't stored with the run's files | models:/<model ID> |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Deserializing this model is disallowed... | MLFLOW_ALLOW_MODEL_CODE_EXECUTION is false | How to Refuse to Load Untrusted Models in MLflow |
FAQ
Does it need the trusted types of a skops model?
No: MLflow reads them from the model's MLmodel file, as How to Save a scikit-learn Model in the skops Format with MLflow shows.
Can I keep training the loaded model?
It's an ordinary scikit-learn object, so calling fit on it works as usual; log the result as a new model.
Conclusion
mlflow.sklearn.load_model("models:/m-…") returned the logged LinearRegression itself: its coefficients were there, and it predicted the same values. Use it when you need the scikit-learn object, and mlflow.pyfunc.load_model when you only predict.
Additional Resources
- mlflow.sklearn —
load_model.
