ice-skaters

skaters on a river: calibrated forecast features for streaming ML pipelines.

What it does

In streaming machine learning a model predicts, learns and moves on, one row at a time. The usual pre-processing in river is a running z-score: subtract a running mean, divide by a running deviation. That fixes scale only. A bad reading still reaches the model at full size, and it corrupts the running mean and deviation used on every reading after it.

ice-skaters gives each numeric stream its own online forecaster (from skaters) and passes the model two numbers in place of the raw value: the predictive mean, and the standardized surprise z. z is bounded by construction — it cannot exceed 7 — so no single observation moves the pair far.

Two ways to feed a stream to a model
A running scaler passes the bad tick through at full size and its mean and variance absorb it. The forecaster lane passes the predictive mean and a bounded z instead.

Install

pip install ice-skaters

Quickstart

from river import datasets, linear_model, metrics, preprocessing
from ice_skaters import LaplaceFeatures, LaplaceTarget

model = LaplaceTarget(
    regressor=preprocessing.TargetStandardScaler(
        regressor=LaplaceFeatures()
        | preprocessing.StandardScaler()
        | linear_model.LinearRegression()))

mae = metrics.MAE()
for x, y in datasets.TrumpApproval():
    pred = model.predict_one(x)
    mae.update(y, pred if pred is not None else 0.0)
    model.learn_one(x, y)

LaplaceFeatures is a river transformer for the input streams. LaplaceTarget wraps any regressor to add the target's own pair, which a transformer cannot do since it never sees y. Both pipe, pickle and deep-copy like any river estimator. Details in the guide.

What you get

On TrumpApproval with river's recommended pipeline, progressive validation MAE with a burn-in of 100:

clean2% corrupted readings
StandardScaler pipeline0.3280.597
+ Laplace front-end0.3690.382

The front-end costs a little on clean data and loses less under corruption. In simulation the same substitution beats raw features, a running z-score, a median/MAD winsorizer and a Huberised loss on 30 seeds out of 30, under every contamination type tested. Protocols, numbers, and the cases where the front-end loses are on the papers page.

Relation to the stack

skaters is fast univariate distributional forecasting, stdlib-only, in Python or the browser. timemachines builds anomaly detection on the same surprise streams. ice-skaters connects those streams to river's estimator protocol.