Proximity to learned representations and relationship to threshold#

RANDOM_SEED = 42
VERBOSE = False
# 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)
import numpy as np
from pan import ParallelAnomalousNudge
# 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)
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.


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()
demonstrate 08 inspect score component display

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

Gallery generated by Sphinx-Gallery