Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 133aaf0

Browse files
larsmansGaelVaroquaux
authored andcommitted
BUG make GridSearchCV work with non-CSR sparse matrix
1 parent f7241ac commit 133aaf0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

sklearn/grid_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def fit_grid_point(X, y, base_clf, clf_params, train, test, loss_func,
7979
for k, v in clf_params.iteritems()))
8080
print "[GridSearchCV] %s %s" % (msg, (64 - len(msg)) * '.')
8181

82-
X, y = check_arrays(X, y)
82+
X, y = check_arrays(X, y, sparse_format="csr")
8383
# update parameters of the classifier after a copy of its base structure
8484
clf = clone(base_clf)
8585
clf.set_params(**clf_params)

sklearn/tests/test_grid_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_grid_search_sparse():
113113
X_ = sp.csr_matrix(X_)
114114
clf = LinearSVC()
115115
cv = GridSearchCV(clf, {'C': [0.1, 1.0]})
116-
cv.fit(X_[:180], y_[:180])
116+
cv.fit(X_[:180].tocoo(), y_[:180])
117117
y_pred2 = cv.predict(X_[180:])
118118
C2 = cv.best_estimator_.C
119119

0 commit comments

Comments
 (0)