pub struct OrdinalEncoder { /* private fields */ }Expand description
Online ordinal encoder for string features.
Categories are discovered incrementally via update_strs
and kept in sorted order. transform_strs maps each
string to its index in the sorted category list.
Implementations§
Source§impl OrdinalEncoder
impl OrdinalEncoder
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>
Encode each string as its category index (as f64).
Output length = features.len() (one value per input string).
§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 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§fn default() -> OrdinalEncoder
fn default() -> OrdinalEncoder
Returns the “default value” for a type. Read more
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