pub struct OrdinalEncoder;Expand description
An unfitted ordinal encoder.
Calling Fit::fit on an Array2<String> learns, for each column, a
mapping from the unique string categories (in order of first appearance)
to consecutive integers 0, 1, 2, ..., and returns a
FittedOrdinalEncoder.
§Examples
use ferrolearn_preprocess::ordinal_encoder::OrdinalEncoder;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::Array2;
let enc = OrdinalEncoder::new();
let data = Array2::from_shape_vec(
(3, 2),
vec![
"cat".to_string(), "small".to_string(),
"dog".to_string(), "large".to_string(),
"cat".to_string(), "small".to_string(),
],
).unwrap();
let fitted = enc.fit(&data, &()).unwrap();
let encoded = fitted.transform(&data).unwrap();
assert_eq!(encoded[[0, 0]], 0); // "cat" is index 0 in col 0
assert_eq!(encoded[[1, 0]], 1); // "dog" is index 1 in col 0Implementations§
Trait Implementations§
Source§impl Clone for OrdinalEncoder
impl Clone for OrdinalEncoder
Source§fn clone(&self) -> OrdinalEncoder
fn clone(&self) -> OrdinalEncoder
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 Debug for OrdinalEncoder
impl Debug for OrdinalEncoder
Source§impl Default for OrdinalEncoder
impl Default for OrdinalEncoder
Source§fn default() -> OrdinalEncoder
fn default() -> OrdinalEncoder
Returns the “default value” for a type. Read more
Source§impl Fit<ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>, ()> for OrdinalEncoder
impl Fit<ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>, ()> for OrdinalEncoder
Source§fn fit(
&self,
x: &Array2<String>,
_y: &(),
) -> Result<FittedOrdinalEncoder, FerroError>
fn fit( &self, x: &Array2<String>, _y: &(), ) -> Result<FittedOrdinalEncoder, FerroError>
Fit the encoder by building per-column category-to-index mappings.
Categories are recorded in order of first appearance in each column.
§Errors
Returns FerroError::InsufficientSamples if the input has zero rows.
Source§type Fitted = FittedOrdinalEncoder
type Fitted = FittedOrdinalEncoder
The fitted model type returned by
fit.Source§type Error = FerroError
type Error = FerroError
The error type returned by
fit.Source§impl FitTransform<ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>> for OrdinalEncoder
impl FitTransform<ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>> for OrdinalEncoder
Source§fn fit_transform(&self, x: &Array2<String>) -> Result<Array2<usize>, FerroError>
fn fit_transform(&self, x: &Array2<String>) -> Result<Array2<usize>, FerroError>
Fit the encoder on x and return the encoded output in one step.
§Errors
Returns an error if fitting or transformation fails.
Source§type FitError = FerroError
type FitError = FerroError
The error type for the combined fit-transform operation.
Source§impl Transform<ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>> for OrdinalEncoder
Implement Transform on the unfitted encoder to satisfy the
FitTransform: Transform supertrait bound.
impl Transform<ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>> for OrdinalEncoder
Implement Transform on the unfitted encoder to satisfy the
FitTransform: Transform supertrait bound.
Auto Trait Implementations§
impl Freeze for OrdinalEncoder
impl RefUnwindSafe for OrdinalEncoder
impl Send for OrdinalEncoder
impl Sync for OrdinalEncoder
impl Unpin for OrdinalEncoder
impl UnsafeUnpin for OrdinalEncoder
impl UnwindSafe for OrdinalEncoder
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.