Expand description

Naive Bayes Classifiers

The classifier supports Gaussian, Bernoulli and Multinomial distributions.

A naive Bayes classifier works by treating the features of each input as independent observations. Under this assumption we utilize Bayes’ rule to compute the probability that each input belongs to a given class.

Examples

use rusty_machine::learning::naive_bayes::{NaiveBayes, Gaussian};
use rusty_machine::linalg::Matrix;
use rusty_machine::learning::SupModel;

let inputs = Matrix::new(6, 2, vec![1.0, 1.1,
                                    1.1, 0.9,
                                    2.2, 2.3,
                                    2.5, 2.7,
                                    5.2, 4.3,
                                    6.2, 7.3]);

let targets = Matrix::new(6,3, vec![1.0, 0.0, 0.0,
                                    1.0, 0.0, 0.0,
                                    0.0, 1.0, 0.0,
                                    0.0, 1.0, 0.0,
                                    0.0, 0.0, 1.0,
                                    0.0, 0.0, 1.0]);

// Create a Gaussian Naive Bayes classifier.
let mut model = NaiveBayes::<Gaussian>::new();

// Train the model.
model.train(&inputs, &targets).unwrap();

// Predict the classes on the input data
let outputs = model.predict(&inputs).unwrap();

// Will output the target classes - otherwise our classifier is bad!
println!("Final outputs --\n{}", outputs);

Structs

The Bernoulli Naive Bayes model distribution.
The Gaussian Naive Bayes model distribution.
The Multinomial Naive Bayes model distribution.
The Naive Bayes model.

Traits

Naive Bayes Distribution.