Skip to Content
OchreML
Linear, GLM & Linear SVM

QuantileRegressor

L1-regularized linear regression predicting conditional quantiles by minimizing pinball loss.

Overview

QuantileRegressor estimates a conditional quantile (quantile in (0, 1)) of the target distribution by minimizing the sample-weighted pinball (check) loss plus an L1 penalty:

min (1 / n_samples) * sum(pinball_loss_q(y_i, x_i @ w + b)) + alpha * ||w||_1

It is solved via Iteratively Reweighted Least Squares (IRLS) paired with warm-started Coordinate Descent. Setting quantile=0.5 yields Least Absolute Deviations (median regression); fitting multiple models (e.g., quantile=0.1 and quantile=0.9) produces distribution-free prediction intervals.

When to Use

  • Predicting conditional medians (quantile=0.5) when target errors are skewed or heavy-tailed.
  • Constructing prediction intervals (such as 10th, 50th, and 90th percentiles) for risk, demand forecasting, or SLA modeling.
  • Performing quantile regression with automatic L1 feature shrinkage.

Hardware Backend Support

BackendPrimitives UsedSupport
CPU (Rayon)Dense E1-E5 (f64)Full (default fallback)
CUDA (cuda:0, cuda:all)cuBLAS FP64 Gram & projections (E1-E5)Full
wgpu (wgpu)WGSL compute shaders (E1-E5)Full
TPU (tpu:0)OpenXLA PJRT (E1-E5)Full

Import & Constructor

from ochreml.glm import QuantileRegressor
# also available via:
from ochreml.linear_model import QuantileRegressor
from ochreml import QuantileRegressor

model = QuantileRegressor(
    quantile: float = 0.5,
    alpha: float = 1.0,
    fit_intercept: bool = True,
    max_iter: int = 1000,
    tol: float = 1e-6,
    device: str | None = None,
)

Parameters

ParameterTypeDefaultDescription
quantilefloat0.5Target conditional quantile to estimate. Must be strictly in (0.0, 1.0).
alphafloat1.0Regularization constant multiplying the L1 penalty ||coef_||_1.
fit_interceptboolTrueWhether to estimate an unpenalized intercept term.
max_iterint1000Maximum number of IRLS iterations.
tolfloat1e-6Convergence tolerance for the stopping criterion.
devicestr | NoneNoneTarget compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
coef_ndarray of shape (n_features,)Estimated feature weights.
intercept_floatFitted bias term.
n_iter_intNumber of IRLS iterations performed.
n_features_in_intNumber of features seen during fit.
device_strResolved hardware device string used by the estimator.

Methods

MethodSignatureDescription
fitfit(X, y, sample_weight=None) -> selfFit quantile regression model on (X, y).
predictpredict(X) -> ndarrayPredict the conditional quantile for input matrix X.
scorescore(X, y, sample_weight=None) -> floatReturn weighted coefficient of determination R^2.
toto(device: str) -> selfMove the estimator execution target to another hardware device.
save / loadmodel.save(path) / QuantileRegressor.load(path, device=None)Persist or restore the model in OchreML's binary .dit format.

Usage Example

import numpy as np
import ochreml
from ochreml.glm import QuantileRegressor

rng = np.random.default_rng(15)
X = rng.uniform(0.0, 10.0, size=(300, 2))
y = 2.0 * X[:, 0] - 0.5 * X[:, 1] + rng.exponential(scale=1.5, size=300)

q50 = QuantileRegressor(quantile=0.5, alpha=0.01, device="auto").fit(X, y)
q90 = QuantileRegressor(quantile=0.9, alpha=0.01, device="auto").fit(X, y)

preds_50 = q50.predict(X[:5])
preds_90 = q90.predict(X[:5])
print(f"Median R^2: {q50.score(X, y):.4f}, 90th >= 50th: {bool(np.all(preds_90 >= preds_50))}")

# Persist to .dit and reload
q50.save("quantile_p50.dit")
loaded = ochreml.load("quantile_p50.dit", device="cpu")
assert np.allclose(preds_50, loaded.predict(X[:5]))

On this page