Scalers & Normalizers
Hardware-accelerated feature scaling and sample normalization in ochreml.preprocessing (StandardScaler, MinMaxScaler, MaxAbsScaler, RobustScaler, Normalizer).
OchreML provides five Rust-backed scaling and normalization transformers in ochreml.preprocessing (also lazily importable from ochreml), alongside stateless functional helpers. All five classes use zero-copy buffer ingestion, support .save() / .load() binary .dit persistence, and expose .to(device) for hardware target switching (cpu, cuda:0, wgpu, tpu:0, auto). (^▽^)
Overview
| Class | Transformation | partial_fit | inverse_transform | .dit Tag |
|---|---|---|---|---|
StandardScaler | Zero-mean, unit-variance standardization | Yes | Yes | 7 |
MinMaxScaler | Linear scaling to a target (min, max) range | Yes | Yes | 8 |
MaxAbsScaler | Division by per-feature maximum absolute value | Yes | Yes | 9 |
RobustScaler | Median centering and interquartile range (IQR) scaling | No | Yes | 10 |
Normalizer | Row-wise normalization to unit l1, l2, or max norm | No | No | 11 |
Every scaler also exposes n_features_in_, device_, get_feature_names_out(input_features=None), save(path), load(path, device=None), and to(device).
StandardScaler
Standardizes each feature by subtracting the mean and dividing by the standard deviation: z = (x - mean) / scale. Supports weighted fitting via sample_weight and streaming updates via partial_fit.
from ochreml.preprocessing import StandardScaler
scaler = StandardScaler(
copy=True,
with_mean=True,
with_std=True,
device=None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
copy | bool | True | Kept for scikit-learn parity; OchreML always returns a new array. |
with_mean | bool | True | If True, center each feature by subtracting its mean. |
with_std | bool | True | If True, scale each feature to unit variance. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to get_default_device(). |
Methods & Fitted Attributes
- Methods:
fit(X, y=None, sample_weight=None),partial_fit(X, y=None, sample_weight=None),transform(X),fit_transform(X, y=None, sample_weight=None),inverse_transform(X),get_feature_names_out(input_features=None) - Attributes:
mean_,var_,scale_,n_samples_seen_,n_features_in_,device_
import numpy as np
from ochreml.preprocessing import StandardScaler
X = np.array([[1.0, 100.0], [2.0, 200.0], [3.0, 300.0]])
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
X_orig = scaler.inverse_transform(X_scaled)MinMaxScaler
Scales each feature independently to a specified feature_range = (min, max) using X_std = (X - data_min) / (data_max - data_min) and X_scaled = X_std * (max - min) + min.
from ochreml.preprocessing import MinMaxScaler
scaler = MinMaxScaler(
feature_range=(0.0, 1.0),
copy=True,
clip=False,
device=None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
feature_range | tuple[float, float] | (0.0, 1.0) | Desired (min, max) bounds of the transformed features. |
copy | bool | True | Kept for scikit-learn parity; returns a new array. |
clip | bool | False | If True, clips transformed held-out values to feature_range. |
device | str | None | None | Target compute device. |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),partial_fit(X, y=None),transform(X),fit_transform(X, y=None),inverse_transform(X),get_feature_names_out(input_features=None) - Attributes:
min_,scale_,data_min_,data_max_,data_range_,n_samples_seen_,n_features_in_,device_
MaxAbsScaler
Divides each feature by its maximum absolute value so transformed values lie in [-1.0, 1.0] without shifting zeros.
from ochreml.preprocessing import MaxAbsScaler
scaler = MaxAbsScaler(copy=True, device=None)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
copy | bool | True | Kept for scikit-learn parity; returns a new array. |
device | str | None | None | Target compute device. |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),partial_fit(X, y=None),transform(X),fit_transform(X, y=None),inverse_transform(X),get_feature_names_out(input_features=None) - Attributes:
max_abs_,scale_,n_samples_seen_,n_features_in_,device_
RobustScaler
Centers and scales features using outlier-resistant quantiles (median and IQR by default). All constructor parameters are keyword-only.
from ochreml.preprocessing import RobustScaler
scaler = RobustScaler(
with_centering=True,
with_scaling=True,
quantile_range=(25.0, 75.0),
copy=True,
unit_variance=False,
device=None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
with_centering | bool | True | If True, subtract the median before scaling. |
with_scaling | bool | True | If True, divide by the quantile range. |
quantile_range | tuple[float, float] | (25.0, 75.0) | Lower and upper percentiles (q_min, q_max) used to compute scale_. |
copy | bool | True | Kept for scikit-learn parity; returns a new array. |
unit_variance | bool | False | If True, rescale so normally distributed features have variance 1.0. |
device | str | None | None | Target compute device. |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),transform(X),fit_transform(X, y=None),inverse_transform(X),get_feature_names_out(input_features=None) - Attributes:
center_,scale_,n_features_in_,device_
Normalizer
Normalizes each non-zero sample (row) independently to unit norm. Unlike feature-wise scalers, Normalizer is stateless with respect to sample statistics (fit only validates input dimensions and records n_features_in_).
from ochreml.preprocessing import Normalizer
norm = Normalizer(norm="l2", copy=True, device=None)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
norm | {"l1", "l2", "max"} | "l2" | Vector norm used to normalize each non-zero row. |
copy | bool | True | Keyword-only; kept for scikit-learn parity. |
device | str | None | None | Keyword-only; target compute device. |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),transform(X, copy=None),fit_transform(X, y=None),get_feature_names_out(input_features=None) - Attributes:
n_features_in_,device_
Stateless Functional Helpers
ochreml.preprocessing also exports stateless functions for one-off scaling along either axis=0 (features) or axis=1 (samples):
from ochreml.preprocessing import (
scale,
minmax_scale,
maxabs_scale,
robust_scale,
normalize,
)
X_z = scale(X, axis=0, with_mean=True, with_std=True, copy=True, device=None)
X_mm = minmax_scale(X, feature_range=(0.0, 1.0), axis=0, copy=True, device=None)
X_ma = maxabs_scale(X, axis=0, copy=True, device=None)
X_rb = robust_scale(X, axis=0, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), unit_variance=False, copy=True, device=None)
X_l2, norms = normalize(X, norm="l2", axis=1, copy=True, return_norm=True, device=None)GaussianProcessClassifier
Bayesian Gaussian Process classification using Laplace approximation for binary tasks and One-vs-Rest for multiclass tasks.
Categorical & Target Encoders
Rust-accelerated categorical feature and target label encoders in ochreml.preprocessing (OneHotEncoder, OrdinalEncoder, TargetEncoder, LabelEncoder, LabelBinarizer, MultiLabelBinarizer).