-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Ridge and Lasso return different shaped .coef_ attributes #19693
Copy link
Copy link
Closed
Description
Describe the bug
Ridge.coef_ returns an array with shape (1, n_features), while Lasso.coef_ returns an array with shape (n_features,). LinearRegression.coef_ resembles Ridge.coef_
Steps/Code to Reproduce
import numpy as np
from sklearn.linear_model import Ridge, Lasso
x = np.array([1,2,3,4,5]).reshape(-1,1)
y = np.array([2,4,6,8,10]).reshape(-1,1)
ridge_reg = Ridge()
lasso_reg = Lasso()
_ = ridge_reg.fit(x,y)
_ = lasso_reg.fit(x,y)
print(ridge_reg.coef_.shape)
print(lasso_reg.coef_.shape)Expected Results
(1, 1)
(1, 1)Actual Results
(1, 1)
(1,)Versions
System:
python: 3.7.6 (default, Feb 14 2020, 16:17:39) [Clang 11.0.0 (clang-1100.0.33.17)]
executable: ./venv-mmm/bin/python
machine: Darwin-19.6.0-x86_64-i386-64bit
Python dependencies:
pip: 21.0.1
setuptools: 41.2.0
sklearn: 0.23.2
numpy: 1.19.1
scipy: 1.5.2
Cython: None
pandas: 1.1.1
matplotlib: 3.3.1
joblib: 0.16.0
threadpoolctl: 2.1.0
Built with OpenMP: True
Reactions are currently unavailable