Struct linfa_bayes::GaussianNbParams
source · [−]pub struct GaussianNbParams<F, L>(_);
Expand description
A hyper-parameter set during construction
The parameter set can be verified into a
GaussianNbValidParams
by calling
ParamGuard::check. It is also possible to directly fit a model with
Fit::fit or
FitWith::fit_with which implicitely verifies the parameter set
prior to the model estimation and forwards any error.
Parameters
Name | Default | Purpose | Range |
---|---|---|---|
var_smoothing | 1e-9 | Stabilize variance calculation if ratios are small in update step | [0, inf) |
Errors
The following errors can come from invalid hyper-parameters:
Returns InvalidSmoothing
if the smoothing
parameter is negative.
Example
use linfa_bayes::{GaussianNbParams, GaussianNbValidParams, Result};
use linfa::prelude::*;
use ndarray::array;
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 ds = DatasetView::new(x.view(), y.view());
// create a new parameter set with variance smoothing equals `1e-5`
let unchecked_params = GaussianNbParams::new()
.var_smoothing(1e-5);
// fit model with unchecked parameter set
let model = unchecked_params.fit(&ds)?;
// transform into a verified parameter set
let checked_params = unchecked_params.check()?;
// update model with the verified parameters, this only returns
// errors originating from the fitting process
let model = checked_params.fit_with(Some(model), &ds)?;
Implementations
sourceimpl<F: Float, L> GaussianNbParams<F, L>
impl<F: Float, L> GaussianNbParams<F, L>
sourcepub fn new() -> Self
pub fn new() -> Self
Create new GaussianNbParams set with default values for its parameters
sourcepub fn var_smoothing(self, var_smoothing: F) -> Self
pub fn var_smoothing(self, var_smoothing: F) -> Self
Specifies the portion of the largest variance of all the features that is added to the variance for calculation stability
Trait Implementations
sourceimpl<F: Float, L> Default for GaussianNbParams<F, L>
impl<F: Float, L> Default for GaussianNbParams<F, L>
sourceimpl<F: Float, L> ParamGuard for GaussianNbParams<F, L>
impl<F: Float, L> ParamGuard for GaussianNbParams<F, L>
type Checked = GaussianNbValidParams<F, L>
type Checked = GaussianNbValidParams<F, L>
The checked hyperparameters
type Error = NaiveBayesError
type Error = NaiveBayesError
Error type resulting from failed hyperparameter checking
sourcefn check_ref(&self) -> Result<&Self::Checked, Self::Error>
fn check_ref(&self) -> Result<&Self::Checked, Self::Error>
Checks the hyperparameters and returns a reference to the checked hyperparameters if successful Read more
sourcefn check(self) -> Result<Self::Checked, Self::Error>
fn check(self) -> Result<Self::Checked, Self::Error>
Checks the hyperparameters and returns the checked hyperparameters if successful
sourcefn check_unwrap(self) -> Self::Checked
fn check_unwrap(self) -> Self::Checked
Calls check()
and unwraps the result
Auto Trait Implementations
impl<F, L> RefUnwindSafe for GaussianNbParams<F, L> where
F: RefUnwindSafe,
L: RefUnwindSafe,
impl<F, L> Send for GaussianNbParams<F, L> where
F: Send,
L: Send,
impl<F, L> Sync for GaussianNbParams<F, L> where
F: Sync,
L: Sync,
impl<F, L> Unpin for GaussianNbParams<F, L> where
F: Unpin,
L: Unpin,
impl<F, L> UnwindSafe for GaussianNbParams<F, L> where
F: UnwindSafe,
L: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more