Skip to content

Commit d1f5833

Browse files
qinhanmin2014glemaitre
authored andcommitted
EXA Show the advantage of PCA in plot_digits_pipe.py (scikit-learn#14348)
1 parent 01a140a commit d1f5833

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/compose/plot_digits_pipe.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@
2626

2727
from sklearn import datasets
2828
from sklearn.decomposition import PCA
29-
from sklearn.linear_model import SGDClassifier
29+
from sklearn.linear_model import LogisticRegression
3030
from sklearn.pipeline import Pipeline
3131
from sklearn.model_selection import GridSearchCV
3232

3333

3434
# Define a pipeline to search for the best combination of PCA truncation
3535
# and classifier regularization.
36-
logistic = SGDClassifier(loss='log', penalty='l2', early_stopping=True,
37-
max_iter=10000, tol=1e-5, random_state=0)
3836
pca = PCA()
37+
# set the tolerance to a large value to make the example faster
38+
logistic = LogisticRegression(max_iter=10000, tol=0.1)
3939
pipe = Pipeline(steps=[('pca', pca), ('logistic', logistic)])
4040

4141
X_digits, y_digits = datasets.load_digits(return_X_y=True)
4242

4343
# Parameters of pipelines can be set using ‘__’ separated parameter names:
4444
param_grid = {
4545
'pca__n_components': [5, 20, 30, 40, 50, 64],
46-
'logistic__alpha': np.logspace(-4, 4, 5),
46+
'logistic__C': np.logspace(-4, 4, 5),
4747
}
48-
search = GridSearchCV(pipe, param_grid)
48+
search = GridSearchCV(pipe, param_grid, n_jobs=-1)
4949
search.fit(X_digits, y_digits)
5050
print("Best parameter (CV score=%0.3f):" % search.best_score_)
5151
print(search.best_params_)

0 commit comments

Comments
 (0)