Skip to main content

MultinomialNB

Struct MultinomialNB 

Source
pub struct MultinomialNB<TX: Number + Unsigned, TY: Number + Ord + Unsigned, X: Array2<TX>, Y: Array1<TY>> { /* private fields */ }
Expand description

MultinomialNB implements the naive Bayes algorithm for multinomially distributed data.

Implementations§

Source§

impl<TX: Number + Unsigned, TY: Number + Ord + Unsigned, X: Array2<TX>, Y: Array1<TY>> MultinomialNB<TX, TY, X, Y>

Source

pub fn fit( x: &X, y: &Y, parameters: MultinomialNBParameters, ) -> Result<Self, Failed>

Fits MultinomialNB with given data

  • x - training data of size NxM where N is the number of samples and M is the number of features.
  • y - vector with target values (classes) of length N.
  • parameters - additional parameters like class priors, alpha for smoothing and binarizing threshold.
Source

pub fn predict(&self, x: &X) -> Result<Y, Failed>

Estimates the class labels for the provided data.

  • x - data of shape NxM where N is number of data points to estimate and M is number of features.

Returns a vector of size N with class estimates.

Source

pub fn classes(&self) -> &Vec<TY>

Class labels known to the classifier. Returns a vector of size n_classes.

Source

pub fn class_count(&self) -> &Vec<usize>

Number of training samples observed in each class. Returns a vector of size n_classes.

Source

pub fn feature_log_prob(&self) -> &Vec<Vec<f64>>

Empirical log probability of features given a class, P(x_i|y). Returns a 2d vector of shape (n_classes, n_features)

Source

pub fn n_features(&self) -> usize

Number of features of each sample

Source

pub fn feature_count(&self) -> &Vec<Vec<usize>>

Number of samples encountered for each (class, feature) Returns a 2d vector of shape (n_classes, n_features)

Trait Implementations§

Source§

impl<TX: Debug + Number + Unsigned, TY: Debug + Number + Ord + Unsigned, X: Debug + Array2<TX>, Y: Debug + Array1<TY>> Debug for MultinomialNB<TX, TY, X, Y>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TX: Number + Unsigned, TY: Number + Ord + Unsigned, X: Array2<TX>, Y: Array1<TY>> Display for MultinomialNB<TX, TY, X, Y>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TX: PartialEq + Number + Unsigned, TY: PartialEq + Number + Ord + Unsigned, X: PartialEq + Array2<TX>, Y: PartialEq + Array1<TY>> PartialEq for MultinomialNB<TX, TY, X, Y>

Source§

fn eq(&self, other: &MultinomialNB<TX, TY, X, Y>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<TX: Number + Unsigned, TY: Number + Ord + Unsigned, X: Array2<TX>, Y: Array1<TY>> Predictor<X, Y> for MultinomialNB<TX, TY, X, Y>

Source§

fn predict(&self, x: &X) -> Result<Y, Failed>

Estimate target values from new data. Read more
Source§

impl<TX: PartialEq + Number + Unsigned, TY: PartialEq + Number + Ord + Unsigned, X: PartialEq + Array2<TX>, Y: PartialEq + Array1<TY>> StructuralPartialEq for MultinomialNB<TX, TY, X, Y>

Source§

impl<TX: Number + Unsigned, TY: Number + Ord + Unsigned, X: Array2<TX>, Y: Array1<TY>> SupervisedEstimator<X, Y, MultinomialNBParameters> for MultinomialNB<TX, TY, X, Y>

Source§

fn new() -> Self

Empty constructor, instantiate an empty estimator. Object is dropped as soon as fit() is called. used to pass around the correct fit() implementation. by calling ::fit(). mostly used to be used with model_selection::cross_validate(...)
Source§

fn fit( x: &X, y: &Y, parameters: MultinomialNBParameters, ) -> Result<Self, Failed>

Fit a model to a training dataset, estimate model’s parameters. Read more

Auto Trait Implementations§

§

impl<TX, TY, X, Y> Freeze for MultinomialNB<TX, TY, X, Y>

§

impl<TX, TY, X, Y> RefUnwindSafe for MultinomialNB<TX, TY, X, Y>

§

impl<TX, TY, X, Y> Send for MultinomialNB<TX, TY, X, Y>
where TX: Send, TY: Send, X: Send, Y: Send,

§

impl<TX, TY, X, Y> Sync for MultinomialNB<TX, TY, X, Y>
where TX: Sync, TY: Sync, X: Sync, Y: Sync,

§

impl<TX, TY, X, Y> Unpin for MultinomialNB<TX, TY, X, Y>
where TX: Unpin, TY: Unpin, X: Unpin, Y: Unpin,

§

impl<TX, TY, X, Y> UnsafeUnpin for MultinomialNB<TX, TY, X, Y>

§

impl<TX, TY, X, Y> UnwindSafe for MultinomialNB<TX, TY, X, Y>
where TX: UnwindSafe, TY: UnwindSafe, X: UnwindSafe, Y: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.