The project is in a healthy, maintained state
Time series anomaly detection for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 4.3.3
 Project Readme

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("2025-01-01") => 100,
  Date.parse("2025-01-02") => 150,
  Date.parse("2025-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