StreamAD Detector#

Univariate Anomaly Detector#

KNNDetector#

class streamad.model.KNNDetector(window_len=100, buffer_len=200, k_neighbor=3)[source]#

Bases: streamad.base.detector.BaseDetector

Univariate KNN-CAD model with mahalanobis distance. [mdBI16]. See KNN-CAD

__init__(window_len=100, buffer_len=200, k_neighbor=3)[source]#

KNN anomaly detector with mahalanobis distance.

Parameters
  • window_len (int, optional) – The length of window. Defaults to 100.

  • buffer_len (int, optional) – The length of references. Defaults to 200.

  • k_neighbor (int, optional) – The number of neighbors to cumulate distances. Defaults to 3.

check(X)#

Check whether the detector can handle the data.

Return type

bool

fit(X)[source]#

Record and analyse the current observation from the stream. Detector collect the init data firstly, and further score observation base on the observed data.

Parameters

X (np.ndarray) – Current observation.

fit_score(X)#

Detector fit and score the anomaly of current observation from StreamGenerator.

Parameters

X (np.ndarray) – Data of current observation

Return type

float

Returns

float – Anomaly score. 1.0 for anomaly and 0.0 for normal.

score(X)[source]#

Score the current observation. None for init period and float for the score of anomalies.

Parameters

X (np.ndarray) – Current observation.

Return type

float

Returns

float – Anomaly probability.


SpotDetector#

class streamad.model.SpotDetector(prob=0.0001, window_size=10, init_len=300)[source]#

Bases: streamad.base.detector.BaseDetector

Univariate Spot model. [mdSFTLargouet17]. See SPOT

__init__(prob=0.0001, window_size=10, init_len=300)[source]#

Spot detector.

Parameters
  • prob (float, optional) – Threshold for probability, a small float value. Defaults to 1e-4.

  • window_size (int, optional) – A window for reference. Defaults to 10.

  • init_len (int, optional) – Data length for initialization. Recommended > 100. Defaults to 300.

check(X)#

Check whether the detector can handle the data.

Return type

bool

fit(X)[source]#

Record and analyse the current observation from the stream. Detector collect the init data firstly, and add random drift.

Parameters

X (np.ndarray) – [description]

fit_score(X)#

Detector fit and score the anomaly of current observation from StreamGenerator.

Parameters

X (np.ndarray) – Data of current observation

Return type

float

Returns

float – Anomaly score. 1.0 for anomaly and 0.0 for normal.

score(X)[source]#

Score the current observation. None for init period and float for the probability of anomalousness between two thresholds. 1.0 for certain anomaly point.

Parameters

X (np.ndarray) – Current observation.

Return type

float

Returns

float – Anomaly probability.


Multivariate Anomaly Detector#

Note that these methods are compatible with univariate time series.

xStreamDetector#

class streamad.model.xStreamDetector(n_components=50, n_chains=100, depth=25, window_size=25)[source]#

Bases: streamad.base.detector.BaseDetector

Multivariate xStreamDetector [mdMLA18]. See xStream

__init__(n_components=50, n_chains=100, depth=25, window_size=25)[source]#

xStream detector for multivariate data.

Parameters
  • n_components (int, optional) – Number of streamhash projection, similar to feature numbers. Defaults to 50.

  • n_chains (int, optional) – Number of half-space chains. Defaults to 100.

  • depth (int, optional) – Maximum depth for each chain. Defaults to 25.

  • window_size (int, optional) – Size of reference window. Defaults to 25.

check(X)#

Check whether the detector can handle the data.

Return type

bool

fit(X)[source]#

xStreamDetector collects data with a window length, projects them via streamhash projector, and then scores the observed data.

Parameters

X (np.ndarray) – Current observation.

fit_score(X)#

Detector fit and score the anomaly of current observation from StreamGenerator.

Parameters

X (np.ndarray) – Data of current observation

Return type

float

Returns

float – Anomaly score. 1.0 for anomaly and 0.0 for normal.

score(X)[source]#

Score the current observation. None for init period and float for the probability of anomalousness.

Parameters

X (np.ndarray) – Current observation.

Return type

float

Returns

float – Anomaly probability.


RandomDetector#

class streamad.model.RandomDetector[source]#

Bases: streamad.base.detector.BaseDetector

Return random anomaly score. A minimum score for benchmark.

check(X)#

Check whether the detector can handle the data.

Return type

bool

fit(X)[source]#

Detector fit current observation from StreamGenerator.

Parameters

X (np.ndarray) – The data value of current observation from StreamGenerator.

Return type

None

fit_score(X)#

Detector fit and score the anomaly of current observation from StreamGenerator.

Parameters

X (np.ndarray) – Data of current observation

Return type

float

Returns

float – Anomaly score. 1.0 for anomaly and 0.0 for normal.

score(X)[source]#

Abstract method: Detector predict the probability of anomaly for current observation form StreamGenerator.

Parameters

X (np.ndarray) – The data value of current observation from StreamGenerator.

Return type

float

Returns

float – Anomaly probability.