Skip to content

Commit

Permalink
add twitter's anomaly detection from github
Browse files Browse the repository at this point in the history
fix the problem with plot
twitter/AnomalyDetection#101
  • Loading branch information
PyRPy authored Dec 21, 2019
1 parent 26bd1c5 commit d4d2ca9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions PracticalTSA/Chapter16_time_series_packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,30 @@ points(forecast$ds, forecast$yhat, type = "l", col=2)

# decomposition
prophet_plot_components(m, forecast)


# anomaly detection -------------------------------------------------------
# library(RCurl)
# library(httr)
# set_config( config( ssl_verifypeer = 0L ) )
#
# devtools::install_github("twitter/AnomalyDetection", force = TRUE)
library(AnomalyDetection)
data("raw_data")
head(raw_data)

# find unusual values in both directions
library(ggplot2)

raw_data$timestamp <- as.POSIXct(raw_data$timestamp) # change format

res = AnomalyDetectionTs(raw_data, max_anoms = 0.01,
direction = 'pos', plot = TRUE)

res$anoms$timestamp <- as.POSIXct(res$anoms$timestamp)
res$plot

# fix
ggplot(raw_data, aes(timestamp, count)) +
geom_line(data=raw_data, aes(timestamp, count), color='blue') +
geom_point(data=res$anoms, aes(timestamp, anoms), color='red')

0 comments on commit d4d2ca9

Please sign in to comment.