How to Determine the Optimal Anomaly Detection Method For Your Application
Cynthia Freeman
Research Engineer
Jonathan Merriman
Software Engineer
How to Determine the Optimal Anomaly Detection Method For Your - - PowerPoint PPT Presentation
How to Determine the Optimal Anomaly Detection Method For Your Application Cynthia Freeman Research Engineer Jonathan Merriman Software Engineer Background Time Series A time series is a sequence of data points indexed in order of time.
Cynthia Freeman
Research Engineer
Jonathan Merriman
Software Engineer
▶ A time series is a sequence of data points indexed in order of time. ▶ How are time series used?
▶ Stock Market ▶ Tracking KPIs ▶ Medical Sensors ▶ Weather Patterns
An anomaly in a time series is a pattern that does not conform to past patterns of behavior. Applications: ▶ Ecient troubleshooting ▶ Fraud detection ▶ Ensuring undisrupted business ▶ Saving lives in system health monitoring
▶ What is anomalous? ▶ Online anomaly detection ▶ Lack of labeled data ▶ Data imbalance ▶ Minimize false positives ▶ Plethora of anomaly detection methods
▶ Base this decision o of the characteristics the time series possesses ▶ Evaluate anomaly detection methods on 4 time series characteristics as an example ▶ Experiment with 2 evaluation criteria
▶ Window-based F-score ▶ Numenta Anomaly Benchmark (NAB) Score
signal residual detect lter score
▶ Estimate mean and variance over sliding window ▶ Compute a score based on the tail probability S(yt) = P(yt ≤ τ|µ, σ2) ▶ Use max relative to upper and lower extremes
02-24 00 02-24 12 02-25 00 02-25 12 02-26 00 02-26 12 02-27 00 02-27 12 02-28 00 10 10 20 30
2014-02-24 2014-02-25 2014-02-26 2014-02-27 2014-02-28 0.5 0.6 0.7 0.8 0.9 1.0 Anomaly Score 2014-02-20 2014-02-21 2014-02-22 2014-02-23 2014-02-24 2014-02-25 2014-02-26 2014-02-27 2014-02-28 2014-03-01 5 10 15 20 25 30 35 log
▶ Presence of variations that occur at specic regular intervals ▶ Real data often exhibits seasonal eects at multiple time scales.
▶ Day-of-week ▶ Hour-of-day ▶ Can be irregular
▶ Day-of-month ▶ Holidays
▶ ACF plot is one way to detect seasonality
01 Jul 2014 30 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 timestamp
The underlying process can change over time. ▶ Bayesian Online Changepoint Detection ▶ ecp package in R
30 40 50 60
https://github.com/hildensia/bayesian_changepoint_detection
The process mean can change over time.
1000 2000 3000 4000 5000 6000 7000 8000 60 65 70 75 80 85
▶ First-order dierence to remove trend: [∆y](t) = y(t) − y(t − 1) ▶ Seasonal dierencing with period s: [∆sy](t) = y(t) − y(t − s)
2
4 2
4 1 2 2
5 2
5 1 2 2
6 2
6 1 2 2
7 2
7 1 2 2
8 10 10 20 30 2
4 2
4 1 2 2
5 2
5 1 2 2
6 2
6 1 2 2
7 2
7 1 2 2
8 20 10 10 20
Local regression with LOESS y(t) = S(t) + T(t) + ϵ(t) ▶ Decompose into season and trend ▶ LOESS smoothing can interpolate missing data ▶ Residual should look more stationary
A family of Gaussian models with temporal correlation.
y(t) −
p
∑
i=1
θiy(t − i)
= ϵ(t) +
q
∑
j=1
ϕjϵ(t − j)
Autoregressive (AR) The value at time t is a linear combination of p past values plus current noise signal. Moving Average (MA) The value at time t is a linear combination of q past values of noise.
ARIMA ARMA on dierenced signal. SARIMA Extend ARIMA to incorporate longer-term seasonal correlation. SARIMAX Add eXogenous variables.
▶ Generative model having Gaussian distribution at each timestep ▶ Optimal model order selection is not straightforward ▶ See: Box-Jenkins method
Uses an additive model: y(t) = g(t) + s(t) + h(t) + ϵt ▶ g(t) is linear/logistic growth trend ▶ s(t) is yearly/weekly seasonal component ▶ h(t) is user-provided list of holidays
https://github.com/facebook/prophet
How many outliers does the data set contain? ESD test requires an upper bound on the number of outliers. Assuming data is approximately normally distributed,
Ri = maxi |xi − ¯ x| s
x|, and repeat
▶ Uses STL but replaces trend with median
▶ Anomalies can aect trend estimation ▶ Leads to articial anomalies in the residual
▶ Apply Extreme Studentized Deviate (ESD) test
▶ Need to specify an upper limit on the # of outliers ▶ ¯ x is median and s is Median Absolute Deviation
https://github.com/twitter/AnomalyDetection
▶ Given a window of nlag time steps in the past, predict a window of nseq time steps in the future ▶ Anomaly score is an average of the prediction error ▶ Adaptive: uses online gradient-based optimizer, built to deal with concept drift ▶ Choice of nseq can greatly aect false positive rate
Anomaly Score Computation
Prediction using RNN
Anomaly Score Computation RNN Updation using BPTT At time t At time t+1
Prediction using RNN
RNN Updation using BPTT
Illustration from Saurav et al. '18
Hierarchical Temporal Memory Network ▶ HTM outputs sparse representation of input and next prediction step to determine the prediction error modeled as a rolling normal distribution ▶ HTM not implmented in a widely accessible way ▶ Cannot handle missing time steps innately
Illustration from Ahmad et al. '17
Heuristically Ordered Timeseries - Symbolic Aggregated ApproXimation ▶ Finds Discords: Subsequences of time series that are maximally dierent from all remaining subsequences ▶ Transform timeseries into alphabetical symbols and compare the distances between words ▶ Not built for concept drift detection ▶ Inecient for very large time series
b a a b c c b c
1000 1100 1200
r
P Q R S T
Discord 4 1 3 2
900 1000 1100 1200
r
P Q R S T
Discord 4 1 3 2
Illustrations from Keough et al. 2005
Anomaly detectors are adapted to output a score between 0 and 1 ▶ HTM: Use provided score ▶ Twitter AD and HOT-SAX: Use binary determination ▶ Windowed gaussian: Apply Q function to standardized signal ▶ STL, SARIMA, Prophet: Apply Q function to standardized residual
▶ For every predicted anomaly y, its score σ(y) is determined by its position relative to its containing window or an immediately preceding window ▶ For every ground truth anomaly, construct an anomaly window with the anomaly in the center.
.1×length of time series # of true anomalies
. .
Illustration from Lavin & Ahmad '15
▶ The raw score is computed as: Sd = ∑
y∈Yd
σ(y) + AFNfd AFN is cost of false negatives ▶ Then rescale to get summary score: 100 × S − Snull Sperfect − Snull ▶ Choose threshold that maximizes score
▶ Segment into nonoverlapping windows ▶ Window is anomalous if it contains an anomaly ▶ Treat like binary classication and report F1 ▶ Choose threshold that minimizes # of errors ▶ Prefer detection in case of tie
Seasonality
10 datasets 63,336 samples 23 ground truth anomalies
Trend
10 datasets 31,596 samples 17 ground truth anomalies
Concept Drift
10 datasets 32,402 samples 27 ground truth anomalies
Missing Timesteps
10 datasets 33,245 samples 22 ground truth anomalies 1,254 missing samples
https://github.com/numenta/NAB
Seasonality and Trend STL, SARIMA, Prophet Concept Drift Requires more complex methods such as HTMs Missing Time Steps ▶ Performance varies based on evaluation strategy ▶ Area for future work: more methods needed!
▶ F-score scheme is more restrictive ▶ NAB scores have more wiggle room for false positives due to reward for early detection ▶ What evaluation metric to use is entirely based on the needs of the user
▶ The existence of an anomaly detection method that is optimal for all domains is a myth ▶ Determine the characteristics present in the data to narrow down the choices for anomaly detection methods
Cynthia Freeman cynthia.freeman@verint.com Jonathan Merriman jonathan.merriman@verint.com https://github.com/cynthiaw2004/adclasses
Session page on conference website O’Reilly Events App
Average time to generate anomaly scores: