3 个版本
使用旧的 Rust 2015
| 0.1.2 | 2019年3月25日 |
|---|---|
| 0.1.1 | 2019年3月24日 |
| 0.1.0 | 2018年11月28日 |
#851 在 科学
34 每月下载量
用于 grizzly
15KB
344 行
naive-bayes
用 Rust 编写的朴素贝叶斯分类器。
安装
将以下内容添加到您的 Cargo.toml
naivebayes = "0.1.1"
使用
将 crate 和 NaiveBayes 添加到您的代码中
extern crate naivebayes;
use naivebayes::NaiveBayes;
通过传递 Vec<String> 的标记以及一个标签来初始化分类器并训练它
let mut nb = NaiveBayes::new();
nb.train(&tokens, &label);
使用另一组标记作为 Vec<String> 来进行分类
let classification = nb.classify(&tokens_classify);
print!("classification = {:?}", classification);
或者,为了防止非常大的概率下的潜在计算下溢,可以使用 log_classify 方法
let classification = nb.log_classify(&tokens_classify);
print!("classification = {:?}", classification);