Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Online ml River Preprocessing PredClipper

From Leeroopedia


Knowledge Sources
Domains Online_Learning, Preprocessing, Regression
Last Updated 2026-02-08 16:00 GMT

Overview

Wrapper for regression models that clips predictions to a specified range.

Description

PredClipper constrains regression model predictions to lie within specified minimum and maximum bounds. It wraps any regression model and applies clamping to the predicted values after inference, ensuring they remain within valid ranges. The underlying model trains normally without constraints, but all predictions are clipped to [y_min, y_max] before being returned. This is particularly useful when domain knowledge dictates hard limits on possible output values.

Usage

Use this when your regression target has known physical or logical bounds (e.g., percentages between 0-100, prices above zero, ratings within 1-5). Prevents models from making nonsensical predictions outside valid ranges. Common applications include predicting probabilities, counts, or any domain-constrained continuous variables. Wraps any regressor without modifying its learning behavior.

Code Reference

Source Location

Signature

class PredClipper(base.Wrapper, base.Regressor):
    def __init__(self, regressor: base.Regressor, y_min: float, y_max: float)

Import

from river import preprocessing

I/O Contract

Input Output
Dict[str, float] - Features float - Clipped prediction

Usage Examples

from river import linear_model
from river import preprocessing

dataset = (
    ({'a': 2, 'b': 4}, 80),
    ({'a': 3, 'b': 5}, 100),
    ({'a': 4, 'b': 6}, 120)
)

model = preprocessing.PredClipper(
    regressor=linear_model.LinearRegression(),
    y_min=0,
    y_max=200
)

for x, y in dataset:
    model.learn_one(x, y)

print(model.predict_one({'a': -100, 'b': -200}))
# 0

print(model.predict_one({'a': 50, 'b': 60}))
# 200

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment