Implementation:Online ml River Preprocessing TargetScalers
| Knowledge Sources | |
|---|---|
| Domains | Online_Learning, Preprocessing, Regression |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Target scaling transformations for regression models using standard scaling or min-max normalization.
Description
This module provides two methods for scaling regression targets before training and inverse-transforming predictions. TargetStandardScaler applies z-score normalization (zero mean, unit variance) to targets using running statistics. TargetMinMaxScaler scales targets to a 0-1 range using running minimum and maximum values. Both wrappers automatically transform targets during learning and inverse-transform predictions, making the scaling transparent to the underlying regressor.
Usage
Use target scaling when your regression targets have large magnitudes or high variance, which can slow convergence or cause numerical issues. TargetStandardScaler is preferred for normally distributed targets, while TargetMinMaxScaler works well for bounded targets. Both improve optimization stability and can speed up convergence for gradient-based models. Always use with regression models that benefit from normalized targets.
Code Reference
Source Location
- Repository: Online_ml_River
- File: river/preprocessing/scale_target.py
Signature
class TargetStandardScaler(compose.TargetTransformRegressor):
def __init__(self, regressor: base.Regressor)
class TargetMinMaxScaler(compose.TargetTransformRegressor):
def __init__(self, regressor: base.Regressor)
Import
from river import preprocessing
I/O Contract
| Input | Output |
|---|---|
| Dict[str, float] - Features and float target | float - Prediction in original scale |
Usage Examples
from river import datasets
from river import evaluate
from river import linear_model
from river import metrics
from river import preprocessing
# TargetStandardScaler
dataset = datasets.TrumpApproval()
model = (
preprocessing.StandardScaler() |
preprocessing.TargetStandardScaler(
regressor=linear_model.LinearRegression(intercept_lr=0.15)
)
)
metric = metrics.MSE()
evaluate.progressive_val_score(dataset, model, metric)
# MSE: 2.005999
# TargetMinMaxScaler
dataset = datasets.TrumpApproval()
model = (
preprocessing.StandardScaler() |
preprocessing.TargetMinMaxScaler(
regressor=linear_model.LinearRegression(intercept_lr=0.15)
)
)
metric = metrics.MSE()
evaluate.progressive_val_score(dataset, model, metric)
# MSE: 2.018905