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 在 算法 中
每月 124 次下载
在 2 个crate中使用(通过 bliss-audio)
260KB
362 行
扩展隔离森林
这是对扩展隔离森林中描述的异常检测算法的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