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:Scikit learn Scikit learn IsotonicRegression

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Regression
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for isotonic regression (monotonic fitting) provided by scikit-learn.

Description

IsotonicRegression fits a non-decreasing (or non-increasing) piecewise linear function to data. It finds the monotonic function that best fits the data in terms of mean squared error, making it useful for calibrating model outputs or fitting data where a monotonic relationship is expected. The module also provides the utility functions check_increasing for testing whether y is monotonically correlated with x, and the low-level isotonic_regression function for direct monotonic fitting.

Usage

Use IsotonicRegression when you need to fit a monotonic curve to data, such as probability calibration of classifier outputs, dose-response modeling, or any regression problem where the target is known to increase (or decrease) monotonically with the feature. It works as both a regressor and a transformer.

Code Reference

Source Location

Signature

class IsotonicRegression(RegressorMixin, TransformerMixin, BaseEstimator):
    def __init__(self, *, y_min=None, y_max=None, increasing=True, out_of_bounds="nan"):

Import

from sklearn.isotonic import IsotonicRegression

I/O Contract

Inputs

Name Type Required Description
y_min float or None No Lower bound on the lowest predicted value (default=None)
y_max float or None No Upper bound on the highest predicted value (default=None)
increasing bool or str No Whether the isotonic constraint is increasing; True, False, or 'auto' (default=True)
out_of_bounds str No How to handle out-of-bounds points: 'nan', 'clip', 'raise' (default='nan')

Outputs

Name Type Description
X_min_ float Minimum value of input features seen during fit
X_max_ float Maximum value of input features seen during fit
X_thresholds_ ndarray of shape (n_thresholds,) Unique input thresholds used for the piecewise linear fit
y_thresholds_ ndarray of shape (n_thresholds,) Predicted values at the thresholds
f_ function Interpolation function for prediction
increasing_ bool Whether the isotonic regression is increasing
n_features_in_ int Number of features seen during fit

Usage Examples

Basic Usage

from sklearn.isotonic import IsotonicRegression
import numpy as np

# Generate noisy monotonic data
rng = np.random.RandomState(42)
x = np.arange(50)
y = x + rng.normal(0, 3, size=50)

# Fit isotonic regression
ir = IsotonicRegression(increasing=True)
y_pred = ir.fit_transform(x, y)

print(f"Input range: [{ir.X_min_:.1f}, {ir.X_max_:.1f}]")
print(f"Predictions are monotonic: {all(y_pred[i] <= y_pred[i+1] for i in range(len(y_pred)-1))}")

Related Pages

Page Connections

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