https://github.com/jettify/isoforest
Isolation forest implementation in Rust.
https://github.com/jettify/isoforest
Last synced: 17 days ago
JSON representation
Isolation forest implementation in Rust.
- Host: GitHub
- URL: https://github.com/jettify/isoforest
- Owner: jettify
- Created: 2021-03-13T04:44:17.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-26T21:36:06.000Z (over 2 years ago)
- Last Synced: 2025-02-03T22:38:15.924Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 64.5 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# IsolationForest
[](https://github.com/jettify/isoforest/actions?query=workflow%3ACI)Isolation forest implementation in Rust with option Python bindings.
# Example
```rust
use isoforest::{IsolationForestParams, IsolationTreeParams, MaxFeatures, MaxSamples};
use ndarray::array;
use std::io::Result;use linfa::dataset::DatasetBase;
use linfa::traits::{Fit, Predict};fn main() -> Result<()> {
let data = array![
[-2.0, -1.0],
[-1.0, -1.0],
[-1.0, -2.0],
[1.0, 1.0],
[1.0, 2.0],
[2.0, 1.0],
[6.0, 3.0], // anomaly
[-4.0, 7.0] // anomaly
];let dataset = DatasetBase::new(data.clone(), ());
let tree_params = IsolationTreeParams::default()
.with_max_samples(MaxSamples::Auto)
.with_max_features(MaxFeatures::Ratio(1.0))
.with_seed(3);let forest_prams = IsolationForestParams::new(3, &tree_params);
let model = forest_prams.fit(&dataset).unwrap();
let scores = model.decision_function(&data).unwrap();
let preds = model.predict(&data).unwrap();println!("{:?}", preds);
println!("{:?}", scores);
// expected result [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0]
Ok(())
}
```# Lincese
Licensed under the Apache License, Version 2.0