pub struct IterativeImputer<F> { /* private fields */ }Expand description
An unfitted iterative imputer.
Calling Fit::fit learns the per-feature BayesianRidge models and
returns a FittedIterativeImputer that can impute missing values in new
data by deterministically replaying the learned imputation sequence.
§Parameters
max_iter— maximum number of imputation rounds (default 10).tol— convergence tolerance on the inf-norm of the change scaled bymax|X_observed|(default 1e-3).initial_strategy— strategy for the initial fill (defaultMean).imputation_order— feature visit order (defaultAscending).min_value/max_value— imputed-value clip bounds (default ±∞).
§Examples
use ferrolearn_preprocess::iterative_imputer::{IterativeImputer, InitialStrategy};
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let imputer = IterativeImputer::<f64>::new(10, 1e-3, InitialStrategy::Mean);
let x = array![[1.0, 2.0], [3.0, f64::NAN], [f64::NAN, 6.0]];
let fitted = imputer.fit(&x, &()).unwrap();
let out = fitted.transform(&x).unwrap();
assert!(!out[[1, 1]].is_nan());
assert!(!out[[2, 0]].is_nan());Implementations§
Source§impl<F: Float + Send + Sync + 'static> IterativeImputer<F>
impl<F: Float + Send + Sync + 'static> IterativeImputer<F>
Sourcepub fn new(max_iter: usize, tol: F, initial_strategy: InitialStrategy) -> Self
pub fn new(max_iter: usize, tol: F, initial_strategy: InitialStrategy) -> Self
Create a new IterativeImputer with the given core parameters and the
sklearn defaults for imputation_order (Ascending) and the
min_value/max_value clip (-inf/+inf).
Sourcepub fn with_imputation_order(self, order: ImputationOrder) -> Self
pub fn with_imputation_order(self, order: ImputationOrder) -> Self
Set the feature imputation order (default Ascending), mirroring
sklearn’s imputation_order (_iterative.py:316).
Sourcepub fn with_min_value(self, min_value: F) -> Self
pub fn with_min_value(self, min_value: F) -> Self
Set the minimum imputed value (the clip lower bound), mirroring sklearn’s
min_value (_iterative.py:318, default -inf).
Sourcepub fn with_max_value(self, max_value: F) -> Self
pub fn with_max_value(self, max_value: F) -> Self
Set the maximum imputed value (the clip upper bound), mirroring sklearn’s
max_value (_iterative.py:319, default +inf).
Sourcepub fn initial_strategy(&self) -> InitialStrategy
pub fn initial_strategy(&self) -> InitialStrategy
Return the initial imputation strategy.
Sourcepub fn imputation_order(&self) -> ImputationOrder
pub fn imputation_order(&self) -> ImputationOrder
Return the feature imputation order.
Trait Implementations§
Source§impl<F: Clone> Clone for IterativeImputer<F>
impl<F: Clone> Clone for IterativeImputer<F>
Source§fn clone(&self) -> IterativeImputer<F>
fn clone(&self) -> IterativeImputer<F>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for IterativeImputer<F>
impl<F: Debug> Debug for IterativeImputer<F>
Source§impl<F: ImputerFloat> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for IterativeImputer<F>
impl<F: ImputerFloat> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for IterativeImputer<F>
Source§fn fit(
&self,
x: &Array2<F>,
_y: &(),
) -> Result<FittedIterativeImputer<F>, FerroError>
fn fit( &self, x: &Array2<F>, _y: &(), ) -> Result<FittedIterativeImputer<F>, FerroError>
Fit the iterative imputer by round-robin BayesianRidge regression,
mirroring sklearn.impute.IterativeImputer.fit_transform
(sklearn/impute/_iterative.py:693-831) in the sample_posterior=False
path.
Features with missing values are visited in imputation_order (default
Ascending); each is fit on the rows where it is observed and its
missing rows are predicted and clipped to [min_value, max_value]. The
round-robin repeats up to max_iter rounds, breaking early when
max|Xt - Xt_prev| < tol * max|X_observed| (inf-norm convergence,
:780,811,818).
§Errors
FerroError::InsufficientSamplesif the input has zero rows.- Propagates
FerroErrorfrom the per-featureBayesianRidgefit.
max_iter == 0 is valid (matching sklearn _iterative.py:750-752): the
iteration loop runs zero times and fit returns the initial fill with
n_iter() == 0.
Source§type Fitted = FittedIterativeImputer<F>
type Fitted = FittedIterativeImputer<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F: ImputerFloat> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for IterativeImputer<F>
impl<F: ImputerFloat> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for IterativeImputer<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.
Source§type FitError = FerroError
type FitError = FerroError
Auto Trait Implementations§
impl<F> Freeze for IterativeImputer<F>where
F: Freeze,
impl<F> RefUnwindSafe for IterativeImputer<F>where
F: RefUnwindSafe,
impl<F> Send for IterativeImputer<F>where
F: Send,
impl<F> Sync for IterativeImputer<F>where
F: Sync,
impl<F> Unpin for IterativeImputer<F>where
F: Unpin,
impl<F> UnsafeUnpin for IterativeImputer<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for IterativeImputer<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,
impl<T, U> Imply<T> for U
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.