pub struct SimpleImputer<F> { /* private fields */ }Expand description
An unfitted simple imputer.
Calling Fit::fit computes the per-column fill values according to
the chosen ImputeStrategy and returns a FittedSimpleImputer that
can transform new data by replacing NaN values with those fill values.
NaN values are ignored when computing statistics during fitting — e.g.
the Mean strategy computes the mean of only the non-NaN elements.
§Examples
use ferrolearn_preprocess::imputer::{SimpleImputer, ImputeStrategy};
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let imputer = SimpleImputer::<f64>::new(ImputeStrategy::Mean);
let x = array![[1.0, f64::NAN], [3.0, 4.0], [5.0, 6.0]];
let fitted = imputer.fit(&x, &()).unwrap();
let out = fitted.transform(&x).unwrap();
// NaN in column 1 row 0 is replaced with the mean of column 1 = (4+6)/2 = 5.0
assert!((out[[0, 1]] - 5.0).abs() < 1e-10);Implementations§
Source§impl<F: Float + Send + Sync + 'static> SimpleImputer<F>
impl<F: Float + Send + Sync + 'static> SimpleImputer<F>
Sourcepub fn new(strategy: ImputeStrategy<F>) -> Self
pub fn new(strategy: ImputeStrategy<F>) -> Self
Create a new SimpleImputer with the given strategy.
Sourcepub fn strategy(&self) -> &ImputeStrategy<F>
pub fn strategy(&self) -> &ImputeStrategy<F>
Return the imputation strategy.
Trait Implementations§
Source§impl<F: Clone> Clone for SimpleImputer<F>
impl<F: Clone> Clone for SimpleImputer<F>
Source§fn clone(&self) -> SimpleImputer<F>
fn clone(&self) -> SimpleImputer<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for SimpleImputer<F>
impl<F: Debug> Debug for SimpleImputer<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for SimpleImputer<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for SimpleImputer<F>
Source§fn fit(
&self,
x: &Array2<F>,
_y: &(),
) -> Result<FittedSimpleImputer<F>, FerroError>
fn fit( &self, x: &Array2<F>, _y: &(), ) -> Result<FittedSimpleImputer<F>, FerroError>
Fit the imputer by computing per-column fill values.
NaN values are excluded from the statistic computation. Columns that
are entirely NaN at fit time are filled with F::zero() for Mean and
Median, and F::zero() for MostFrequent.
§Errors
Returns FerroError::InsufficientSamples if the input has zero rows.
Source§type Fitted = FittedSimpleImputer<F>
type Fitted = FittedSimpleImputer<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SimpleImputer<F>
impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SimpleImputer<F>
Source§fn fit_transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn fit_transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Fit the imputer on x and return the imputed output in one step.
§Errors
Returns an error if fitting fails (e.g. zero rows).
Source§type FitError = FerroError
type FitError = FerroError
Source§impl PipelineTransformer for SimpleImputer<f64>
impl PipelineTransformer for SimpleImputer<f64>
Source§fn fit_pipeline(
&self,
x: &Array2<f64>,
_y: &Array1<f64>,
) -> Result<Box<dyn FittedPipelineTransformer>, FerroError>
fn fit_pipeline( &self, x: &Array2<f64>, _y: &Array1<f64>, ) -> Result<Box<dyn FittedPipelineTransformer>, FerroError>
Source§impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SimpleImputer<F>
Implement Transform on the unfitted imputer to satisfy the
FitTransform: Transform supertrait bound. Always returns an error.
impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SimpleImputer<F>
Implement Transform on the unfitted imputer to satisfy the
FitTransform: Transform supertrait bound. Always returns an error.
Source§fn transform(&self, _x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn transform(&self, _x: &Array2<F>) -> Result<Array2<F>, FerroError>
Always returns an error — the imputer must be fitted first.
Use Fit::fit to produce a FittedSimpleImputer, then call
Transform::transform on that.
Source§type Error = FerroError
type Error = FerroError
transform.Auto Trait Implementations§
impl<F> Freeze for SimpleImputer<F>where
F: Freeze,
impl<F> RefUnwindSafe for SimpleImputer<F>where
F: RefUnwindSafe,
impl<F> Send for SimpleImputer<F>where
F: Send,
impl<F> Sync for SimpleImputer<F>where
F: Sync,
impl<F> Unpin for SimpleImputer<F>where
F: Unpin,
impl<F> UnsafeUnpin for SimpleImputer<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for SimpleImputer<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more