pub struct LabelEncoder;Expand description
An unfitted label encoder.
Calling Fit::fit on an Array1<String> learns an alphabetically
ordered mapping from unique string labels to integer indices
0, 1, ..., n_classes - 1 and returns a FittedLabelEncoder.
§Examples
use ferrolearn_preprocess::LabelEncoder;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let enc = LabelEncoder::new();
let labels = array!["cat".to_string(), "dog".to_string(), "cat".to_string()];
let fitted = enc.fit(&labels, &()).unwrap();
let encoded = fitted.transform(&labels).unwrap();
assert_eq!(encoded[0], 0); // "cat" → 0
assert_eq!(encoded[1], 1); // "dog" → 1Implementations§
Source§impl LabelEncoder
impl LabelEncoder
Trait Implementations§
Source§impl Clone for LabelEncoder
impl Clone for LabelEncoder
Source§fn clone(&self) -> LabelEncoder
fn clone(&self) -> LabelEncoder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LabelEncoder
impl Debug for LabelEncoder
Source§impl Default for LabelEncoder
impl Default for LabelEncoder
Source§fn default() -> LabelEncoder
fn default() -> LabelEncoder
Source§impl Fit<ArrayBase<OwnedRepr<String>, Dim<[usize; 1]>>, ()> for LabelEncoder
impl Fit<ArrayBase<OwnedRepr<String>, Dim<[usize; 1]>>, ()> for LabelEncoder
Source§fn fit(
&self,
x: &Array1<String>,
_y: &(),
) -> Result<FittedLabelEncoder, FerroError>
fn fit( &self, x: &Array1<String>, _y: &(), ) -> Result<FittedLabelEncoder, FerroError>
Fit the encoder by learning the sorted set of unique labels.
Labels are sorted alphabetically; the first label maps to 0.
§Errors
Returns FerroError::InsufficientSamples if the input is empty.
Source§type Fitted = FittedLabelEncoder
type Fitted = FittedLabelEncoder
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl FitTransform<ArrayBase<OwnedRepr<String>, Dim<[usize; 1]>>> for LabelEncoder
impl FitTransform<ArrayBase<OwnedRepr<String>, Dim<[usize; 1]>>> for LabelEncoder
Source§fn fit_transform(&self, x: &Array1<String>) -> Result<Array1<usize>, FerroError>
fn fit_transform(&self, x: &Array1<String>) -> Result<Array1<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
Source§impl Transform<ArrayBase<OwnedRepr<String>, Dim<[usize; 1]>>> for LabelEncoder
Implement Transform on the unfitted encoder to satisfy the FitTransform: Transform
supertrait bound. Calling transform on an unfitted encoder always returns an error.
impl Transform<ArrayBase<OwnedRepr<String>, Dim<[usize; 1]>>> for LabelEncoder
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: &Array1<String>) -> Result<Array1<usize>, FerroError>
fn transform(&self, _x: &Array1<String>) -> Result<Array1<usize>, FerroError>
Always returns an error — the encoder must be fitted first.
Use Fit::fit to produce a FittedLabelEncoder, then call
Transform::transform on that.
Source§type Error = FerroError
type Error = FerroError
transform.Auto Trait Implementations§
impl Freeze for LabelEncoder
impl RefUnwindSafe for LabelEncoder
impl Send for LabelEncoder
impl Sync for LabelEncoder
impl Unpin for LabelEncoder
impl UnsafeUnpin for LabelEncoder
impl UnwindSafe for LabelEncoder
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