Skip to main content

How to Make an MLflow Model Return Probabilities

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

Load a scikit-learn classifier from MLflow as a Python function and predict gives you labels: 0, 1, 2. For ranking, alerts or your own cut-off you usually want the probabilities. log_model(pyfunc_predict_fn="predict_proba") makes the logged model's predict return them, wherever it's loaded or served. This guide does it, with real output from MLflow 3.18.0.

Syntax​

Syntax
signature = infer_signature(X, model.predict_proba(X))
mlflow.sklearn.log_model(
sk_model, name="...", signature=signature, pyfunc_predict_fn="predict_proba"
)
PartWhat it means
pyfunc_predict_fnWhich of the model's methods the MLflow Python-function predict calls. The default is "predict"; the reference also lists "predict_proba", "predict_log_proba", "predict_joint_log_proba" and "score"
signatureInferred from predict_proba, so it describes what the model now returns

Pass the signature yourself: when MLflow infers it from an input example, it uses predict, and the signature then describes labels the model never returns (Fixed: MLflow Signature Says long for a predict_proba Model).

Prerequisites​

  • An MLflow tracking server at http://127.0.0.1:8080. MLflow's tracking server guide shows how to start one.
  • mlflow and scikit-learn in your project, for example with uv add mlflow scikit-learn pandas.

Step 1: Log the Classifier to Return Probabilities​

The example trains a logistic regression on scikit-learn's iris flowers, three species, and logs it with predict_proba as its prediction function. Then it compares scikit-learn's own predict with the logged model's:

The probabilities.py script in a macOS-style code window: it trains a LogisticRegression on iris, infers the signature from predict_proba, logs the model named iris-model with that signature and pyfunc_predict_fn set to predict_proba, then prints scikit-learn's predict and the MLflow pyfunc model's predict for two rows.

probabilities.py
import mlflow
from mlflow.models import infer_signature
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("probabilities-demo")

X, y = load_iris(return_X_y=True, as_frame=True)
model = LogisticRegression(max_iter=500).fit(X, y)

# The signature describes what the model returns: one probability per class.
signature = infer_signature(X, model.predict_proba(X))
with mlflow.start_run():
model_info = mlflow.sklearn.log_model(
model, name="iris-model", signature=signature, pyfunc_predict_fn="predict_proba"
)

rows = X.head(2)
print("scikit-learn predict:", model.predict(rows))
print("MLflow pyfunc predict:")
print(mlflow.pyfunc.load_model(model_info.model_uri).predict(rows).round(3))
Terminal
uv run python probabilities.py
Output
2026/11/21 14:12:13 INFO mlflow.tracking.fluent: Experiment with name 'probabilities-demo' does not exist. Creating a new experiment.
2026/11/21 14:12:14 INFO mlflow.utils.uv_utils: Detected uv project: found uv.lock and pyproject.toml in /Users/you/source/mlflow-demo
2026/11/21 14:12:14 INFO mlflow.utils.uv_utils: Detected uv project: found uv.lock and pyproject.toml in /Users/you/source/mlflow-demo
2026/11/21 14:12:14 INFO mlflow.utils.environment: Detected uv project at /Users/you/source/mlflow-demo. Attempting to export requirements via 'uv export'.
2026/11/21 14:12:14 INFO mlflow.utils.uv_utils: Exported 91 dependencies via uv
2026/11/21 14:12:14 INFO mlflow.utils.environment: Successfully exported 91 requirements from uv project. Skipping package capture based inference.
🏃 View run abrasive-frog-459 at: http://127.0.0.1:8080/#/experiments/7/runs/c8985731fbef496b882250fbd8527d02
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/7
scikit-learn predict: [0 0]
MLflow pyfunc predict:
[[0.982 0.018 0. ]
[0.972 0.028 0. ]]

The output of probabilities.py in a terminal: after the run's link, scikit-learn's predict gives the labels 0 0, while the MLflow pyfunc model's predict gives two rows of three probabilities, 0.982 0.018 0 and 0.972 0.028 0.

Same model, same two flowers. scikit-learn's predict says class 0 for both; the logged model's predict returns the three probabilities behind that answer, in the order of the classes, 0, 1 and 2.

Step 2: Check the MLmodel File​

Open the model from the experiment's Models tab, then Artifacts and MLmodel:

The model's Artifacts tab with MLmodel open: under the python_function flavor, predict_fn is predict_proba.

predict_fn: predict_proba under the python_function flavor is the setting every MLflow tool reads, whether it loads the model in Python or serves it over HTTP. Further down, the signature's output is a tensor of decimals, inferred from predict_proba:

MLmodel (excerpt)
outputs: '[{"type": "tensor", "tensor-spec": {"dtype": "float64", "shape": [-1,
3]}}]'

Common Mistakes​

MistakeWhat happensDo this instead
Setting pyfunc_predict_fn but letting MLflow infer the signature from an input exampleThe signature says the output is a whole number, the labelInfer the signature from predict_proba yourself
Expecting the native model to change toomlflow.sklearn.load_model returns the scikit-learn model, whose predict still returns labelsCall predict_proba on it, or load with mlflow.pyfunc.load_model

Troubleshooting​

SymptomLikely causeFix
The served or loaded model returns 0 and 1pyfunc_predict_fn wasn't set when it was loggedLog the model again with pyfunc_predict_fn="predict_proba"
UserWarning: Hint: Inferred schema contains integer column(s)... when logging a classifierThe signature was inferred from the labelsFixed: MLflow Signature Says long for a predict_proba Model

FAQ​

Can I change predict_fn for a model already logged?​

The setting is written into the model's MLmodel file when it's logged, so log the model again with the new value.

Which column is the probability of yes?​

For classes 0 and 1, the second: predictions[:, 1]. The columns follow the classifier's classes_.

Conclusion​

With pyfunc_predict_fn="predict_proba" and a signature inferred from predict_proba, the logged logistic regression returned three probabilities per flower where scikit-learn's predict gave a label, and its MLmodel file says so for every tool that loads it.

Additional Resources​