Detector Base Classes

class darts.ad.detectors.detectors.Detector(*args, **kwargs)[source]

Bases: ABC

Base class for all detectors

Methods

detect(series)

Detect anomalies on given time series.

eval_accuracy(actual_anomalies, anomaly_score)

Score the results against true anomalies.

detect(series)[source]

Detect anomalies on given time series.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – series on which to detect anomalies.

Returns

binary prediciton (1 if considered as an anomaly, 0 if not)

Return type

Union[TimeSeries, Sequence[TimeSeries]]

eval_accuracy(actual_anomalies, anomaly_score, window=1, metric='recall')[source]

Score the results against true anomalies.

Parameters
  • actual_anomalies (Union[TimeSeries, Sequence[TimeSeries]]) – The ground truth of the anomalies (1 if it is an anomaly and 0 if not).

  • anomaly_score (Union[TimeSeries, Sequence[TimeSeries]]) – Series indicating how anomoulous each window of size w is.

  • window (int) – Integer value indicating the number of past samples each point represents in the anomaly_score.

  • metric (str) – Metric function to use. Must be one of “recall”, “precision”, “f1”, and “accuracy”. Default: “recall”

Returns

Metric results for each anomaly score

Return type

Union[float, Sequence[float], Sequence[Sequence[float]]]

class darts.ad.detectors.detectors.FittableDetector(*args, **kwargs)[source]

Bases: Detector

Base class of Detectors that need training.

Methods

detect(series)

Detect anomalies on given time series.

eval_accuracy(actual_anomalies, anomaly_score)

Score the results against true anomalies.

fit(series)

Trains the detector on the given time series.

fit_detect(series)

Trains the detector and detects anomalies on the same series.

detect(series)[source]

Detect anomalies on given time series.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – series on which to detect anomalies.

Returns

binary prediciton (1 if considered as an anomaly, 0 if not)

Return type

Union[TimeSeries, Sequence[TimeSeries]]

eval_accuracy(actual_anomalies, anomaly_score, window=1, metric='recall')

Score the results against true anomalies.

Parameters
  • actual_anomalies (Union[TimeSeries, Sequence[TimeSeries]]) – The ground truth of the anomalies (1 if it is an anomaly and 0 if not).

  • anomaly_score (Union[TimeSeries, Sequence[TimeSeries]]) – Series indicating how anomoulous each window of size w is.

  • window (int) – Integer value indicating the number of past samples each point represents in the anomaly_score.

  • metric (str) – Metric function to use. Must be one of “recall”, “precision”, “f1”, and “accuracy”. Default: “recall”

Returns

Metric results for each anomaly score

Return type

Union[float, Sequence[float], Sequence[Sequence[float]]]

fit(series)[source]

Trains the detector on the given time series.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – Time series to be used to train the detector.

Returns

Fitted Detector.

Return type

self

fit_detect(series)[source]

Trains the detector and detects anomalies on the same series.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – Time series to be used for training and be detected for anomalies.

Returns

Binary prediciton (1 if considered as an anomaly, 0 if not)

Return type

Union[TimeSeries, Sequence[TimeSeries]]