pub struct FeatureNormalizer { /* private fields */ }Expand description
Z-score (standardization) normalizer: (x - mean) / std.
Must be fit on training data before calling transform.
§Example
use fin_primitives::ml_features::FeatureNormalizer;
let mut norm = FeatureNormalizer::new();
norm.fit(&[1.0, 2.0, 3.0, 4.0, 5.0]).unwrap();
let z = norm.transform(3.0).unwrap();
assert!((z - 0.0).abs() < 1e-10);Implementations§
Source§impl FeatureNormalizer
impl FeatureNormalizer
Sourcepub fn fit(&mut self, data: &[f64]) -> Result<(), FinError>
pub fn fit(&mut self, data: &[f64]) -> Result<(), FinError>
Fit the normalizer to a dataset.
§Errors
FinError::InsufficientData if fewer than 2 observations.
FinError::InvalidInput if std dev is zero (constant series).
Sourcepub fn transform(&self, value: f64) -> Result<f64, FinError>
pub fn transform(&self, value: f64) -> Result<f64, FinError>
Transform a single value to z-score.
§Errors
FinError::InvalidInput if the normalizer has not been fit.
Sourcepub fn inverse_transform(&self, z: f64) -> Result<f64, FinError>
pub fn inverse_transform(&self, z: f64) -> Result<f64, FinError>
Inverse transform a z-score back to original scale.
§Errors
FinError::InvalidInput if the normalizer has not been fit.
Sourcepub fn transform_slice(&self, values: &[f64]) -> Result<Vec<f64>, FinError>
pub fn transform_slice(&self, values: &[f64]) -> Result<Vec<f64>, FinError>
Transform a slice of values in place.
§Errors
FinError::InvalidInput if the normalizer has not been fit.
Trait Implementations§
Source§impl Clone for FeatureNormalizer
impl Clone for FeatureNormalizer
Source§impl Debug for FeatureNormalizer
impl Debug for FeatureNormalizer
Auto Trait Implementations§
impl Freeze for FeatureNormalizer
impl RefUnwindSafe for FeatureNormalizer
impl Send for FeatureNormalizer
impl Sync for FeatureNormalizer
impl Unpin for FeatureNormalizer
impl UnsafeUnpin for FeatureNormalizer
impl UnwindSafe for FeatureNormalizer
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