.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_mlops/plot_03_tracking_cards.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 Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_10_mlops_plot_03_tracking_cards.py: Experiment tracking and model cards =================================== Comparing settings is an experiment, and experiments should leave a trace. The :class:`~mvtsa.mlops.ExperimentTracker` logs parameters, metrics, figures and models of every run to a local folder (and to MLflow when it is installed and requested). A model card documents what a model is for, how it was evaluated and where its limits are (Mitchell et al., 2019). .. GENERATED FROM PYTHON SOURCE LINES 11-27 .. code-block:: Python import tempfile from pathlib import Path import matplotlib.pyplot as plt import mvtsa as mv from mvtsa import mlops from mvtsa import segmentation as sg from mvtsa.evaluation import evaluate_segmentation X, cps, _ = mv.datasets.make_correlation_switching( n_segments=5, length=150, n_variables=4, random_state=7 ) workdir = Path(tempfile.mkdtemp()) .. GENERATED FROM PYTHON SOURCE LINES 28-30 Tracked runs ------------ .. GENERATED FROM PYTHON SOURCE LINES 30-58 .. code-block:: Python tracker = mlops.ExperimentTracker( workdir / "runs", experiment="pca-segmentation", use_mlflow=False ) for q in (1, 2, 3): with tracker.start_run(f"q={q}") as run: model = sg.PCASegmenter(n_segments=5, n_components=q) seg = model.segment(X) run.log_params(mlops.to_config(model)["params"]) run.log_metrics( { k: v for k, v in evaluate_segmentation( cps, seg, len(X), margin=8 ).items() if k in ("f1", "covering", "hausdorff") } ) fig = mv.viz.plot_segmentation(X, seg, truth=cps).figure run.log_figure(fig, "segmentation.png") plt.close(fig) runs = tracker.runs() print(runs[["name", "param.n_components", "metric.f1", "metric.covering"]]) fig, ax = plt.subplots(figsize=(4.5, 3)) ax.bar(runs["name"], runs["metric.covering"], color="#285780") ax.set_ylabel("covering") ax.set_ylim(0, 1.05) ax.set_title("tracked runs", fontsize=9, loc="left") .. image-sg:: /auto_examples/10_mlops/images/sphx_glr_plot_03_tracking_cards_001.png :alt: tracked runs :srcset: /auto_examples/10_mlops/images/sphx_glr_plot_03_tracking_cards_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none name param.n_components metric.f1 metric.covering 0 q=2 2 1.00 1.000000 1 q=3 3 0.75 0.974167 2 q=1 1 1.00 1.000000 Text(0.0, 1.0, 'tracked runs') .. GENERATED FROM PYTHON SOURCE LINES 59-61 A model card ------------ .. GENERATED FROM PYTHON SOURCE LINES 61-72 .. code-block:: Python card = mlops.model_card( sg.PCASegmenter(n_segments=5, n_components=1), name="PCA segmentation of unit 7", purpose="Detect changes of the correlation structure of four process variables.", data_description="Synthetic data with four correlation switches.", metrics={"f1": 1.0, "covering": 1.0}, limitations="Blind to pure mean shifts; assumes one latent variable.", path=workdir / "MODEL_CARD.md", ) print(card) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none # Model card: PCA segmentation of unit 7 *Generated 2026-11-29 with mvtsa 1.0.1, numpy 2.5.5, scipy 1.18.1, sklearn 1.9.1, python 3.12.16.* ## Model **Class:** `mvtsa.segmentation.latent.PCASegmenter` | Parameter | Value | |---|---| | `n_segments` | `5` | | `n_components` | `1` | | `statistic` | `Q` | | `search` | `bottomup` | | `initial_size` | `10` | | `aggregate` | `sum` | | `scale` | `True` | | `lags` | `0` | ## Intended use Detect changes of the correlation structure of four process variables. ## Data Synthetic data with four correlation switches. ## Evaluation | Metric | Value | |---|---| | f1 | 1 | | covering | 1 | ## Limitations and monitoring Blind to pure mean shifts; assumes one latent variable. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.218 seconds) .. _sphx_glr_download_auto_examples_10_mlops_plot_03_tracking_cards.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/ComplexSystemsIntelligence/mvtsa/main?urlpath=lab/tree/notebooks/auto_examples/10_mlops/plot_03_tracking_cards.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_tracking_cards.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_tracking_cards.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_tracking_cards.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_