.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/demonstrate_08_inspect_score_component_display.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_demonstrate_08_inspect_score_component_display.py: ================================================================== Proximity to learned representations and relationship to threshold ================================================================== .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python RANDOM_SEED = 42 VERBOSE = False .. GENERATED FROM PYTHON SOURCE LINES 12-18 .. code-block:: Python # generate train / test data from examples.utils.dataset import generate_train_data, generate_test_data X_train, y_train = generate_train_data(n_normal=100, n_abnormal=20, random_seed=RANDOM_SEED) X_test, y_test = generate_test_data(n_normal=100, n_abnormal=20, random_seed=RANDOM_SEED*2) .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python import numpy as np from pan import ParallelAnomalousNudge .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: Python # train PAN model = ParallelAnomalousNudge.with_derived_estimators(X_train, y_train, nu=.1, random_seed=RANDOM_SEED, verbose=VERBOSE) model.fit(X_train, y_train) .. raw:: html
ParallelAnomalousNudge(estimators={np.int64(0): SomRepresentationEstimator(nu=0.1,
                                                                               random_seed=42,
                                                                               som_representation=<minisom_representation.som_representation.SomRepresentation object at 0x7fc2830ab620>),
                                       np.int64(1): SomRepresentationEstimator(nu=0.1,
                                                                               random_seed=42,
                                                                               som_representation=<minisom_representation.som_representation.SomRepresentation object at 0x7fc2830aa990>)},
                           nu=0.1, random_seed=42, scaler=StandardScaler())
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 29-48 .. code-block:: Python import matplotlib.pyplot as plt from pan import ScoreComponentDisplay fig = plt.figure(figsize=(12, 12)) disp = ScoreComponentDisplay \ .from_estimator( model, np.vstack((X_train, X_test)), ax=fig.gca(), threshold_style={"colors": "black", "linewidths": 2, "linestyles": "dashed"} ) \ .plot_samples(X_train[y_train == 0], style_preset="train") \ .plot_samples(X_train[y_train == 1], style_preset="train_anomaly") \ .plot_samples(X_test[y_test == 0], style_preset="test") \ .plot_samples(X_test[y_test == 1], style_preset="test_anomaly") plt.margins(.1) plt.legend() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_demonstrate_08_inspect_score_component_display_001.png :alt: demonstrate 08 inspect score component display :srcset: /auto_examples/images/sphx_glr_demonstrate_08_inspect_score_component_display_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.247 seconds) .. _sphx_glr_download_auto_examples_demonstrate_08_inspect_score_component_display.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demonstrate_08_inspect_score_component_display.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demonstrate_08_inspect_score_component_display.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demonstrate_08_inspect_score_component_display.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_