The mlflow.sklearn module provides an API for logging and loading scikit-learn models. This module exports scikit-learn models with the following flavors:

Python (native) pickle format
This is the main flavor that can be loaded back into scikit-learn.
Produced for use by generic pyfunc-based deployment tools and batch inference.
mlflow.sklearn.load_model(path, run_id=None)

Load a scikit-learn model from a local file (if run_id is None) or a run.

  • path – Local filesystem path or run-relative artifact path to the model saved by mlflow.sklearn.save_model().
  • run_id – Run ID. If provided, combined with path to identify the model.

Load a persisted scikit-learn model as a python_function model.

Parameters:path – Local filesystem path to the model saved by mlflow.sklearn.save_model().
Return type:Pyfunc format model with function model.predict(pandas DataFrame) -> pandas DataFrame.
mlflow.sklearn.log_model(sk_model, artifact_path)

Log a scikit-learn model as an MLflow artifact for the current run.

  • sk_model – scikit-learn model to be saved.
  • artifact_path – Run-relative artifact path.
mlflow.sklearn.save_model(sk_model, path, conda_env=None, mlflow_model=<mlflow.models.Model object>)

Save a scikit-learn model to a path on the local file system.

  • sk_model – scikit-learn model to be saved.
  • path – Local path where the model is to be saved.
  • conda_env – Path to a Conda environment file. If provided, this decribes the environment this model should be run in. At minimum, it should specify python, scikit-learn, and mlflow with appropriate versions.
  • mlflow_modelmlflow.models.Model this flavor is being added to.