3 releases

Uses old Rust 2015

0.1.2 Mar 25, 2019
0.1.1 Mar 24, 2019
0.1.0 Nov 28, 2018

#851 in Science

34 downloads per month
Used in grizzly

Apache-2.0

15KB
344 lines

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

naive-bayes

A Naive Bayes classifier written in Rust.

installation

Add to your Cargo.toml:

naivebayes = "0.1.1"

usage

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);

No runtime deps