Least Squares Anomaly Detection on Static Data

In this example, we generate some points from a 2-D Gaussian mixture, and then plot the response of the anomaly detection model across the data space given some different parameter settings.

The plots show training data as black crosses, contours in blue indicate the response of the model across the space after training, and the contour line in red indicates the decision boundary given by thresholding the model output at 0.5.

This example was created by modifying the scikit-learn demo.

In general the LSAnomaly class can be used as a plug-in replacement in any of the outlier detection demos on the sklearn site (e.g., as a replacement for svm.OneClassSVM).


In [1]:
import os
import numpy as np
from pathlib import Path

cwd = os.getcwd()
os.chdir(Path(cwd).parents[1])

from lsanomaly import LSAnomaly
import lsanomaly.notebooks.static_mix as demo

Generate Data


In [2]:
n_samples = 20
offset = 2.5
X, xx, yy = demo.data_prep(n_samples=n_samples, offset=offset)

Anomaly Models


In [3]:
sigma_candidates = [1, 2, 3]
rho_candidates = [0.1, 1, 10]

demo.plot_results(
    X, 
    xx, 
    yy, 
    threshold=0.5,
    sigma_candidates=sigma_candidates, 
    rho_candidates=rho_candidates
)



In [ ]: