#分类 #贝叶斯 #机器 #统计 #学习 #机器学习

randomforests

一个简单的随机森林分类器

2 个版本

使用旧 Rust 2015

0.1.1 2019 年 2 月 19 日
0.1.0 2018 年 12 月 2 日

#489 in 科学

Apache-2.0

27KB
743

https://crates.io/crates/randomforests https://docs.rs/randomforests/

random-forests

Rust 库用于 随机森林

支持泛型不纯度度量

[x] 熵 [x] Gini

安装

将以下内容添加到您的 Cargo.toml

randomforests = "*"

使用

将 crate 和 RandomForests 添加到您的代码

extern crate randomforests;

use randomforests::RandomForest;

创建一个 Dataset 作为 Item 的集合

let mut dataset = Dataset::new();
let mut item1 = Item::new();
item1.insert("lang".to_string(), Value { data: "rust".to_string() });
item1.insert("typing".to_string(), Value { data: "static".to_string() });
dataset.push(item1);

let mut item2 = Item::new();
item2.insert("lang".to_string(), Value { data: "python".to_string() } );
item2.insert("typing".to_string(), Value { data: "dynamic".to_string() } );
dataset.push(item2);

let mut item3 = Item::new();
item3.insert("lang".to_string(), Value { data: "haskell".to_string() });
item3.insert("typing".to_string(), Value { data: "static".to_string() });
dataset.push(item3);

初始化分类器并通过传递 Dataset、一个 TreeConfig、树的数量和数据子样本大小来训练它

let mut config = TreeConfig::new();
config.decision = "lang".to_string();
let forest = RandomForest::build("lang".to_string(), config, &dataset, 100, 3);

创建一个问题作为 Item

let mut question = Item::new();
question.insert("typing".to_string(), Value { data: "static".to_string() });

并获取预测结果

let answer = RandomForest::predict(forest, question);
// answer = {Value { data: haskell }: 48, Value { data: rust }: 52}

依赖项

~570–800KB
~11K SLoC