.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_mlops/plot_01_pipeline_registry.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_01_pipeline_registry.py: From analysis to a deployable model =================================== An analysis that should run every day has to be reproducible: the same configuration, the same preprocessing and the same learned regimes. The :class:`~mvtsa.mlops.AnalysisPipeline` standardizes the data, segments it, learns recurring regimes from the segments of the training data and labels new data with them. Every object can be written to a JSON or YAML configuration; fitted models are saved with checksums, library versions and a fingerprint of the training data, and a registry keeps their versions and stages. .. GENERATED FROM PYTHON SOURCE LINES 14-31 .. code-block:: Python import tempfile from pathlib import Path import mvtsa as mv from mvtsa import mlops from mvtsa import segmentation as sg # One process with three recurring regimes: the first half is the training # record, the second half arrives later. X, cps, states = mv.datasets.make_regime_process( n_regimes=3, n_segments=16, length=150, random_state=0 ) half = cps[7] X_train, X_new, cps_new = X[:half], X[half:], cps[8:] - half workdir = Path(tempfile.mkdtemp()) .. GENERATED FROM PYTHON SOURCE LINES 32-34 Configuration as code --------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-40 .. code-block:: Python pipe = mlops.AnalysisPipeline( sg.BottomUp("normal", n_segments=8, initial_size=15), n_regimes=3 ) cfg = mlops.to_config(pipe) print(mlops.save_config(pipe, workdir / "pipeline.yaml").read_text()) same = mlops.from_config(cfg) # an identical, unfitted pipeline .. rst-class:: sphx-glr-script-out .. code-block:: none class: mvtsa.mlops.pipeline.AnalysisPipeline params: segmenter: class: mvtsa.segmentation.search.BottomUp params: cost: normal n_segments: 8 penalty: null max_cost: null min_size: null initial_size: 15 merge_criterion: increase cost_params: null n_regimes: 3 standardize: zscore descriptor: gaussian metric: gaussian_w2 min_regime_length: 10 .. GENERATED FROM PYTHON SOURCE LINES 41-43 Fit, save, register, promote ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 43-68 .. code-block:: Python pipe.fit(X_train) seg = pipe.predict(X_new) print( "regimes of the new data:", seg.labels.tolist(), "| true regimes:", states[8:].tolist(), ) reg = mlops.ModelRegistry(workdir / "registry") v1 = reg.register( "regimes", pipe, data=X_train, metrics={"covering": 0.97}, tags={"plant": "demo"}, ) reg.promote("regimes", v1, "production") print(reg.list()[["name", "version", "stage", "created"]]) production = reg.load("regimes", stage="production") mv.viz.plot_segmentation( X_new, production.predict(X_new), truth=cps_new, title="production model on new data", ) .. image-sg:: /auto_examples/10_mlops/images/sphx_glr_plot_01_pipeline_registry_001.png :alt: production model on new data :srcset: /auto_examples/10_mlops/images/sphx_glr_plot_01_pipeline_registry_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none regimes of the new data: [1, 0, 1, 0, 1, 2, 1, 0] | true regimes: [0, 2, 0, 2, 0, 1, 0, 2] name version stage created 0 regimes 1 production 2026-11-29T08:40:35+00:00 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.071 seconds) .. _sphx_glr_download_auto_examples_10_mlops_plot_01_pipeline_registry.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_01_pipeline_registry.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_pipeline_registry.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_pipeline_registry.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_pipeline_registry.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_