pub struct StandardScaler {
pub mean: Array1<f64>,
pub scale: Array1<f64>,
/* private fields */
}Expand description
Zero-mean unit-variance scaler.
Fits per-column mean μⱼ and standard deviation σⱼ, then
transforms each row via x ← (x - μ) / σ. On the inverse
transform, x ← x · σ + μ.
§Complexity
fit:O(n · d)time,O(d)space.transform/inverse_transform:O(n · d)time.
§Reference
Chan, T. F., Golub, G. H., & LeVeque, R. J. (1983). Algorithms for computing the sample variance: analysis and recommendations. The American Statistician, 37(3), 242-247.
Fields§
§mean: Array1<f64>Per-column mean.
scale: Array1<f64>Per-column standard deviation (with n - 1 denominator by default;
1.0 for zero-variance columns to keep the transform well-defined).
Implementations§
Source§impl StandardScaler
impl StandardScaler
Sourcepub fn fit(x: ArrayView2<'_, f64>) -> Result<Self>
pub fn fit(x: ArrayView2<'_, f64>) -> Result<Self>
Fit the scaler on x (rows = samples, cols = features).
Sourcepub fn fit_with(
x: ArrayView2<'_, f64>,
with_mean: bool,
with_std: bool,
biased: bool,
) -> Result<Self>
pub fn fit_with( x: ArrayView2<'_, f64>, with_mean: bool, with_std: bool, biased: bool, ) -> Result<Self>
Full-configuration fit.
with_mean— subtract the mean on transform.with_std— divide by the std on transform.biased— use the population variance (ndenominator) rather than the sample variance (n - 1).
Sourcepub fn population(self) -> Self
pub fn population(self) -> Self
Switch to the biased (population) variance.
Sourcepub fn fit_transform(x: ArrayView2<'_, f64>) -> Result<(Self, Array2<f64>)>
pub fn fit_transform(x: ArrayView2<'_, f64>) -> Result<(Self, Array2<f64>)>
Fit + transform in one call — returns a freshly-allocated matrix.
Sourcepub fn transform(&self, x: ArrayView2<'_, f64>) -> Result<Array2<f64>>
pub fn transform(&self, x: ArrayView2<'_, f64>) -> Result<Array2<f64>>
Apply the scaler to x. Returns a new matrix.
Sourcepub fn inverse_transform(&self, x: ArrayView2<'_, f64>) -> Result<Array2<f64>>
pub fn inverse_transform(&self, x: ArrayView2<'_, f64>) -> Result<Array2<f64>>
Invert the transform: x ← x · σ + μ.