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:
darts.ad.detectors.detectors.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.
Methods
detect
(series)Detect anomalies on given time series.
eval_accuracy
(actual_anomalies, anomaly_score)Score the results against true anomalies.
- 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]]]