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||_1It 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
| Backend | Primitives Used | Support |
|---|---|---|
| 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
| Parameter | Type | Default | Description |
|---|---|---|---|
quantile | float | 0.5 | Target conditional quantile to estimate. Must be strictly in (0.0, 1.0). |
alpha | float | 1.0 | Regularization constant multiplying the L1 penalty ||coef_||_1. |
fit_intercept | bool | True | Whether to estimate an unpenalized intercept term. |
max_iter | int | 1000 | Maximum number of IRLS iterations. |
tol | float | 1e-6 | Convergence tolerance for the stopping criterion. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
coef_ | ndarray of shape (n_features,) | Estimated feature weights. |
intercept_ | float | Fitted bias term. |
n_iter_ | int | Number of IRLS iterations performed. |
n_features_in_ | int | Number of features seen during fit. |
device_ | str | Resolved hardware device string used by the estimator. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y, sample_weight=None) -> self | Fit quantile regression model on (X, y). |
predict | predict(X) -> ndarray | Predict the conditional quantile for input matrix X. |
score | score(X, y, sample_weight=None) -> float | Return weighted coefficient of determination R^2. |
to | to(device: str) -> self | Move the estimator execution target to another hardware device. |
save / load | model.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]))