An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

# IsolationForest
[![ci-badge](https://github.com/jettify/isoforest/workflows/CI/badge.svg)](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