pub struct OneHotEncoder<F> { /* private fields */ }Expand description
An unfitted one-hot encoder for multi-column categorical data.
Input: Array2<usize> where each column contains non-negative integer
category indices. Calling Fit::fit learns the set of categories per
column and returns a FittedOneHotEncoder.
§Examples
use ferrolearn_preprocess::OneHotEncoder;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let enc = OneHotEncoder::<f64>::new();
let x = array![[0usize, 1], [1, 0], [2, 1]];
let fitted = enc.fit(&x, &()).unwrap();
let encoded = fitted.transform(&x).unwrap();Implementations§
Trait Implementations§
Source§impl<F: Clone> Clone for OneHotEncoder<F>
impl<F: Clone> Clone for OneHotEncoder<F>
Source§fn clone(&self) -> OneHotEncoder<F>
fn clone(&self) -> OneHotEncoder<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 OneHotEncoder<F>
impl<F: Debug> Debug for OneHotEncoder<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>, ()> for OneHotEncoder<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>, ()> for OneHotEncoder<F>
Source§fn fit(
&self,
x: &Array2<usize>,
_y: &(),
) -> Result<FittedOneHotEncoder<F>, FerroError>
fn fit( &self, x: &Array2<usize>, _y: &(), ) -> Result<FittedOneHotEncoder<F>, FerroError>
Fit the encoder by determining the number of unique categories per column.
The number of categories for column j is max(x[:, j]) + 1.
§Errors
Returns FerroError::InsufficientSamples if the input has zero rows.
Source§type Fitted = FittedOneHotEncoder<F>
type Fitted = FittedOneHotEncoder<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>> for OneHotEncoder<F>
impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>> for OneHotEncoder<F>
Source§fn fit_transform(&self, x: &Array2<usize>) -> Result<Array2<F>, FerroError>
fn fit_transform(&self, x: &Array2<usize>) -> Result<Array2<F>, FerroError>
Fit the encoder on x and return the one-hot encoded output in one step.
§Errors
Returns an error if fitting or transformation fails.
Source§type FitError = FerroError
type FitError = FerroError
Source§impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>> for OneHotEncoder<F>
Implement Transform on the unfitted encoder to satisfy the FitTransform: Transform
supertrait bound. Calling transform on an unfitted encoder always returns an error.
impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>> for OneHotEncoder<F>
Implement Transform on the unfitted encoder to satisfy the FitTransform: Transform
supertrait bound. Calling transform on an unfitted encoder always returns an error.
Source§fn transform(&self, _x: &Array2<usize>) -> Result<Array2<F>, FerroError>
fn transform(&self, _x: &Array2<usize>) -> Result<Array2<F>, FerroError>
Always returns an error — the encoder must be fitted first.
Use Fit::fit to produce a FittedOneHotEncoder, then call
Transform::transform on that.
Source§type Error = FerroError
type Error = FerroError
transform.Auto Trait Implementations§
impl<F> Freeze for OneHotEncoder<F>
impl<F> RefUnwindSafe for OneHotEncoder<F>where
F: RefUnwindSafe,
impl<F> Send for OneHotEncoder<F>where
F: Send,
impl<F> Sync for OneHotEncoder<F>where
F: Sync,
impl<F> Unpin for OneHotEncoder<F>where
F: Unpin,
impl<F> UnsafeUnpin for OneHotEncoder<F>
impl<F> UnwindSafe for OneHotEncoder<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