pub struct OneHotEncoder { /* private fields */ }Expand description
Encode categorical features as one-hot numeric columns, mirroring
sklearn.preprocessing.OneHotEncoder. Categories per column are
sorted lexicographically (sklearn default).
Input is a 2-D StrMatrix; output is a dense Matrix by default.
Use sparse_output and
transform_sparse for CSR output.
Implementations§
Source§impl OneHotEncoder
impl OneHotEncoder
Sourcepub fn drop(self, d: DropStrategy) -> Self
pub fn drop(self, d: DropStrategy) -> Self
Sets the category drop strategy.
Sourcepub fn handle_unknown(self, h: HandleUnknown) -> Self
pub fn handle_unknown(self, h: HandleUnknown) -> Self
Sets how unknown categories are handled during transform.
Sourcepub fn sparse_output(self, sparse: bool) -> Self
pub fn sparse_output(self, sparse: bool) -> Self
Enable or disable sparse (CSR) output. When true, use
transform_sparse to obtain a
SparseMatrix. Default is false (dense).
Sourcepub fn categories(&self) -> &[Vec<String>]
pub fn categories(&self) -> &[Vec<String>]
Returns the learned categories per column.
Sourcepub fn n_output_cols(&self) -> usize
pub fn n_output_cols(&self) -> usize
Returns the number of output columns after transform.
Sourcepub fn transform(&self, x: &StrMatrix) -> Result<Matrix>
pub fn transform(&self, x: &StrMatrix) -> Result<Matrix>
Encodes the input as a dense one-hot matrix.
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 into a dense matrix.
Sourcepub fn transform_sparse(&self, x: &StrMatrix) -> Result<SparseMatrix>
pub fn transform_sparse(&self, x: &StrMatrix) -> Result<SparseMatrix>
Transform using sparse (CSR) output, regardless of the sparse_output
flag. Useful when only some callers need sparse data.
Sourcepub fn fit_transform_sparse(&mut self, x: &StrMatrix) -> Result<SparseMatrix>
pub fn fit_transform_sparse(&mut self, x: &StrMatrix) -> Result<SparseMatrix>
Convenience: fit then transform into sparse output.
Sourcepub fn inverse_transform(&self, x: &Matrix) -> Result<StrMatrix>
pub fn inverse_transform(&self, x: &Matrix) -> Result<StrMatrix>
Convert one-hot encoded dense data back to categorical strings.
For each row, the active (1.0) column within each feature block is
decoded to its category. When drop = First, an all-zero block
decodes to the dropped (first) category. All-zero blocks with
drop = None decode to an empty string (matching sklearn’s None).
Sourcepub fn inverse_transform_sparse(&self, x: &SparseMatrix) -> Result<StrMatrix>
pub fn inverse_transform_sparse(&self, x: &SparseMatrix) -> Result<StrMatrix>
Inverse transform from sparse (CSR) input.
Sourcepub fn transform_auto(&self, x: &StrMatrix) -> Result<OneHotOutput>
pub fn transform_auto(&self, x: &StrMatrix) -> Result<OneHotOutput>
Transform returning sparse if sparse_output is set, dense otherwise.
Trait Implementations§
Source§impl CategoricalTransformer for OneHotEncoder
impl CategoricalTransformer for OneHotEncoder
Source§fn fit(&mut self, x: &StrMatrix) -> Result<()>
fn fit(&mut self, x: &StrMatrix) -> Result<()>
Source§fn transform(&self, x: &StrMatrix) -> Result<Matrix>
fn transform(&self, x: &StrMatrix) -> Result<Matrix>
Matrix.Source§impl Clone for OneHotEncoder
impl Clone for OneHotEncoder
Source§fn clone(&self) -> OneHotEncoder
fn clone(&self) -> OneHotEncoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OneHotEncoder
impl Debug for OneHotEncoder
Source§impl Default for OneHotEncoder
impl Default for OneHotEncoder
Source§impl<'de> Deserialize<'de> for OneHotEncoder
impl<'de> Deserialize<'de> for OneHotEncoder
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>,
impl Estimator for OneHotEncoder
Source§impl FeatureNames for OneHotEncoder
impl FeatureNames for OneHotEncoder
Auto Trait Implementations§
impl Freeze for OneHotEncoder
impl RefUnwindSafe for OneHotEncoder
impl Send for OneHotEncoder
impl Sync for OneHotEncoder
impl Unpin for OneHotEncoder
impl UnsafeUnpin for OneHotEncoder
impl UnwindSafe for OneHotEncoder
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,
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>
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