pub struct TargetEncoder<F> { /* private fields */ }Expand description
An unfitted target encoder.
Takes a matrix of categorical integer features and a continuous (or binary) target vector at fit time. Each category is encoded as the smoothed mean of the target for that category.
§Parameters
smooth— smoothing factor (default 1.0). Higher values regularise more toward the global mean. Set to 0 for no smoothing.
§Examples
use ferrolearn_preprocess::target_encoder::TargetEncoder;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let enc = TargetEncoder::<f64>::new(1.0);
let x = array![[0usize, 1], [0, 0], [1, 1], [1, 0]];
let y = array![1.0, 2.0, 3.0, 4.0];
let fitted = enc.fit(&x, &y).unwrap();
let out = fitted.transform(&x).unwrap();
assert_eq!(out.shape(), &[4, 2]);Implementations§
Trait Implementations§
Source§impl<F: Clone> Clone for TargetEncoder<F>
impl<F: Clone> Clone for TargetEncoder<F>
Source§fn clone(&self) -> TargetEncoder<F>
fn clone(&self) -> TargetEncoder<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 TargetEncoder<F>
impl<F: Debug> Debug for TargetEncoder<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for TargetEncoder<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for TargetEncoder<F>
Source§fn fit(
&self,
x: &Array2<usize>,
y: &Array1<F>,
) -> Result<FittedTargetEncoder<F>, FerroError>
fn fit( &self, x: &Array2<usize>, y: &Array1<F>, ) -> Result<FittedTargetEncoder<F>, FerroError>
Fit the encoder by computing smoothed target means per category.
§Errors
FerroError::InsufficientSamplesif the input has zero rows.FerroError::ShapeMismatchifxrows andylength differ.FerroError::InvalidParameterifsmoothis negative.
Source§type Fitted = FittedTargetEncoder<F>
type Fitted = FittedTargetEncoder<F>
The fitted model type returned by
fit.Source§type Error = FerroError
type Error = FerroError
The error type returned by
fit.Auto Trait Implementations§
impl<F> Freeze for TargetEncoder<F>where
F: Freeze,
impl<F> RefUnwindSafe for TargetEncoder<F>where
F: RefUnwindSafe,
impl<F> Send for TargetEncoder<F>where
F: Send,
impl<F> Sync for TargetEncoder<F>where
F: Sync,
impl<F> Unpin for TargetEncoder<F>where
F: Unpin,
impl<F> UnsafeUnpin for TargetEncoder<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for TargetEncoder<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.