Crates.io | naivebayes |
lib.rs | naivebayes |
version | 0.1.2 |
source | src |
created_at | 2018-11-28 19:42:22.059579 |
updated_at | 2019-03-25 18:39:48.159074 |
description | A simple Naive Bayes classifier. |
homepage | https://gitlab.com/ruivieira/naive-bayes |
repository | https://gitlab.com/ruivieira/naive-bayes |
max_upload_size | |
id | 99122 |
size | 27,663 |
A Naive Bayes classifier written in Rust.
Add to your Cargo.toml
:
naivebayes = "0.1.1"
Add the crate and NaiveBayes
to your code:
extern crate naivebayes;
use naivebayes::NaiveBayes;
Initialise the classifier and train it classifier by passing Vec<String>
of tokens, along with a label:
let mut nb = NaiveBayes::new();
nb.train(&tokens, &label);
Use another set of tokens as Vec<String>
to classify it:
let classification = nb.classify(&tokens_classify);
print!("classification = {:?}", classification);
Alternitavely, to prevent a potential calculation underflow with very small probabilities, the log_classify
method can be used:
let classification = nb.log_classify(&tokens_classify);
print!("classification = {:?}", classification);