pub struct BinaryEncoder<F> { /* private fields */ }Expand description
An unfitted binary encoder.
Takes a matrix of categorical integer features and encodes each category
as a sequence of binary digits. For k categories, each feature produces
ceil(log2(k)) output columns.
§Examples
use ferrolearn_preprocess::binary_encoder::BinaryEncoder;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let enc = BinaryEncoder::<f64>::new();
let x = array![[0usize], [1], [2], [3]];
let fitted = enc.fit(&x, &()).unwrap();
let out = fitted.transform(&x).unwrap();
// 4 categories → ceil(log2(4)) = 2 binary columns
assert_eq!(out.ncols(), 2);Implementations§
Trait Implementations§
Source§impl<F: Clone> Clone for BinaryEncoder<F>
impl<F: Clone> Clone for BinaryEncoder<F>
Source§fn clone(&self) -> BinaryEncoder<F>
fn clone(&self) -> BinaryEncoder<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 BinaryEncoder<F>
impl<F: Debug> Debug for BinaryEncoder<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>, ()> for BinaryEncoder<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>, ()> for BinaryEncoder<F>
Source§fn fit(
&self,
x: &Array2<usize>,
_y: &(),
) -> Result<FittedBinaryEncoder<F>, FerroError>
fn fit( &self, x: &Array2<usize>, _y: &(), ) -> Result<FittedBinaryEncoder<F>, FerroError>
Fit by determining the number of 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 = FittedBinaryEncoder<F>
type Fitted = FittedBinaryEncoder<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<usize>, Dim<[usize; 2]>>> for BinaryEncoder<F>
impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>> for BinaryEncoder<F>
Source§fn fit_transform(&self, x: &Array2<usize>) -> Result<Array2<F>, FerroError>
fn fit_transform(&self, x: &Array2<usize>) -> Result<Array2<F>, FerroError>
Source§type FitError = FerroError
type FitError = FerroError
The error type for the combined fit-transform operation.
Auto Trait Implementations§
impl<F> Freeze for BinaryEncoder<F>
impl<F> RefUnwindSafe for BinaryEncoder<F>where
F: RefUnwindSafe,
impl<F> Send for BinaryEncoder<F>where
F: Send,
impl<F> Sync for BinaryEncoder<F>where
F: Sync,
impl<F> Unpin for BinaryEncoder<F>where
F: Unpin,
impl<F> UnsafeUnpin for BinaryEncoder<F>
impl<F> UnwindSafe for BinaryEncoder<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.