[−][src]Module smartcore::naive_bayes::bernoulli
Bernoulli Naive Bayes
Bernoulli Naive Bayes classifier is a variant of Naive Bayes for the data that is distributed according to multivariate Bernoulli distribution. It is used for discrete data with binary features. One example of a binary feature is a word that occurs in the text or not.
Example:
use smartcore::linalg::naive::dense_matrix::*; use smartcore::naive_bayes::bernoulli::BernoulliNB; // Training data points are: // Chinese Beijing Chinese (class: China) // Chinese Chinese Shanghai (class: China) // Chinese Macao (class: China) // Tokyo Japan Chinese (class: Japan) let x = DenseMatrix::<f64>::from_2d_array(&[ &[1., 1., 0., 0., 0., 0.], &[0., 1., 0., 0., 1., 0.], &[0., 1., 0., 1., 0., 0.], &[0., 1., 1., 0., 0., 1.], ]); let y = vec![0., 0., 0., 1.]; let nb = BernoulliNB::fit(&x, &y, Default::default()).unwrap(); // Testing data point is: // Chinese Chinese Chinese Tokyo Japan let x_test = DenseMatrix::<f64>::from_2d_array(&[&[0., 1., 1., 0., 0., 1.]]); let y_hat = nb.predict(&x_test).unwrap();
References:
Structs
BernoulliNB | BernoulliNB implements the categorical naive Bayes algorithm for categorically distributed data. |
BernoulliNBParameters |
|