Random Cut Forest (RCF) anomaly detection for Ruby
Add this line to your application’s Gemfile:
gem "rcf"
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])
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
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
)
View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
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