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

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.

low_threshold

The (sequence of) lower quantile values.

high_threshold

The (sequence of) upper quantile values.

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)

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)

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)

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