pub struct OneHotEncoder { /* private fields */ }Expand description
Online one-hot encoder for string features.
Categories are discovered incrementally via update_strs.
Before any category is seen, transform_strs returns an empty vector.
Implementations§
Source§impl OneHotEncoder
impl OneHotEncoder
Sourcepub fn categories(&self) -> &[String]
pub fn categories(&self) -> &[String]
The known categories, kept in sorted order.
Sourcepub fn category_index(&self, category: &str) -> Option<usize>
pub fn category_index(&self, category: &str) -> Option<usize>
Find the index of category using binary search.
Sourcepub fn fit_one(&mut self, category: &str)
pub fn fit_one(&mut self, category: &str)
Add a category if not already present, keeping the list sorted.
Sourcepub fn transform_strs(&self, features: &[&str]) -> Result<Vec<f64>, RillError>
pub fn transform_strs(&self, features: &[&str]) -> Result<Vec<f64>, RillError>
One-hot encode each string.
Output length = features.len() * categories.len(). Each group of
categories.len() consecutive values has a 1.0 at the category
index and 0.0 elsewhere.
§Errors
RillError::EmptyFeaturesiffeaturesis empty.RillError::UnknownCategoryif any string is not in the known categories.
Before any category has been seen, returns an empty vector.
Sourcepub fn update_strs(&mut self, features: &[&str]) -> Result<(), RillError>
pub fn update_strs(&mut self, features: &[&str]) -> Result<(), RillError>
Add all new categories from features and increment samples_seen.
§Errors
Returns RillError::EmptyFeatures if features is empty.
Sourcepub fn samples_seen(&self) -> u64
pub fn samples_seen(&self) -> u64
How many samples have been seen.
Trait Implementations§
Source§impl Clone for OneHotEncoder
impl Clone for OneHotEncoder
Source§fn clone(&self) -> OneHotEncoder
fn clone(&self) -> OneHotEncoder
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 OneHotEncoder
impl Debug for OneHotEncoder
Source§impl Default for OneHotEncoder
impl Default for OneHotEncoder
Source§fn default() -> OneHotEncoder
fn default() -> OneHotEncoder
Returns the “default value” for a type. Read more
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