pub struct StandardScaler {
pub means: Vec<f32>,
pub stds: Vec<f32>,
/* private fields */
}Expand description
StandardScaler: (x - μ) / σ
Transforms features to have zero mean and unit variance.
§Why it helps GBDTs
Even though trees are scale-invariant, scaling improves:
- Regularization fairness: L1/L2 penalties applied uniformly
- Binning uniformity: Quantiles distributed evenly
- Numerical stability: Gradient/Hessian calculations
- Mixed ensembles: Combining linear + tree models
§Example
use treeboost::preprocessing::{StandardScaler, Scaler};
let mut train = vec![1.0, 10.0, 2.0, 20.0, 3.0, 30.0]; // 3 rows × 2 features
let mut test = vec![1.5, 15.0, 2.5, 25.0]; // 2 rows × 2 features
let mut scaler = StandardScaler::new();
scaler.fit(&train, 2)?;
scaler.transform(&mut train, 2)?;
scaler.transform(&mut test, 2)?; // Use same mean/std from trainingFields§
§means: Vec<f32>Mean of each feature (learned during fit)
stds: Vec<f32>Standard deviation of each feature (learned during fit)
Implementations§
Source§impl StandardScaler
impl StandardScaler
Sourcepub fn with_forget_factor(forget_factor: f32) -> Self
pub fn with_forget_factor(forget_factor: f32) -> Self
Create a StandardScaler with EMA-based rolling window updates
§Arguments
forget_factor- Alpha value between 0.0 and 1.0 (clamped if out of range)
§Example
ⓘ
// Create scaler with alpha=0.1 (10% blend from each new batch)
let mut scaler = StandardScaler::with_forget_factor(0.1);
scaler.partial_fit(&batch1, num_features)?; // 100% batch1
scaler.partial_fit(&batch2, num_features)?; // 90% batch1, 10% batch2
scaler.partial_fit(&batch3, num_features)?; // 81% batch1, 9% batch2, 10% batch3Sourcepub fn set_forget_factor(&mut self, factor: Option<f32>)
pub fn set_forget_factor(&mut self, factor: Option<f32>)
Set the forget factor for EMA-based updates
§Arguments
factor- Value between 0.0 and 1.0, or None to disable EMA mode
Sourcepub fn forget_factor(&self) -> Option<f32>
pub fn forget_factor(&self) -> Option<f32>
Get the current forget factor
Trait Implementations§
Source§impl Clone for StandardScaler
impl Clone for StandardScaler
Source§fn clone(&self) -> StandardScaler
fn clone(&self) -> StandardScaler
Returns a duplicate of the value. Read more
1.0.0 · 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 StandardScaler
impl Debug for StandardScaler
Source§impl Default for StandardScaler
impl Default for StandardScaler
Source§impl<'de> Deserialize<'de> for StandardScaler
impl<'de> Deserialize<'de> for StandardScaler
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 From<StandardScaler> for Preprocessor
impl From<StandardScaler> for Preprocessor
Source§fn from(scaler: StandardScaler) -> Self
fn from(scaler: StandardScaler) -> Self
Converts to this type from the input type.
Source§impl IncrementalScaler for StandardScaler
impl IncrementalScaler for StandardScaler
Source§impl Scaler for StandardScaler
impl Scaler for StandardScaler
Auto Trait Implementations§
impl Freeze for StandardScaler
impl RefUnwindSafe for StandardScaler
impl Send for StandardScaler
impl Sync for StandardScaler
impl Unpin for StandardScaler
impl UnwindSafe for StandardScaler
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.