RidgeCV doesn't allow `alpha=0`
See original GitHub issueDescribe the bug
RidgeCV doesn’t allow any alphas to be 0, despite the underlying Ridge
linear model allowing such behavior.
Steps/Code to Reproduce
from sklearn.datasets import load_diabetes
from sklearn.linear_model import RidgeCV
X, y = load_diabetes(return_X_y=True)
clf = RidgeCV(alphas=[0, 1e-2, 1e-1, 1]).fit(X, y)
Expected Results
No error thrown
Actual Results
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18064/1693855650.py in <module>
2 from sklearn.linear_model import RidgeCV
3 X, y = load_diabetes(return_X_y=True)
----> 4 clf = RidgeCV(alphas=[0, 1e-2, 1e-1, 1]).fit(X, y)
5 clf.score(X, y)
r:\work\scikit-learn\sklearn\linear_model\_ridge.py in fit(self, X, y, sample_weight)
2147 if n_alphas != 1:
2148 for index, alpha in enumerate(self.alphas):
-> 2149 alpha = check_scalar_alpha(alpha, f"alphas[{index}]")
2150 else:
2151 self.alphas[0] = check_scalar_alpha(self.alphas[0], "alphas")
r:\work\scikit-learn\sklearn\utils\validation.py in check_scalar(x, name, target_type, min_val, max_val, include_boundaries)
1466 )
1467 if min_val is not None and comparison_operator(x, min_val):
-> 1468 raise ValueError(
1469 f"{name} == {x}, must be"
1470 f" {'>=' if include_boundaries in ('left', 'both') else '>'} {min_val}."
ValueError: alphas[0] == 0, must be > 0.0.
Versions
System:
python: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
executable: R:\ProgramFiles\anaconda3\envs\scikit-dev\python.exe
machine: Windows-10-10.0.19043-SP0
Python dependencies:
sklearn: 1.1.dev0
pip: 21.2.4
setuptools: 58.0.4
numpy: 1.21.5
scipy: 1.7.3
Cython: 0.29.26
pandas: 1.3.5
matplotlib: 3.5.1
joblib: 1.1.0
threadpoolctl: 3.0.0
Built with OpenMP: True
threadpoolctl info:
user_api: blas
internal_api: openblas
prefix: libopenblas
filepath: R:\ProgramFiles\anaconda3\envs\scikit-dev\Lib\site-packages\numpy\.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll
version: 0.3.17
threading_layer: pthreads
architecture: Zen
num_threads: 12
user_api: openmp
internal_api: openmp
prefix: vcomp
filepath: C:\Windows\System32\vcomp140.dll
version: None
num_threads: 12
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Scikit learn: RidgeCV seems not to give the best option?
Your manual approach is not doing any cross-validation and therefore train- and testdata are the same! # alpha = 0.1 model = Ridge(alpha...
Read more >The results of CV on Ridge are different than ... - Cross Validated
RidgeCV () you allow α such as [0.1,1,10]. Further, defining cv=None , cross_val_predict() implies 3-fold-crossvalidation as you can read in ...
Read more >Lab 10 - Ridge Regression and the Lasso in Python
Okay, so fitting a ridge regression model with alpha = 4 leads to a much lower test MSE than fitting a model with...
Read more >sklearn.linear_model.RidgeCV
Alpha corresponds to 1 / (2C) in other linear models such as LogisticRegression or LinearSVC . If using Leave-One-Out cross-validation, alphas must be...
Read more >RidgeCV Regression in Python - Machine Learning HD
Let us now GridsearchCV and see how it would work. #define parameters param = { 'alpha':[.0001, 0.001,0.01, 0.01,1], 'fit_intercept':[True, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would prefer to avoid introducing some hard coded tiny
EPS > 0
. As a user, if I specifyalpha=0
, I expect that to hold exactly. Therefore, improving documentation (and error message?) seems best to me.Indeed I think it would be best to expand the User Guide entry for RidgeCV and link to the User Guide in the actual docstring. I can work on that in a new PR.