pub struct OneHotEncoder {
pub encoders: Vec<LabelEncoder>,
pub drop_first: bool,
}Expand description
One-hot / dummy-variable encoder for categorical numeric input.
For a n × d matrix, produces a n × Σⱼ kⱼ (or n × Σⱼ (kⱼ - 1)
with drop_first) dense indicator matrix. Column ordering is
deterministic — for column j with sorted categories
[c0, c1, …, ck-1], the encoded block appears in that order.
Fields§
§encoders: Vec<LabelEncoder>One LabelEncoder per input column, in column order.
drop_first: boolWhether to drop the first category of every column (dummy-variable
convention, avoids the classical X'X rank-deficiency of a full
dummy set in a design matrix with an intercept).
Implementations§
Source§impl OneHotEncoder
impl OneHotEncoder
Sourcepub fn fit(x: ArrayView2<'_, f64>) -> Result<Self>
pub fn fit(x: ArrayView2<'_, f64>) -> Result<Self>
Fit — no drop by default.
Sourcepub fn fit_with(x: ArrayView2<'_, f64>, drop_first: bool) -> Result<Self>
pub fn fit_with(x: ArrayView2<'_, f64>, drop_first: bool) -> Result<Self>
Fit with explicit drop_first flag.
Sourcepub fn n_output_columns(&self) -> usize
pub fn n_output_columns(&self) -> usize
Compute the total number of output columns.
Sourcepub fn fit_transform(x: ArrayView2<'_, f64>) -> Result<(Self, Array2<f64>)>
pub fn fit_transform(x: ArrayView2<'_, f64>) -> Result<(Self, Array2<f64>)>
One-call fit + transform.
Trait Implementations§
Source§impl Clone for OneHotEncoder
impl Clone for OneHotEncoder
Source§impl Debug for OneHotEncoder
impl Debug 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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for OneHotEncoder
impl PartialEq for OneHotEncoder
Source§impl Serialize for OneHotEncoder
impl Serialize for OneHotEncoder
impl StructuralPartialEq 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
Mutably borrows from an owned value. Read more