Time series anomaly detection for Ruby

Overview

AnomalyDetection.rb

🔥 Time series AnomalyDetection for Ruby

Learn how it works

Build Status

Installation

Add this line to your application’s Gemfile:

gem 'anomaly_detection'

Getting Started

Detect anomalies in a time series

100, Date.parse("2020-01-02") => 150, Date.parse("2020-01-03") => 136, # ... } AnomalyDetection.detect(series, period: 7) ">
series = {
  Date.parse("2020-01-01") => 100,
  Date.parse("2020-01-02") => 150,
  Date.parse("2020-01-03") => 136,
  # ...
}

AnomalyDetection.detect(series, period: 7)

Works great with Groupdate

series = User.group_by_day(:created_at).count
AnomalyDetection.detect(series, period: 7)

Series can also be an array without times (the index is returned)

series = [100, 150, 136, ...]
AnomalyDetection.detect(series, period: 7)

Options

Pass options

AnomalyDetection.detect(
  series,
  period: 7,            # number of observations in a single period
  alpha: 0.05,          # level of statistical significance
  max_anoms: 0.1,       # maximum number of anomalies as percent of data
  direction: "both",    # pos, neg, or both
  verbose: false        # show progress
)

Plotting

Add Vega to your application’s Gemfile:

gem 'vega'

And use:

AnomalyDetection.plot(series, anomalies)

Credits

This library was ported from the AnomalyDetection R package and is available under the same license. It uses cdflib for the quantile function.

References

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/AnomalyDetection.rb.git
cd AnomalyDetection.rb
bundle install
bundle exec rake compile
bundle exec rake test
You might also like...
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

gRPC - An RPC library and framework gRPC is a modern, open source, high-performance remote procedure call (RPC) framework that can run anywhere. gRPC

Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift

Fast Binary Encoding (FBE) Fast Binary Encoding allows to describe any domain models, business objects, complex data structures, client/server request

A fast phone number lib for Ruby (binds to Google's C++ libphonenumber)

MiniPhone A Ruby gem which plugs directly into Google's native C++ libphonenumber for extremely fast and robust phone number parsing, validation, and

Calleree helps to analyze Ruby's caller-callee relationships.

Calleree Calleree helps to analyze Ruby's caller-callee relationships. Note that this tool consumes memory and introduces additional overhead because

An extra-lightweight Ruby gem for working with SQLite3 databases

Extralite Extralite is an extra-lightweight SQLite3 wrapper for Ruby. It provides a single class with a minimal set of methods to interact with an SQL

Seasonal-trend decomposition for Ruby

STL Ruby Seasonal-trend decomposition for Ruby Installation Add this line to your application’s Gemfile: gem 'stl-rb' Getting Started Decompose a time

List of Persian Colors and hex colors for CSS, SCSS, PHP, JS, Python, and Ruby.

Persian Colors (Iranian colors) List of Persian Colors and hex colors for CSS, SCSS, PHP, C++, QML, JS, Python, Ruby and CSharp. Persian colors Name H

Examples of C extensions in Ruby gems

Ruby C Extensions, Explained Background How To Use This Repository Strategies Strategy 0, "isolated" Strategy 1, "system" Strategy 2a, "packaged_sourc

Access USB devices from Ruby via libusb-1.x
Access USB devices from Ruby via libusb-1.x

Access USB devices from Ruby LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary USB devices. libusb is a library that gives full

TimescaleDB is an open-source database designed to make SQL scalable for time-series data.

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.

Time-series database

README Akumuli is a time-series database for modern hardware. It can be used to capture, store and process time-series data in real-time. The word "ak

Beringei is a high performance, in-memory storage engine for time series data.
Beringei is a high performance, in-memory storage engine for time series data.

** THIS REPO HAS BEEN ARCHIVED AND IS NO LONGER BEING ACTIVELY MAINTAINED ** Beringei A high performance, in memory time series storage engine In the

GridDB is a next-generation open source database that makes time series IoT and big data fast,and easy.
GridDB is a next-generation open source database that makes time series IoT and big data fast,and easy.

Overview GridDB is Database for IoT with both NoSQL interface and SQL Interface. Please refer to GridDB Features Reference for functionality. This rep

以简单、易用、高性能为目标、开源的时序数据库,支持Linux和Windows, Time Series Database
以简单、易用、高性能为目标、开源的时序数据库,支持Linux和Windows, Time Series Database

松果时序数据库(pinusdb) 松果时序数据库是一款针对中小规模(设备数少于10万台,每天产生的数据量少于10亿条)场景设计的时序数据库。以简单、易用、高性能为设计目标。使用SQL语句进行交互,拥有极低的学习、使用成本, 提供了丰富的功能、较高的性能。 我们的目标是成为最简单、易用、健壮的单机时序

High-performance time-series aggregation for PostgreSQL

PipelineDB has joined Confluent, read the blog post here. PipelineDB will not have new releases beyond 1.0.0, although critical bugs will still be fix

SiriDB is a highly-scalable, robust and super fast time series database

SiriDB is a highly-scalable, robust and super fast time series database. Build from the ground up SiriDB uses a unique mechanism to operate without a global index and allows server resources to be added on the fly. SiriDB's unique query language includes dynamic grouping of time series for easy analysis over large amounts of time series.

The Time Series Visualization Tool that you deserve.
The Time Series Visualization Tool that you deserve.

Gold Sponsor: Greenzie PlotJuggler 3.3 PlotJuggler is a tool to visualize time series that is fast, powerful and intuitive. Noteworthy features: Simpl

LSH/Hypercube kNN and KMeans++ Clustering on polygonic curves and time series
LSH/Hypercube kNN and KMeans++ Clustering on polygonic curves and time series

kNN-and-Clustering-on-Time-Series-and-Curves LSH/Hypercube kNN and KMeans++ Clustering on polygonic curves and time series In this project we will exp

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.
Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Bullet Physics SDK This is the official C++ source code repository of the Bullet Physics SDK: real-time collision detection and multi-physics simulati

Comments
  • Failed to install on Ubuntu

    Failed to install on Ubuntu

    gem install anomaly_detection
    
    Fetching anomaly_detection-0.1.4.gem
    Building native extensions. This could take a while...
    ERROR:  Error installing anomaly_detection:
    	ERROR: Failed to build gem native extension.
    
        current directory: /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/anomaly_detection-0.1.4/ext/anomaly_detection
    /home/semaphore/.rbenv/versions/2.7.6/bin/ruby -I /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/site_ruby/2.7.0 -r ./siteconf20221114-4203-1r3ghch.rb extconf.rb
    checking for rice/rice.hpp in /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rice-4.0.4/include... no
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of necessary
    libraries and/or headers.  Check the mkmf.log file for more details.  You may
    need configuration options.
    
    Provided configuration options:
    	--with-opt-dir
    	--without-opt-dir
    	--with-opt-include
    	--without-opt-include=${opt-dir}/include
    	--with-opt-lib
    	--without-opt-lib=${opt-dir}/lib
    	--with-make-prog
    	--without-make-prog
    	--srcdir=.
    	--curdir
    	--ruby=/home/semaphore/.rbenv/versions/2.7.6/bin/$(RUBY_BASE_NAME)
    /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rice-4.0.4/lib/mkmf-rice.rb:120:in `<top (required)>': Could not find rice/rice.hpp header (RuntimeError)
    	from /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:160:in `require'
    	from /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:160:in `rescue in require'
    	from /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:149:in `require'
    	from extconf.rb:1:in `<main>'
    /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- mkmf-rice (LoadError)
    	from /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'
    	from extconf.rb:1:in `<main>'
    
    To see why this extension failed to compile, please check the mkmf.log which can be found here:
    
      /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/anomaly_detection-0.1.4/mkmf.log
    
    extconf failed, exit code 1
    
    Gem files will remain installed in /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/anomaly_detection-0.1.4 for inspection.
    Results logged to /home/semaphore/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/anomaly_detection-0.1.4/gem_make.out
    

    Looks to be the same as: https://github.com/ankane/field_test/issues/33

    lsb_release -a
    
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 18.04.6 LTS
    Release:	18.04
    Codename:	bionic
    
    opened by NielsKSchjoedt 3
  • Anomaly found while change of pace

    Anomaly found while change of pace

    Hi there,

    thanks for your work. We have been using on many GPS tracks your Anomaly Detection to sort and filter all bad position reported by incorrect GPS fix.

    It works well still I'm trying to figure how I should handle such case. So far we are checking speed to detect anomaly but we would have the same issue by checking distance or straight GPS latitude/longitude. I attached a graph to provide a sample of data where I got some anomaly detection found while it's a normal behavior and expected data.

    How should we resolve this?

    Capture d’écran 2022-09-25 à 06 08 31
    opened by Toucouleur66 2
Owner
Andrew Kane
Andrew Kane
Anomaly Detection on Dynamic (time-evolving) Graphs in Real-time and Streaming manner

Anomaly Detection on Dynamic (time-evolving) Graphs in Real-time and Streaming manner. Detecting intrusions (DoS and DDoS attacks), frauds, fake rating anomalies.

Stream-AD 693 Nov 24, 2022
Sketch-Based Streaming Anomaly Detection in Dynamic Graphs

AnoGraph Implementation of Sketch-Based Streaming Anomaly Detection in Dynamic Graphs. Siddharth Bhatia, Mohit Wadhwa, Philip S. Yu, Bryan Hooi Existi

Stream-AD 54 Oct 6, 2022
Time Series Quick Simulator - able to perform time series analysis and to setup validation experiments.

tsqsim Time Series Quick Simulator - able to perform time series analysis and to setup validation experiments. With its somewhat limited plotting capa

null 6 Aug 7, 2022
Breakout detection for Ruby

Breakout ?? BreakoutDetection for Ruby Learn how it works Installation Add this line to your application’s Gemfile: gem 'breakout-detection' Getting S

Andrew Kane 36 Sep 4, 2022
Rule Engine (RE) creates an interpretable anomaly classifier from many one-feature and two-feature decision rules

Rule Engine (RE) creates an interpretable anomaly classifier from many one-feature and two-feature decision rules

James Thomas 15 Aug 15, 2022
An open source library for face detection in images. The face detection speed can reach 1000FPS.

libfacedetection This is an open source library for CNN-based face detection in images. The CNN model has been converted to static variables in C sour

Shiqi Yu 11.3k Nov 28, 2022
Canny edge detection, one of the efficient edge detection algorithms is implemented on a Zedboard FPGA using verilog

In this project, Canny edge detection, one of the efficient edge detection algorithms is implemented on a Zedboard FPGA using verilog. The input image is stored on a PC and fed to the FPGA. The output processed image is displayed on a VGA monitor.

Jeffrey Samuel 3 Nov 16, 2022
C++ Type Traits for Smart Pointers that are not included in the standard library, containing inheritance detection and member detection.

Smart Pointer Type Trait ?? A simple, header-only cpp library implementing smart pointer type traits. You can easily compile your code diffrently depe

Woon2 12 Sep 14, 2022
ANSI C library for NURBS, B-Splines, and Bézier curves with interfaces for C++, C#, D, Go, Java, Lua, Octave, PHP, Python, R, and Ruby.

TinySpline TinySpline is a small, yet powerful library for interpolating, transforming, and querying arbitrary NURBS, B-Splines, and Bézier curves. Th

Marcel Steinbeck 876 Nov 26, 2022