IsoTree
Learn how Isolation Forest works
Installation
Add this line to your application’s Gemfile:
gem 'isotree'
Getting Started
Prep your data
x = [[1, 2], [3, 4], [5, 6], [7, 8]]
Train a model
model = IsoTree::IsolationForest.new
model.fit(x)
Get outlier scores
model.predict(x)
Scores are between 0 and 1, with higher scores indicating outliers
Parameters
Pass parameters - default values below
IsoTree::IsolationForest.new(
sample_size: nil,
ntrees: 500,
ndim: 3,
ntry: 3,
prob_pick_avg_gain: 0,
prob_pick_pooled_gain: 0,
prob_split_avg_gain: 0,
prob_split_pooled_gain: 0,
min_gain: 0,
all_perm: false,
coef_by_prop: false,
sample_with_replacement: false,
penalize_range: true,
weigh_by_kurtosis: false,
min_imp_obs: 3,
random_seed: 1,
nthreads: -1
)
See a detailed explanation
Data
Data can be an array of arrays
[[1, 2, 3], [4, 5, 6]]
Or a Numo array
Numo::NArray.cast([[1, 2, 3], [4, 5, 6]])
Performance
IsoTree uses OpenMP when possible for best performance. To enable OpenMP on Mac, run:
brew install libomp
Then reinstall the gem.
gem uninstall isotree --force
bundle install
History
View the changelog
Contributing
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 --recursive https://github.com/ankane/isotree.git
cd isotree
bundle install
bundle exec rake compile
bundle exec rake test