8000 DOC additional fixes to 20 newsgroups to prevent TypeError (#8204) · scikit-learn/scikit-learn@3dc8d2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dc8d2f

Browse files
BasilBeiroutijnothman
authored andcommitted
DOC additional fixes to 20 newsgroups to prevent TypeError (#8204)
* removed stray space in '__main__ ' * fixed pipeline bug causing TypeError and removed incorrect keyword argument pipeline was not created properly (both classes had .predict) causing TypeError to be thrown. Also removed incorrect keyword argument loss=“l2” for LinearSVC
1 parent cbddb92 commit 3dc8d2f

File tree

1 file changed

+6
-5
lines changed

examples/text/document_classification_20newsgroups.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from sklearn.datasets import fetch_20newsgroups
3535
from sklearn.feature_extraction.text import TfidfVectorizer
3636
from sklearn.feature_extraction.text import HashingVectorizer
37+
from sklearn.feature_selection import SelectFromModel
3738
from sklearn.feature_selection import SelectKBest, chi2
3839
from sklearn.linear_model import RidgeClassifier
3940
from sklearn.pipeline import Pipeline
@@ -259,8 +260,8 @@ def benchmark(clf):
259260
print('=' * 80)
260261
print("%s penalty" % penalty.upper())
261262
# Train Liblinear model
262-
results.append(benchmark(LinearSVC(loss='l2', penalty=penalty,
263-
dual=False, tol=1e-3)))
263+
results.append(benchmark(LinearSVC(penalty=penalty, dual=False,
264+
tol=1e-3)))
264265

265266
# Train SGD model
266267
results.append(benchmark(SGDClassifier(alpha=.0001, n_iter=50,
@@ -288,9 +289,9 @@ def benchmark(clf):
288289
# The smaller C, the stronger the regularization.
289290
# The more regularization, the more sparsity.
290291
results.append(benchmark(Pipeline([
291-
('feature_selection', LinearSVC(penalty="l1", dual=False, tol=1e-3)),
292-
('classification', LinearSVC())
293-
])))
292+
('feature_selection', SelectFromModel(LinearSVC(penalty="l1", dual=False,
293+
tol=1e-3))),
294+
('classification', LinearSVC(penalty="l2"))])))
294295

295296
# make some plots
296297

0 commit comments

Comments
 (0)
0