MLflow#

An example showing the mlflow submodule..

# Authors: The scikit-plots developers
# SPDX-License-Identifier: BSD-3-Clause

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.

# !pip install mlflow pyyaml
import scikitplot as sp

print(sp.mlflow.workflow.__doc__)
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.
('.git', 'configs', 'configs/mlflow.toml', 'Makefile', 'pyproject.toml', 'README', 'README.txt', 'README.md', 'README.rst')

Environment (best for CI)#

Default marker file-folder for auto detection Walk upward from start until a directory containing any marker is found.

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()
PosixPath('/home/circleci/repo/galleries/examples/mlflow')

๐Ÿ’ก Quiskstart Template: Beginner workflow demo#

Demo save config from default settings then customize.

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).
)
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'))

๐Ÿ› ๏ธ How to use customized settings?#

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")
๐Ÿƒ 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

Tags: model-type: classification model-workflow: model building plot-type: mlflow domain: mlflow level: beginner purpose: showcase

Total running time of the script: (0 minutes 57.996 seconds)

Related examples

Compile and run the C++ Annoy with examples

Compile and run the C++ Annoy with examples

plot_classifier_eval with examples

plot_classifier_eval with examples

Cython quickstart: compile_and_load

Cython quickstart: compile_and_load

Multi-file builds: .pxi includes and external headers

Multi-file builds: .pxi includes and external headers

Gallery generated by Sphinx-Gallery