.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/mlflow/plot_mlflow.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 or to run this example in your browser via JupyterLite or Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_mlflow_plot_mlflow.py: MLflow ========================================== .. currentmodule:: scikitplot.mlflow An example showing the :py:mod:`~scikitplot.mlflow` submodule.. .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: Python # Authors: The scikit-plots developers # SPDX-License-Identifier: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 15-20 mlflow workflow helper ---------------------- Adds a **project-level configuration** mechanism so multiple scripts (e.g., `train.py`, `hpo.py`, `predict.py`) share the exact same MLflow settings, regardless of current working directory. .. GENERATED FROM PYTHON SOURCE LINES 20-26 .. code-block:: Python # !pip install mlflow pyyaml import scikitplot as sp print(sp.mlflow.workflow.__doc__) .. rst-class:: sphx-glr-script-out .. code-block:: none Run the built-in end-to-end MLflow workflow demo. This is a small, newbie-friendly helper that: 1. Exports the library's built-in demo config (TOML or YAML) into your project. 2. Runs a small "train" logging run. 3. Optionally keeps the UI open for inspection. 4. Runs a small "predict" logging run. Parameters ---------- profile : str, default="local" Profile name inside the project config. open_ui_seconds : float, default=0.0 If > 0, sleeps for this many seconds while the session is open, printing ``ui_url``. experiment_name : str or None, default=None If provided, patches the exported config to use this experiment name. fmt : {"toml", "yaml"}, default="toml" Which built-in demo config format to export. overwrite : bool, default=False Whether to overwrite existing project config files. Returns ------- None See Also -------- run_demo The implementation used by the CLI entry point. .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python print(sp.mlflow.DEFAULT_PROJECT_MARKERS) .. rst-class:: sphx-glr-script-out .. code-block:: none ('.git', 'configs', 'configs/mlflow.toml', 'Makefile', 'pyproject.toml', 'README', 'README.txt', 'README.md', 'README.rst') .. GENERATED FROM PYTHON SOURCE LINES 31-35 Environment (best for CI) ------------------------- Default marker file-folder for auto detection Walk upward from `start` until a directory containing any marker is found. .. GENERATED FROM PYTHON SOURCE LINES 35-44 .. code-block:: Python import os # export SCIKITPLOT_PROJECT_MARKERS='[".git","pyproject.toml","README.txt","configs/mlflow.toml"]' os.environ["SCIKITPLOT_PROJECT_MARKERS"]='[".git","pyproject.toml","README.txt","configs/mlflow.toml"]' # Check ROOT or base_dir is requested sp.mlflow.find_project_root() .. rst-class:: sphx-glr-script-out .. code-block:: none PosixPath('/home/circleci/repo/galleries/examples/mlflow') .. GENERATED FROM PYTHON SOURCE LINES 45-48 ๐Ÿ’ก Quiskstart Template: Beginner workflow demo ----------------------------------------------- Demo save config from default settings then customize. .. GENERATED FROM PYTHON SOURCE LINES 48-57 .. code-block:: Python sp.mlflow.workflow( profile="local", open_ui_seconds=5, experiment_name="my-first-project", # "scikitplot-project" fmt="toml", overwrite=True, # Config already exists: ./configs/mlflow.toml (use overwrite=True). ) .. rst-class:: sphx-glr-script-out .. code-block:: none 2026/02/01 06:38:25 INFO mlflow.tracking.fluent: Experiment with name 'my-first-project' does not exist. Creating a new experiment. ๐Ÿƒ View run train at: http://127.0.0.1:8891/#/experiments/1/runs/b63ae1eeaf734339a8aa94e2676deddc ๐Ÿงช View experiment at: http://127.0.0.1:8891/#/experiments/1 ๐ŸŒ Open MLflow UI: http://127.0.0.1:8891 ๐Ÿƒ View run predict at: http://127.0.0.1:8891/#/experiments/1/runs/659c6baef44649a9bbd3631cdde7ba6f ๐Ÿงช View experiment at: http://127.0.0.1:8891/#/experiments/1 WorkflowPaths(_project_root=PosixPath('/home/circleci/repo/galleries/examples/mlflow'), _config_dir=PosixPath('/home/circleci/repo/galleries/examples/mlflow/configs'), _toml_path=PosixPath('/home/circleci/repo/galleries/examples/mlflow/configs/mlflow.toml'), _yaml_path=PosixPath('/home/circleci/repo/galleries/examples/mlflow/configs/mlflow.yaml')) .. GENERATED FROM PYTHON SOURCE LINES 58-60 ๐Ÿ› ๏ธ How to use customized settings? ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-88 .. code-block:: Python import time import scikitplot as sp ROOT = sp.mlflow.find_project_root(config_path=None) with sp.mlflow.session_from_file(ROOT / "configs/mlflow.toml", profile="local") as mlflow: with mlflow.start_run(): # default_run_name + default tags apply automatically mlflow.log_param("phase", "train") # Overwrite new profile, If Needed sp.mlflow.dump_project_config_yaml(source_config_path=None) # ROOT = sp.mlflow.find_project_root(config_path=None) with sp.mlflow.session_from_file(ROOT / "configs/mlflow.yaml", profile="local") as mlflow: print("Open MLflow UI:", mlflow.ui_url) # do something time.sleep(5) with sp.mlflow.session_from_file(ROOT / "configs/mlflow.yaml", profile="local") as mlflow: with mlflow.start_run(run_name="predict"): # override default name if you want mlflow.log_param("phase", "predict") .. rst-class:: sphx-glr-script-out .. code-block:: none ๐Ÿƒ View run train at: http://127.0.0.1:8891/#/experiments/1/runs/2f7c12b49cc440ff87b204b80a0ca820 ๐Ÿงช View experiment at: http://127.0.0.1:8891/#/experiments/1 Open MLflow UI: http://127.0.0.1:8891 ๐Ÿƒ View run predict at: http://127.0.0.1:8891/#/experiments/1/runs/e0075fe29e2f412caf2f7c6c8b483e45 ๐Ÿงช View experiment at: http://127.0.0.1:8891/#/experiments/1 .. GENERATED FROM PYTHON SOURCE LINES 89-97 .. tags:: model-type: classification model-workflow: model building plot-type: mlflow domain: mlflow level: beginner purpose: showcase .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 57.996 seconds) .. _sphx_glr_download_auto_examples_mlflow_plot_mlflow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-plots/scikit-plots/main?urlpath=lab/tree/notebooks/auto_examples/mlflow/plot_mlflow.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/mlflow/plot_mlflow.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mlflow.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mlflow.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_mlflow.zip ` .. include:: plot_mlflow.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_