10000 additional fixes to 20 newsgroups to prevent TypeError by BasilBeirouti · Pull Request #8204 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

additional fixes to 20 newsgroups to prevent TypeError #8204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
10000
Diff view
13 changes: 7 additions & 6 deletions examples/text/document_classification_20newsgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.feature_extraction.text import HashingVectorizer
from sklearn.feature_selection import SelectFromModel
from sklearn.feature_selection import SelectKBest, chi2
from sklearn.linear_model import RidgeClassifier
from sklearn.pipeline import Pipeline
Expand Down Expand Up @@ -85,7 +86,7 @@


def is_interactive():
return not hasattr(sys.modules['__main__ '], '__file__')
return not hasattr(sys.modules['__main__'], '__file__')

# work-around for Jupyter notebook and IPython console
argv = [] if is_interactive() else sys.argv[1:]
Expand Down Expand Up @@ -259,8 +260,8 @@ def benchmark(clf):
print('=' * 80)
print("%s penalty" % penalty.upper())
# Train Liblinear model
results.append(benchmark(LinearSVC(loss='l2', penalty=penalty,
dual=False, tol=1e-3)))
results.append(benchmark(LinearSVC(penalty=penalty, dual=False,
tol=1e-3)))

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

# make some plots

Expand Down
0