Language: English
Last updated: 2026-07-12
This page: Model documentation
Switch: Chinese
Language switch: Chinese
Ridge provides L2-regularized linear regression with the same inference surface as LinearRegression (including robust covariance options). It is used when multicollinearity or shrinkage is required while keeping interpretable coefficient inference in aligned settings.
statgpu.linear_model.Ridge
For unweighted observations, statgpu minimizes the average-loss objective
With sample_weight=w, the data-fit term is normalized by the total weight:
The intercept is not penalized. Multiplying every sample weight by the same positive constant therefore leaves the fitted model unchanged.
After centering the data using the corresponding ordinary or weighted means, the first-order condition is
where
Ridge defaults to solver="exact". The same objective scale is used by the exact and FISTA paths, by PenalizedLinearRegression(loss="squared_error", penalty="l2"), and by RidgeCV.
scikit-learn uses an unnormalized residual sum of squares. For coefficient comparisons, use
- unweighted:
sklearn_alpha = n_samples * statgpu_alpha; - weighted:
sklearn_alpha = sample_weight.sum() * statgpu_alpha.
Comparing the two libraries with the same numerical alpha compares different objectives.
cov_type="nonrobust": classical ridge covariance.cov_type="hc0"|"hc1"|"hc2"|"hc3": sandwich-style robust covariance variants.cov_type="hac": Newey-West (Bartlett) covariance with optionalhac_maxlags.compute_inference=Truereturns_bse,_tvalues,_pvalues,_conf_int.- Weighted inference uses the weighted design
[sqrt(w), sqrt(w) * X], so the intercept column, residuals, bread, and meat follow the same weighting convention as estimation.
| Parameter | Default | Description |
|---|---|---|
alpha |
1.0 |
L2 regularization strength on the average-loss scale |
fit_intercept |
True |
Whether to fit an intercept |
device |
"auto" |
cpu / cuda / torch / auto |
n_jobs |
None |
Number of parallel jobs |
compute_inference |
True |
Whether to compute inference stats (SE/t/p/CI) |
cov_type |
"nonrobust" |
nonrobust / hc0 / hc1 / hc2 / hc3 / hac |
hac_maxlags |
None |
Max lag for cov_type="hac"; default follows a Newey-West-style heuristic |
gpu_memory_cleanup |
False |
Best-effort GPU memory cleanup after each fit |
solver |
"exact" |
Exact L2 solution by default; fista uses the same objective |
from statgpu.linear_model import Ridge
# CPU
m_cpu = Ridge(alpha=1.0, device="cpu", cov_type="hc3", compute_inference=True)
m_cpu.fit(X, y, sample_weight=w)
# CuPy CUDA
m_gpu = Ridge(
alpha=1.0,
device="cuda",
cov_type="hc3",
compute_inference=True,
gpu_memory_cleanup=True,
)
m_gpu.fit(X, y, sample_weight=w)No separate public approximate mode is exposed. CPU tests cover the exact/FISTA, weighted/unweighted, formula, inference, and RidgeCV contracts. Physical CuPy/Torch CUDA numerical and performance validation remains part of the remote validation gate.
- Coefficients:
intercept_,coef_ - Inference:
_bse,_tvalues,_pvalues,_conf_int - Diagnostics:
rsquared,rsquared_adj,fvalue,aic,bic - Methods:
fit,predict,score,summary
- How should
alphabe chosen? UseRidgeCVor a task-specific log grid on statgpu's average-loss scale. - Why does the same
alphadiffer from sklearn? The residual term has a different normalization; apply the mapping above. - Does rescaling all sample weights change the model? No. The weighted loss is divided by
sum(sample_weight). - When should I set
hac_maxlags? When usingcov_type="hac"with time dependence; otherwise leave the default.
- Internal consistency is tested against the average-loss closed form and the generic penalized-linear estimator.
- sklearn comparisons use the explicit unweighted or weighted alpha mapping.
- Weighted exact/FISTA, formula-row alignment, inference, and RidgeCV weight-rescaling invariance are covered in
dev/tests/test_ridge_weighted_consistency.py.
- Hoerl, A. E., & Kennard, R. W. (1970). Ridge regression: Biased estimation for nonorthogonal problems. Technometrics, 12(1), 55-67. https://doi.org/10.1080/00401706.1970.10488634
- Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed.). Springer.