naivebayes 0.1.2

A simple Naive Bayes classifier.
Documentation
  • Coverage
  • 66.67%
    4 out of 6 items documented0 out of 5 items with examples
  • Size
  • Source code size: 27.66 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 218.92 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ruivieira/naive-bayes
    1 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ruivieira

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