Detector Base Classes

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

Bases: ABC

Base class for all detectors

Methods

detect(series[, name])

Detect anomalies on given time series.

eval_metric(anomalies, pred_scores[, ...])

Score the results against true anomalies.

detect(series, name='series')[source]

Detect anomalies on given time series.

Parameters
  • series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) series on which to detect anomalies.

  • name (str) – The name of series.

Returns

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

Return type

Union[TimeSeries, Sequence[TimeSeries]]

eval_metric(anomalies, pred_scores, window=1, metric='recall')[source]

Score the results against true anomalies.

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

  • pred_scores (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) of estimated anomaly score series indicating how anomalous each window of size w is.

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

  • metric (Literal[‘recall’, ‘precision’, ‘f1’, ‘accuracy’]) – The name of the 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 require training.

Methods

detect(series[, name])

Detect anomalies on given time series.

eval_metric(anomalies, pred_scores[, ...])

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, name='series')[source]

Detect anomalies on given time series.

Parameters
  • series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) series on which to detect anomalies.

  • name (str) – The name of series.

Returns

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

Return type

Union[TimeSeries, Sequence[TimeSeries]]

eval_metric(anomalies, pred_scores, window=1, metric='recall')

Score the results against true anomalies.

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

  • pred_scores (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) of estimated anomaly score series indicating how anomalous each window of size w is.

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

  • metric (Literal[‘recall’, ‘precision’, ‘f1’, ‘accuracy’]) – The name of the 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 (sequence of) 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]]