ankane / random-cut-forest-ruby

Random Cut Forest anomaly detection for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Random Cut Forest Ruby

Random Cut Forest (RCF) anomaly detection for Ruby

Build Status

Installation

Add this line to your application’s Gemfile:

gem "rcf"

Getting Started

Create a forest with 3 dimensions

forest = Rcf::Forest.new(3)

Score a point

forest.score([1.0, 2.0, 3.0])

Update with a point

forest.update([1.0, 2.0, 3.0])

Example

forest = Rcf::Forest.new(3)

200.times do |i|
  point = [rand, rand, rand]

  # make the second to last point an anomaly
  if i == 198
    point[1] = 2
  end

  score = forest.score(point)
  puts "point = #{i}, score = #{score}"
  forest.update(point)
end

Parameters

Set parameters

Rcf::Forest.new(
  dimensions,
  shingle_size: 1,          # shingle size to use
  sample_size: 256,         # points to keep in sample for each tree
  number_of_trees: 100,     # number of trees to use in the forest
  random_seed: 42,          # random seed to use
  parallel: false           # enable parallel execution
)

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/random-cut-forest-ruby.git
cd random-cut-forest-ruby
bundle install
bundle exec rake vendor:all
bundle exec rake test

About

Random Cut Forest anomaly detection for Ruby

License:Apache License 2.0


Languages

Language:Ruby 100.0%