10000 DOC: faster and more meaningful example · pfdevilliers/scikit-learn@b93105e · GitHub
[go: up one dir, main page]

Skip to content

Commit b93105e

Browse files
committed
DOC: faster and more meaningful example
1 parent e6ecf57 commit b93105e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

examples/plot_digits_pipe.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
"""
55
=========================================================
6-
Pipelining
6+
Pipelining: chaining a PCA and a logistic regression
77
=========================================================
88
9-
This plot is generated by pipelining a PCA and a logisitic regression.
9+
The PCA does an unsupervised dimensionality reduction, while the logistic
10+
regression does the prediction.
11+
12+
We use a GridSearchCV to set the dimensionality of the PCA
1013
1114
"""
1215
print __doc__
@@ -50,18 +53,17 @@
5053

5154
from sklearn.grid_search import GridSearchCV
5255

53-
n_components = [10, 15, 20, 30, 40, 50, 64]
54-
Cs = np.logspace(-4, 4, 16)
56+
n_components = [20, 40, 64]
57+
Cs = np.logspace(-4, 4, 3)
5558

5659
#Parameters of pipelines can be set using ‘__’ separated parameter names:
5760

5861
estimator = GridSearchCV(pipe,
5962
dict(pca__n_components=n_components,
60-
logistic__C=Cs),
61-
n_jobs=-1)
63+
logistic__C=Cs))
6264
estimator.fit(X_digits, y_digits)
6365

64-
# Plot the PCA spectrum
65-
pca.fit(X_digits)
66-
66+
pl.axvline(estimator.best_estimator_.named_steps['pca'].n_components,
67+
linestyle=':', label='n_components chosen')
68+
pl.legend(prop=dict(size=12))
6769
pl.show()

0 commit comments

Comments
 (0)
0