pub struct KNNImputer<F> { /* private fields */ }Expand description
An unfitted KNN imputer.
Calling Fit::fit stores the training data and returns a
FittedKNNImputer that can impute missing values in new data.
§Parameters
n_neighbors— number of nearest neighbors to use (default 5).weights— how to weight neighbor contributions (defaultUniform).
§Examples
use ferrolearn_preprocess::knn_imputer::{KNNImputer, KNNWeights};
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let imputer = KNNImputer::<f64>::new(2, KNNWeights::Uniform);
let x = array![[1.0, 2.0], [3.0, 4.0], [5.0, f64::NAN]];
let fitted = imputer.fit(&x, &()).unwrap();
let out = fitted.transform(&x).unwrap();
assert!(!out[[2, 1]].is_nan());Implementations§
Source§impl<F: Float + Send + Sync + 'static> KNNImputer<F>
impl<F: Float + Send + Sync + 'static> KNNImputer<F>
Sourcepub fn new(n_neighbors: usize, weights: KNNWeights) -> Self
pub fn new(n_neighbors: usize, weights: KNNWeights) -> Self
Create a new KNNImputer with the given parameters.
Sourcepub fn n_neighbors(&self) -> usize
pub fn n_neighbors(&self) -> usize
Return the number of neighbors.
Sourcepub fn weights(&self) -> KNNWeights
pub fn weights(&self) -> KNNWeights
Return the weighting strategy.
Trait Implementations§
Source§impl<F: Clone> Clone for KNNImputer<F>
impl<F: Clone> Clone for KNNImputer<F>
Source§fn clone(&self) -> KNNImputer<F>
fn clone(&self) -> KNNImputer<F>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<F: Debug> Debug for KNNImputer<F>
impl<F: Debug> Debug for KNNImputer<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for KNNImputer<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for KNNImputer<F>
Source§fn fit(&self, x: &Array2<F>, _y: &()) -> Result<FittedKNNImputer<F>, FerroError>
fn fit(&self, x: &Array2<F>, _y: &()) -> Result<FittedKNNImputer<F>, FerroError>
Fit the imputer by storing the training data.
§Errors
FerroError::InsufficientSamplesif the input has zero rows.FerroError::InvalidParameterifn_neighborsis zero or exceeds the number of samples.
Source§type Fitted = FittedKNNImputer<F>
type Fitted = FittedKNNImputer<F>
The fitted model type returned by
fit.Source§type Error = FerroError
type Error = FerroError
The error type returned by
fit.Source§impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for KNNImputer<F>
impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for KNNImputer<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
The error type for the combined fit-transform operation.
Auto Trait Implementations§
impl<F> Freeze for KNNImputer<F>
impl<F> RefUnwindSafe for KNNImputer<F>where
F: RefUnwindSafe,
impl<F> Send for KNNImputer<F>where
F: Send,
impl<F> Sync for KNNImputer<F>where
F: Sync,
impl<F> Unpin for KNNImputer<F>where
F: Unpin,
impl<F> UnsafeUnpin for KNNImputer<F>
impl<F> UnwindSafe for KNNImputer<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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.