Struct linfa_bayes::GaussianNbParams[][src]

pub struct GaussianNbParams { /* fields omitted */ }

Gaussian Naive Bayes (GaussianNB)

The Gaussian Naive Bayes is a classification algorithm where the likelihood of the feature P(x_i | y) is assumed to be Gaussian, features are assumed to be independent, and the mean and variance are estimated using maximum likelihood.

Implementations

impl GaussianNbParams[src]

pub fn params() -> Self[src]

Create new GaussianNB model with default values for its parameters

pub fn var_smoothing(self, var_smoothing: f64) -> Self[src]

Specifies the portion of the largest variance of all the features that is added to the variance for calculation stability

Trait Implementations

impl Debug for GaussianNbParams[src]

impl Default for GaussianNbParams[src]

impl<F, D, L> Fit<'_, ArrayBase<D, Dim<[usize; 2]>>, L> for GaussianNbParams where
    F: Float,
    D: Data<Elem = F>,
    L: AsTargets<Elem = usize> + Labels<Elem = usize>, 
[src]

type Object = Result<GaussianNb<F>>

fn fit(&self, dataset: &DatasetBase<ArrayBase<D, Ix2>, L>) -> Self::Object[src]

Fit the model

Example

let x = array![
    [-2., -1.],
    [-1., -1.],
    [-1., -2.],
    [1., 1.],
    [1., 2.],
    [2., 1.]
];
let y = array![1, 1, 1, 2, 2, 2];

let data = Dataset::new(x, y);
let model = GaussianNbParams::params().fit(&data)?;
let pred = model.predict(&data);

assert_abs_diff_eq!(pred, data.try_single_target()?);

impl<F, D, L> IncrementalFit<'_, ArrayBase<D, Dim<[usize; 2]>>, L> for GaussianNbParams where
    F: Float,
    D: Data<Elem = F>,
    L: AsTargets<Elem = usize> + Labels<Elem = usize>, 
[src]

type ObjectIn = Option<GaussianNb<F>>

type ObjectOut = Result<Option<GaussianNb<F>>>

fn fit_with(
    &self,
    model_in: Self::ObjectIn,
    dataset: &DatasetBase<ArrayBase<D, Ix2>, L>
) -> Self::ObjectOut
[src]

Incrementally fit on a batch of samples

Example

let x = array![
    [-2., -1.],
    [-1., -1.],
    [-1., -2.],
    [1., 1.],
    [1., 2.],
    [2., 1.]
];
let y = array![1, 1, 1, 2, 2, 2];

let mut clf = GaussianNbParams::params();
let mut model = None;

for (x, y) in x
    .axis_chunks_iter(Axis(0), 2)
    .zip(y.axis_chunks_iter(Axis(0), 2))
{
    model = clf.fit_with(model, &DatasetView::new(x, y))?;
}

let pred = model.as_ref().unwrap().predict(&x);

assert_abs_diff_eq!(pred, y);

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,