Quantile Detector

Flags anomalies that are beyond some quantiles of historical data. This is similar to a threshold-based detector, where the thresholds are computed as quantiles of historical data when the detector is fitted.

class darts.ad.detectors.quantile_detector.QuantileDetector(low_quantile=None, high_quantile=None)[source]

Bases: FittableDetector, _BoundedDetectorMixin

Quantile Detector

Flags values that are either below or above the low_quantile and high_quantile quantiles of historical data, respectively.

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

If sequences of values are given for the parameters low_quantile and/or high_quantile, they must be of the same length, matching the dimensionality of the series passed to fit(), 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_quantile or high_quantile is None, the corresponding bound will not be used. However, at least one of the two must be set.

Parameters
  • low_quantile (Union[Sequence[float], float, None]) – (Sequence of) quantile of historical data below which a value is regarded as anomaly. Must be between 0 and 1. If a sequence, must match the dimensionality of the series this detector is applied to.

  • high_quantile (Union[Sequence[float], float, None]) – (Sequence of) quantile of historical data above which a value is regarded as anomaly. Must be between 0 and 1. 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.

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

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)

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)

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 prediction (1 if considered as an anomaly, 0 if not)

Return type

Union[TimeSeries, Sequence[TimeSeries]]

property high_threshold
property low_threshold