pub struct OrdinalEncoder { /* private fields */ }Expand description
Encode categorical features as ordinal integers (0, 1, 2, …), mirroring
sklearn.preprocessing.OrdinalEncoder.
Input is a 2-D StrMatrix; output is a numeric Matrix of the same
shape, where each cell is replaced by the ordinal index of its category.
Categories per column are sorted lexicographically by default (sklearn
default), or can be user-specified via OrdinalCategories::Manual.
Implementations§
Source§impl OrdinalEncoder
impl OrdinalEncoder
Sourcepub fn new(categories: OrdinalCategories) -> Self
pub fn new(categories: OrdinalCategories) -> Self
Creates a new ordinal encoder with the given category config.
Sourcepub fn handle_unknown(self, h: OrdinalHandleUnknown) -> Self
pub fn handle_unknown(self, h: OrdinalHandleUnknown) -> Self
Sets how unknown categories are handled during transform.
Sourcepub fn categories(&self) -> &[Vec<String>]
pub fn categories(&self) -> &[Vec<String>]
Returns the learned categories per column.
Sourcepub fn fit(&mut self, x: &StrMatrix) -> Result<()>
pub fn fit(&mut self, x: &StrMatrix) -> Result<()>
Learns the category-to-index mapping per column.
Sourcepub fn transform(&self, x: &StrMatrix) -> Result<Matrix>
pub fn transform(&self, x: &StrMatrix) -> Result<Matrix>
Encodes the input as ordinal integer codes.
Sourcepub fn fit_transform(&mut self, x: &StrMatrix) -> Result<Matrix>
pub fn fit_transform(&mut self, x: &StrMatrix) -> Result<Matrix>
Fits the encoder and transforms the input in one step.
Sourcepub fn inverse_transform(&self, y: &Matrix) -> Result<StrMatrix>
pub fn inverse_transform(&self, y: &Matrix) -> Result<StrMatrix>
Decodes ordinal integer codes back to category strings.
Trait Implementations§
Source§impl CategoricalTransformer for OrdinalEncoder
impl CategoricalTransformer for OrdinalEncoder
Source§fn fit(&mut self, x: &StrMatrix) -> Result<()>
fn fit(&mut self, x: &StrMatrix) -> Result<()>
Fit the transformer on categorical training data.
Source§fn transform(&self, x: &StrMatrix) -> Result<Matrix>
fn transform(&self, x: &StrMatrix) -> Result<Matrix>
Transform categorical data using fitted parameters, returning a numeric
Matrix.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 (const: unstable) · 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§impl<'de> Deserialize<'de> for OrdinalEncoder
impl<'de> Deserialize<'de> for OrdinalEncoder
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Estimator for OrdinalEncoder
Source§impl FeatureNames for OrdinalEncoder
impl FeatureNames for OrdinalEncoder
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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 more