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 QuantileRegressor

From Leeroopedia


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

Overview

Concrete tool for linear regression that predicts conditional quantiles using the pinball loss, robust to outliers, provided by scikit-learn.

Description

QuantileRegressor optimizes the pinball loss for a desired quantile, producing a linear model that predicts conditional quantiles rather than the conditional mean. It uses L1 regularization (similar to Lasso) and solves the optimization via linear programming using scipy's linprog. By default it predicts the median (quantile=0.5), but can predict any quantile between 0 and 1. The model is inherently robust to outliers since the pinball loss grows linearly rather than quadratically for large residuals.

Usage

Use QuantileRegressor when you need to predict specific quantiles of the response distribution (e.g., the 90th percentile for risk assessment), when you need robust regression that is not sensitive to outliers, or when you want to understand the full conditional distribution of the target rather than just its mean. It is commonly used in financial risk modeling, weather forecasting, and any domain requiring prediction intervals.

Code Reference

Source Location

Signature

class QuantileRegressor(LinearModel, RegressorMixin, BaseEstimator):
    def __init__(
        self,
        *,
        quantile=0.5,
        alpha=1.0,
        fit_intercept=True,
        solver="highs",
        solver_options=None,
    ):

Import

from sklearn.linear_model import QuantileRegressor

I/O Contract

Inputs

Name Type Required Description
quantile float No Target quantile to predict, strictly between 0 and 1 (default=0.5)
alpha float No L1 regularization constant (default=1.0)
fit_intercept bool No Whether to fit the intercept (default=True)
solver str No Linear programming solver: 'highs-ds', 'highs-ipm', 'highs', 'interior-point', 'revised simplex' (default='highs')
solver_options dict No Additional parameters passed to scipy.optimize.linprog (default=None)

Outputs

Name Type Description
coef_ ndarray of shape (n_features,) Estimated coefficients for the features
intercept_ float The intercept of the model (bias term)
n_features_in_ int Number of features seen during fit
feature_names_in_ ndarray of shape (n_features_in_,) Names of features seen during fit

Usage Examples

Basic Usage

from sklearn.linear_model import QuantileRegressor
from sklearn.datasets import make_regression

X, y = make_regression(n_samples=200, n_features=5, noise=20, random_state=42)

# Predict the median
model_median = QuantileRegressor(quantile=0.5, alpha=0.0)
model_median.fit(X, y)

# Predict the 90th percentile
model_upper = QuantileRegressor(quantile=0.9, alpha=0.0)
model_upper.fit(X, y)

print("Median prediction:", model_median.predict(X[:3]))
print("90th percentile prediction:", model_upper.predict(X[:3]))

Related Pages

Page Connections

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