diff --git a/sklearn/linear_model/coordinate_descent.py b/sklearn/linear_model/coordinate_descent.py index 2a38eb65831f6..b9257026551f9 100644 --- a/sklearn/linear_model/coordinate_descent.py +++ b/sklearn/linear_model/coordinate_descent.py @@ -1150,7 +1150,7 @@ def fit(self, X, y): cv = check_cv(self.cv) # Compute path for all folds and compute MSE to get the best alpha - folds = list(cv.split(X)) + folds = list(cv.split(X, y)) best_mse = np.inf # We do a double for loop folded in one, in order to be able to diff --git a/sklearn/linear_model/tests/test_coordinate_descent.py b/sklearn/linear_model/tests/test_coordinate_descent.py index 13f3a999d8434..8c3ff10bcfd2e 100644 --- a/sklearn/linear_model/tests/test_coordinate_descent.py +++ b/sklearn/linear_model/tests/test_coordinate_descent.py @@ -175,6 +175,24 @@ def test_lasso_cv(): assert_greater(clf.score(X_test, y_test), 0.99) +def test_lasso_cv_with_some_model_selection(): + from sklearn.pipeline import make_pipeline + from sklearn.preprocessing import StandardScaler + from sklearn.model_selection import StratifiedKFold + from sklearn import datasets + from sklearn.linear_model import LassoCV + + diabetes = datasets.load_diabetes() + X = diabetes.data + y = diabetes.target + + pipe = make_pipeline( + StandardScaler(), + LassoCV(cv=StratifiedKFold(n_splits=5)) + ) + pipe.fit(X, y) + + def test_lasso_cv_positive_constraint(): X, y, X_test, y_test = build_dataset() max_iter = 500