pub struct LabelEncoder {
pub classes: Vec<String>,
}Expand description
1-D label ↔ usize encoder with a lexicographically-sorted vocabulary.
§Complexity
fit:O(n · log n)time (sort + dedup),O(k)space wherekis the number of distinct classes.transform:O(n · log k)time via binary search.
Fields§
§classes: Vec<String>Sorted, deduplicated class values as strings.
Storing labels as owned Strings keeps the encoder generic and
Serialize-friendly without pulling in a hashable-trait bound.
Implementations§
Source§impl LabelEncoder
impl LabelEncoder
Sourcepub fn fit<I, T>(labels: I) -> Selfwhere
I: IntoIterator<Item = T>,
T: ToString,
pub fn fit<I, T>(labels: I) -> Selfwhere
I: IntoIterator<Item = T>,
T: ToString,
Fit onto an iterable of labels (each rendered with to_string).
Sourcepub fn transform<I, T>(&self, labels: I) -> Result<Array1<usize>>where
I: IntoIterator<Item = T>,
T: ToString,
pub fn transform<I, T>(&self, labels: I) -> Result<Array1<usize>>where
I: IntoIterator<Item = T>,
T: ToString,
Transform each label to its class index. Errors on an unseen label.
Sourcepub fn inverse_transform(
&self,
encoded: ArrayView1<'_, usize>,
) -> Result<Vec<String>>
pub fn inverse_transform( &self, encoded: ArrayView1<'_, usize>, ) -> Result<Vec<String>>
Inverse-map class indices back to labels.
Sourcepub fn fit_transform<I, T>(labels: I) -> (Self, Array1<usize>)
pub fn fit_transform<I, T>(labels: I) -> (Self, Array1<usize>)
One-call fit + transform.
Trait Implementations§
Source§impl Clone for LabelEncoder
impl Clone for LabelEncoder
Source§impl Debug for LabelEncoder
impl Debug for LabelEncoder
Source§impl<'de> Deserialize<'de> for LabelEncoder
impl<'de> Deserialize<'de> for LabelEncoder
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 LabelEncoder
impl PartialEq for LabelEncoder
Source§impl Serialize for LabelEncoder
impl Serialize for LabelEncoder
impl StructuralPartialEq for LabelEncoder
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
Mutably borrows from an owned value. Read more