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, logging ``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
-------
WorkflowPaths
Paths used during the workflow (project root, config dir, toml/yaml paths).
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/04/12 09:16:05 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/e55b912b5eaa4c7386826d5c40812628
🧪 View experiment at: http://127.0.0.1:8891/#/experiments/1
🏃 View run predict at: http://127.0.0.1:8891/#/experiments/1/runs/db45f7412bac49a1a4ff96848d24b43d
🧪 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/3cf41654adea4ca9be805687b1bc080b
🧪 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/8bb81c76735d4d37b93acf039d808c0c
🧪 View experiment at: http://127.0.0.1:8891/#/experiments/1
Total running time of the script: (1 minutes 7.582 seconds)
Related examples
Workflow templates (train / hpo / predict) + CLI entry template
Workflow templates (train / hpo / predict) + CLI entry template