Tidy anomaly detection
anomalize
enables a tidy workflow for detecting anomalies in data. The main functions are time_decompose()
, anomalize()
, and time_recompose()
. When combined, it’s quite simple to decompose time series, detect anomalies, and create bands separating the “normal” data from the anomalous data.
Check out our entire Software Intro Series on YouTube!
You can install the development version with devtools
or the most recent CRAN version with install.packages()
:
# devtools::install_github("business-science/anomalize")
install.packages("anomalize")
anomalize
has three main functions:
time_decompose()
: Separates the time series into seasonal, trend, and remainder componentsanomalize()
: Applies anomaly detection methods to the remainder component.time_recompose()
: Calculates limits that separate the “normal” data from the anomalies!Load the tidyverse
and anomalize
packages.
library(tidyverse)
library(anomalize)
Next, let’s get some data. anomalize
ships with a data set called tidyverse_cran_downloads
that contains the daily CRAN download counts for 15 “tidy” packages from 2017-01-01 to 2018-03-01.
tidyverse_cran_downloads %>%
ggplot(aes(date, count)) +
geom_point(color = "#2c3e50", alpha = 0.25) +
facet_wrap(~ package, scale = "free_y", ncol = 3) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 30, hjust = 1)) +
labs(title = "Tidyverse Package Daily Download Counts",
subtitle = "Data from CRAN by way of cranlogs package")