Skip to content

Commit 9a3910d

Browse files
larsmansGaelVaroquaux
authored andcommitted
BUG allow array-like y in RFE
+ cosmit: use np.ravel to flatten np.matrix
1 parent 02e6fd0 commit 9a3910d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

sklearn/feature_selection/rfe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def fit(self, X, y):
149149
ranks = np.argsort(safe_sqr(estimator.coef_))
150150

151151
# for sparse case ranks is matrix
152-
ranks = np.asarray(ranks).ravel()
152+
ranks = np.ravel(ranks)
153153

154154
# Eliminate the worse features
155155
threshold = min(step, np.sum(support_) - n_features_to_select)
@@ -327,6 +327,7 @@ def fit(self, X, y):
327327
Target values (integers for classification, real numbers for
328328
regression).
329329
"""
330+
X, y = check_arrays(X, y, sparse_format="csr")
330331
# Initialization
331332
rfe = RFE(estimator=self.estimator, n_features_to_select=1,
332333
step=self.step, estimator_params=self.estimator_params,

sklearn/feature_selection/tests/test_rfe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_rfecv():
6464

6565
iris = load_iris()
6666
X = np.c_[iris.data, generator.normal(size=(len(iris.data), 6))]
67-
y = iris.target
67+
y = list(iris.target) # regression test: list should be supported
6868

6969
# Test using the score function
7070
rfecv = RFECV(estimator=SVC(kernel="linear"), step=1, cv=3)

0 commit comments

Comments
 (0)