[−][src]Module smartcore::naive_bayes::multinomial
Multinomial Naive Bayes
Multinomial Naive Bayes classifier is a variant of Naive Bayes for the multinomially distributed data. It is often used for discrete data with predictors representing the number of times an event was observed in a particular instance, for example frequency of the words present in the document.
Example:
use smartcore::linalg::naive::dense_matrix::*; use smartcore::naive_bayes::multinomial::MultinomialNB; // 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., 2., 0., 0., 0., 0.], &[0., 2., 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 = MultinomialNB::fit(&x, &y, Default::default()).unwrap(); // Testing data point is: // Chinese Chinese Chinese Tokyo Japan let x_test = DenseMatrix::<f64>::from_2d_array(&[&[0., 3., 1., 0., 0., 1.]]); let y_hat = nb.predict(&x_test).unwrap();
References:
Structs
MultinomialNB | MultinomialNB implements the categorical naive Bayes algorithm for categorically distributed data. |
MultinomialNBParameters |
|