Git Product home page Git Product logo

otsad's Introduction

otsad

Online Time Series Anomaly Detectors

This package provides anomaly detectors in the context of online time series and their evaluation with the Numenta score.

Installation

Dependencies

CAD-OSE algorithm is implemented in Python. It uses bencode library in the hashing step. This dependency can be installed with the Python package manager pip.

$ sudo pip install bencode-python3

otsad package

You can install the released version of otsad from CRAN with:

# Get the released version from CRAN
install.packages("otsad")

# Get the latest development version from GitHub
devtools::install_github("alaineiturria/otsad")

Most useful functions

Detectors

  • PEWMA
    • Offline: CpPewma
    • Online: IpPewma
  • SD-EWMA
    • Offline: CpSdEwma
    • Online: IpSdEwma
  • TSSD-EWMA
    • Offline: CpTsSdEwma
    • Online: IpTsSdEwma
  • KNN-ICAD
    • Offline: CpKnnCad(ncm.type = "ICAD")
    • Online: IpKnnCad(ncm.type = "ICAD")
  • KNN-LDCD
    • Offline CpKnnCad(ncm.type = "LDCD")
    • Online: IpKnnCad(ncm.type = "LDCD")
  • CAD-OSE
    • Offline and Online: ContextualAnomalyDetector
  • EORELM-AD
    • Offline and Online: EorelmAD

NAB score

  • Get score: GetDetectorScore
  • Normalize score: NormalizeScore + GetNullAndPerfectScores

False Positve Reduction

  • Offline and Online: ReduceAnomalies

Static or interactive visualizations

  • Offline: PlotDetections

From prediction to anomaly detection framework

It is developed a framework that eases the adoption of any online time series prediction algorithm into an anomaly detection algorithm.

The framework is composed of two main components, one for online data normalization and the other for streaming anomaly scoring based on prediction error. The procedure to adapt an online prediction model into anomaly detection using this framework is shown in the following Figure. First, if the prediction model requires it, the current data point is normalized incrementally. Then, the normalized data point is used to train and predict the expected value using the chosen prediction model. After that, to compute the outlierness, the prediction error is calculated and passed to the outlier scoring function.

Online normalization

  • Dynamic normalization
    • Online: DynamicNormalizer
  • Window normalization
    • Online: WindowNormalizer
  • One-pass adaptive normalization
    • Online: AdaptiveNormalizer
  • One-pass adaptive min-max normalization
    • Online: AdaptiveNormalizer2

Outlier scoring

  • Anomaly likelihood
    • Online: AnomalyLikelihoodScorer
  • Dynamic threshold
    • Online: DynamicThresholdScorer
  • Sigma scoring
    • Online: SigmaScorer
  • Dynamic sigma scoring
    • Online: DynamicSigmaScorer

NOTE: As usual in R, the documentation pages for each function can be loaded from the command line with the commands ? or help:

?CpSdEwma
help(CpSdEwma)

Example

This is a basic example of the use of otsad package:

library(otsad)

## basic example code

# Generate data
set.seed(100)
n <- 500
x <- sample(1:100, n, replace = TRUE)
x[70:90] <- sample(110:115, 21, replace = TRUE) # distributional shift
x[25] <- 200 # abrupt transient anomaly
x[320] <- 170 # abrupt transient anomaly
df <- data.frame(timestamp = 1:n, value = x)

# Apply classic processing SD-EWMA detector
result <- CpSdEwma(data = df$value, n.train = 5, threshold = 0.01, l = 3)
res <- cbind(df, result)
PlotDetections(res, title = "SD-EWMA ANOMALY DETECTOR", return.ggplot = TRUE)

See plotly interactive graph

For more details, see otsad documentation and vignettes.

otsad's People

Contributors

alaineiturria avatar jacintocc avatar

Stargazers

 avatar  avatar Jiannan Chen avatar Jimaz avatar  avatar  avatar Edgar Dobriban avatar Wei-Chen.Chen avatar  avatar  avatar valeman avatar Jesse avatar David C. Lambert avatar  avatar jiandong avatar  avatar Gireesh Bogu avatar Psyduck avatar Grzegorz Chlebus avatar  avatar Srikanth K S avatar  avatar Dmitry Ledentsov avatar Haiquan Qiu avatar  avatar Ignacio Aguilera Martos avatar Angel Conde avatar

Watchers

 avatar  avatar

otsad's Issues

Learning more about otsad

Hi, I'm interested in NAB and just came across your project. Do you have a summary of the NAB scores achieved with the detectors in otsad? Is Numenta's HTM included in otsad (It seems that it is not). Are any of the detectors out-performing Numenta's HTM on NAB? Thanks!

Suggest adding a zero variance check on input

Issue: when data has zero variance, CpSdEwma() output has more rows than input

Suggestion:

  • trim output to match length(input) since it doesn't really matter when there's zero variance
  • add a check, something like:
if ( var(data) == 0 ) {  
      res <- data.frame(is.anomaly = rep(0, length(data)), lcl = data, ucl = data, 
                                  stringsAsFactors = FALSE)
   }
library(otsad)
#> Warning: package 'otsad' was built under R version 3.5.3
# when data has non-zero variance, it's OK
vec <- rep(1:5, times = 5)
res <- CpSdEwma(data = vec, n.train = 5, threshold = 0.01, l = 3)
nrow(res) == length(vec)
#> [1] TRUE

# when data has zero variance, CpSdEwma() output has more rows than input
vec <- rep(0, 25)
res <- CpSdEwma(data = vec, n.train = 5, threshold = 0.01, l = 3)
nrow(res) == length(vec)
#> [1] FALSE

# adding just one different value to make data non-zero variance works
vec <- c(0.1, rep(0, 25))
res <- CpSdEwma(data = vec, n.train = 5, threshold = 0.01, l = 3)
nrow(res) == length(vec)
#> [1] TRUE

Created on 2019-06-20 by the reprex package (v0.2.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.