.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/technical_details/plot_skore_mlflow_project.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_technical_details_plot_skore_mlflow_project.py: .. _example_skore_mlflow_project: ==================== MLflow skore Project ==================== This example shows how to persist reports in MLflow using :class:`~skore.Project` in ``mode="mlflow"``: log reports as MLflow runs and inspect them. It uses a :class:`~skore.CrossValidationReport`, but the same approach applies to :class:`~skore.EstimatorReport`. To run this example against your own MLflow tracking server, use: .. code-block:: bash TRACKING_URI= PROJECT= python plot_skore_mlflow_project.py To try it locally, start an MLflow server with ``uvx mlflow server`` and set ``TRACKING_URI=http://127.0.0.1:5000``. .. GENERATED FROM PYTHON SOURCE LINES 24-25 First, let us build one report to persist: .. GENERATED FROM PYTHON SOURCE LINES 27-36 .. code-block:: Python from sklearn.datasets import load_iris from sklearn.ensemble import HistGradientBoostingClassifier from skore import CrossValidationReport, Project X, y = load_iris(return_X_y=True, as_frame=True) estimator = HistGradientBoostingClassifier() report = CrossValidationReport(estimator, X, y) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Then, we can push the report to the MLflow backend: .. GENERATED FROM PYTHON SOURCE LINES 38-55 .. code-block:: Python import io # MLflow/Alembic emits verbose DB initialization logs; silence them so the # example page focuses on skore usage rather than backend startup details. with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()): # This creates an MLflow experiment with name `PROJECT`: project = Project( PROJECT, mode="mlflow", tracking_uri=TRACKING_URI, ) project.put("hgb-baseline", report) .. rst-class:: sphx-glr-script-out .. code-block:: none 2026/03/12 17:28:27 WARNING mlflow.sklearn: Saving scikit-learn models in the pickle or cloudpickle format requires exercising caution because these formats rely on Python's object serialization mechanism, which can execute arbitrary code during deserialization. The recommended safe alternative is the 'skops' format. For more information, see: https://scikit-learn.org/stable/model_persistence.html 2026/03/12 17:28:32 INFO mlflow.models.model: Found the following environment variables used during model inference: [SPHINX_EXAMPLE_API_KEY]. Please check if you need to set them when deploying the model. To disable this message, set environment variable `MLFLOW_RECORD_ENV_VARS_IN_MODEL_LOGGING` to `false`. 2026/03/12 17:28:33 WARNING mlflow.sklearn: Saving scikit-learn models in the pickle or cloudpickle format requires exercising caution because these formats rely on Python's object serialization mechanism, which can execute arbitrary code during deserialization. The recommended safe alternative is the 'skops' format. For more information, see: https://scikit-learn.org/stable/model_persistence.html 2026/03/12 17:28:39 WARNING mlflow.sklearn: Saving scikit-learn models in the pickle or cloudpickle format requires exercising caution because these formats rely on Python's object serialization mechanism, which can execute arbitrary code during deserialization. The recommended safe alternative is the 'skops' format. For more information, see: https://scikit-learn.org/stable/model_persistence.html 2026/03/12 17:28:43 WARNING mlflow.sklearn: Saving scikit-learn models in the pickle or cloudpickle format requires exercising caution because these formats rely on Python's object serialization mechanism, which can execute arbitrary code during deserialization. The recommended safe alternative is the 'skops' format. For more information, see: https://scikit-learn.org/stable/model_persistence.html 2026/03/12 17:28:47 WARNING mlflow.sklearn: Saving scikit-learn models in the pickle or cloudpickle format requires exercising caution because these formats rely on Python's object serialization mechanism, which can execute arbitrary code during deserialization. The recommended safe alternative is the 'skops' format. For more information, see: https://scikit-learn.org/stable/model_persistence.html 2026/03/12 17:28:52 WARNING mlflow.sklearn: Saving scikit-learn models in the pickle or cloudpickle format requires exercising caution because these formats rely on Python's object serialization mechanism, which can execute arbitrary code during deserialization. The recommended safe alternative is the 'skops' format. For more information, see: https://scikit-learn.org/stable/model_persistence.html .. GENERATED FROM PYTHON SOURCE LINES 82-85 Note that mlflow warns us about saving models with `pickle`. Future versions of skore might rely on `skops `__ for model serialization, which will make these warnings disappear. .. GENERATED FROM PYTHON SOURCE LINES 87-89 Like for other types of projects (local, hub), you can access the summary and its DataFrame version: .. GENERATED FROM PYTHON SOURCE LINES 89-95 .. code-block:: Python import pandas as pd summary = project.summarize() pandas_summary = pd.DataFrame(summary).reset_index() pandas_summary[["id", "key", "report_type", "learner", "ml_task", "dataset"]] .. raw:: html
id key report_type learner ml_task dataset
0 a292e56a637e41febb1f2a5f9cdcea79 hgb-baseline cross-validation HistGradientBoostingClassifier multiclass-classification 8f9eb48c


.. GENERATED FROM PYTHON SOURCE LINES 96-98 The "id" column corresponds to the MLflow run ID, so you can access the MLflow run this way: .. GENERATED FROM PYTHON SOURCE LINES 98-105 .. code-block:: Python import mlflow (run_id,) = pandas_summary["id"] mlflow_run = mlflow.get_run(run_id) mlflow_run.data.metrics .. rst-class:: sphx-glr-script-out .. code-block:: none {'accuracy': 0.9466666666666667, 'accuracy_std': 0.0649786289653931, 'log_loss': 0.2822828899154286, 'log_loss_std': 0.24315920107983896, 'recall': 0.9466666666666667, 'recall_std': 0.0649786289653931, 'precision': 0.9466666666666667, 'precision_std': 0.0649786289653931, 'roc_auc': 0.9913333333333334, 'roc_auc_std': 0.009888264649460847, 'fit_time': 0.10991790380001021, 'predict_time': 0.0034695132000024387} .. GENERATED FROM PYTHON SOURCE LINES 106-107 But most importantly, this ID lets you load saved reports: .. GENERATED FROM PYTHON SOURCE LINES 107-109 .. code-block:: Python loaded_report = project.get(run_id) loaded_report.metrics.summarize().frame() .. raw:: html
HistGradientBoostingClassifier
mean std
Metric Label / Average
Accuracy 0.946667 0.064979
Precision 0 1.000000 0.000000
1 0.935065 0.062957
2 0.920280 0.133381
Recall 0 1.000000 0.000000
1 0.900000 0.173205
2 0.940000 0.054772
ROC AUC 0 1.000000 0.000000
1 0.980000 0.020917
2 0.981000 0.018841
Log loss 0.282283 0.243159
Fit time (s) 0.109918 0.028061
Predict time (s) 0.005144 0.000737


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 34.365 seconds) .. _sphx_glr_download_auto_examples_technical_details_plot_skore_mlflow_project.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_skore_mlflow_project.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_skore_mlflow_project.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_skore_mlflow_project.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_