Threshold Detector

Detector that detects anomaly based on user-given threshold. This detector compares time series values with user-given thresholds, and identifies time points as anomalous when values are beyond the thresholds.

class darts.ad.detectors.threshold_detector.ThresholdDetector(low_threshold=None, high_threshold=None)[source]

Bases: Detector, _BoundedDetectorMixin

Threshold Detector

Flags values that are either below or above the low_threshold and high_threshold, respectively.

If a single value is provided for low_threshold or high_threshold, this same value will be used across all components of the series.

If sequences of values are given for the parameters low_threshold and/or high_threshold, they must be of the same length, matching the dimensionality of the series passed to detect(), or have a length of 1. In the latter case, this single value will be used across all components of the series.

If either low_threshold or high_threshold is None, the corresponding bound will not be used. However, at least one of the two must be set.

Parameters
  • low_threshold (Union[int, float, Sequence[float], None]) – (Sequence of) lower bounds. If a sequence, must match the dimensionality of the series this detector is applied to.

  • high_threshold (Union[int, float, Sequence[float], None]) – (Sequence of) upper bounds. If a sequence, must match the dimensionality of the series this detector is applied to.

Attributes

high_threshold

low_threshold

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')

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]]]

property high_threshold
property low_threshold