Giter Club home page Giter Club logo

anomalydetection.rb's Introduction

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

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 stl-cpp for seasonal-trend decomposition and dist.h 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

anomalydetection.rb's People

Contributors

ankane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lepepe

anomalydetection.rb's Issues

Ideas

Ideas

  • Improve performance
  • Faster stopping on interrupt
  • Add plotting

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: ankane/field_test#33

lsb_release -a

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.6 LTS
Release:	18.04
Codename:	bionic

Issue with rake assets:precompile

 => ERROR [10/11] RUN rake assets:precompile                                                                                                                                                         2.9s 
------                                                                                                                                                                                                    
 > [10/11] RUN rake assets:precompile:                                                                                                                                                                    
#0 2.770 rake aborted!                                                                                                                                                                                    
#0 2.770 LoadError: /usr/local/bundle/gems/anomaly_detection-0.2.2/lib/anomaly_detection/ext.so: undefined symbol: _ZTINSt10filesystem7__cxx1116filesystem_errorE - /usr/local/bundle/gems/anomaly_detection-0.2.2/lib/anomaly_detection/ext.so                                                                                                                                                                     
#0 2.770 /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'                                                                                   
#0 2.770 /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#0 2.770 /usr/local/bundle/gems/activesupport-6.1.7.3/lib/active_support/dependencies.rb:332:in `block in require'
#0 2.770 /usr/local/bundle/gems/activesupport-6.1.7.3/lib/active_support/dependencies.rb:299:in `load_dependency'
#0 2.770 /usr/local/bundle/gems/activesupport-6.1.7.3/lib/active_support/dependencies.rb:332:in `require'
#0 2.770 /usr/local/bundle/gems/anomaly_detection-0.2.2/lib/anomaly_detection.rb:2:in `<main>'
#0 2.770 /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#0 2.770 /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#0 2.770 /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
#0 2.770 /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/runtime.rb:55:in `each'
#0 2.770 /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/runtime.rb:55:in `block in require'
#0 2.770 /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/runtime.rb:44:in `each'
#0 2.770 /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/runtime.rb:44:in `require'
#0 2.770 /usr/local/bundle/gems/bundler-2.3.19/lib/bundler.rb:188:in `require'
#0 2.770 /app/config/application.rb:6:in `<top (required)>'
#0 2.770 /app/Rakefile:4:in `require_relative'
#0 2.770 /app/Rakefile:4:in `<top (required)>'
#0 2.770 /usr/local/bundle/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
#0 2.770 (See full trace by running task with --trace)
------
failed to solve: process "/bin/sh -c rake assets:precompile" did not complete successfully: exit code: 1

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

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.