Detecting multiple anomalies in seasonal time series

Introduction to Anomaly Detection in R

Alastair Rushworth

Data Scientist

Monthly revenue data

head(msales)
  sales month
1 6.068     1
2 5.966     2
3 6.133     3
4 6.230     4
5 6.407     5
6 6.433     6

Grubbs' test not appropriate here

  • Seasonality may be present
  • May be multiple anomalies
Introduction to Anomaly Detection in R

Visualizing monthly revenue

plot(sales ~ month, data = msales, type = 'o')

Introduction to Anomaly Detection in R

Seasonal-Hybrid ESD algorithm usage

library(AnomalyDetection)
sales_ad <- AnomalyDetectionVec(x = msales$sales, period = 12, 
                                direction = 'both')

Arguments

  • x: vector of values
  • period: period of repeating pattern
  • direction: find anomalies that are small ('neg'), large ('pos'), or both ('both')

Package download from https://github.com/twitter/AnomalyDetection

Introduction to Anomaly Detection in R

Seasonal-Hybrid ESD algorithm output

sales_ad <- AnomalyDetectionVec(x = msales$sales, period = 12, 
                                direction = 'both')
sales_ad$anoms
  index anoms
1    14 1.561
2   108 2.156
Introduction to Anomaly Detection in R

Seasonal-Hybrid ESD algorithm plot

AnomalyDetectionVec(x = msales$sales, period = 12, 
                    direction = 'both', plot = T)

Introduction to Anomaly Detection in R

Let's practice!

Introduction to Anomaly Detection in R

Preparing Video For Download...