#机器学习 #森林 #隔离 #检测 #端口 #扩展 #异常检测

extended-isolation-forest

异常检测算法的Rust移植版

4个版本

0.2.3 2022年11月30日
0.2.2 2022年10月17日
0.2.1 2022年8月2日
0.2.0 2021年5月12日

#822算法

Download history 50/week @ 2024-04-01 10/week @ 2024-04-15 17/week @ 2024-04-22 63/week @ 2024-05-06 110/week @ 2024-05-13 38/week @ 2024-05-20 45/week @ 2024-05-27 42/week @ 2024-06-03 23/week @ 2024-06-10 40/week @ 2024-06-17 15/week @ 2024-06-24

每月 124 次下载
2 个crate中使用(通过 bliss-audio

MIT 协议

260KB
362

扩展隔离森林

Latest Version dependency status

这是对扩展隔离森林中描述的异常检测算法的Rust移植版,并在https://github.com/sahandha/eif中实现。有关详细描述,请参阅论文或GitHub仓库。

此crate需要rust >= 1.51,因为它使用了min_const_generics

包含带有serde功能的可选serde支持。

示例

use rand::distributions::Uniform;
use rand::Rng;
use extended_isolation_forest::{Forest, ForestOptions};

fn make_f64_forest() -> Forest<f64, 3> {
    let rng = &mut rand::thread_rng();
    let distribution = Uniform::new(-4., 4.);
    let distribution2 = Uniform::new(10., 50.);
    let values: Vec<_> = (0..3000)
        .map(|_| [rng.sample(distribution), rng.sample(distribution), rng.sample(distribution2)])
        .collect();

    let options = ForestOptions {
        n_trees: 150,
        sample_size: 200,
        max_tree_depth: None,
        extension_level: 1,
    };
    Forest::from_slice(values.as_slice(), &options).unwrap()
}

fn main() {
    let forest = make_f64_forest();

    // no anomaly
    assert!(forest.score(&[1.0, 3.0, 25.0]) < 0.5);
    assert!(forest.score(&[-1.0, 3.0, 25.0]) < 0.5);

    // anomalies
    assert!(forest.score(&[-12.0, 6.0, 25.0]) > 0.5);
    assert!(forest.score(&[-1.0, 2.0, 60.0]) > 0.5);
    assert!(forest.score(&[-1.0, 2.0, 0.0]) > 0.5);
}

示例:检测运动记录中的异常

此示例使用智能手机在上下楼梯时记录的加速度数据。异常是由一个小跳跃引起的。代码位于examples/walking_stairs.rs,数据本身位于data/acceleration。所有此示例的数据都是通过phyphox智能手机应用收集的。

可以使用以下命令执行示例

cargo run --example walking_stairs

预期结果

依赖项

~1–1.3MB
~25K SLoC