Skip to content

Commit 546c42d

Browse files
Timsauradrinjalali
authored andcommitted
DOC improving plot_digits_pipe.py by adjusting parameters and making the graph more clear (scikit-learn#14346)
* changed hyperparameter n_iter from 20 to 10 * hyperparameter tuning * REV Revert * improved graph * Review comments
1 parent 02d60c7 commit 546c42d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

examples/compose/plot_digits_pipe.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
# Parameters of pipelines can be set using ‘__’ separated parameter names:
4444
param_grid = {
45-
'pca__n_components': [5, 20, 30, 40, 50, 64],
46-
'logistic__C': np.logspace(-4, 4, 5),
45+
'pca__n_components': [5, 15, 30, 45, 64],
46+
'logistic__C': np.logspace(-4, 4, 4),
4747
}
4848
search = GridSearchCV(pipe, param_grid, n_jobs=-1)
4949
search.fit(X_digits, y_digits)
@@ -54,8 +54,9 @@
5454
pca.fit(X_digits)
5555

5656
fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True, figsize=(6, 6))
57-
ax0.plot(pca.explained_variance_ratio_, linewidth=2)
58-
ax0.set_ylabel('PCA explained variance')
57+
ax0.plot(np.arange(1, pca.n_components_ + 1),
58+
pca.explained_variance_ratio_, '+', linewidth=2)
59+
ax0.set_ylabel('PCA explained variance ratio')
5960

6061
ax0.axvline(search.best_estimator_.named_steps['pca'].n_components,
6162
linestyle=':', label='n_components chosen')
@@ -72,5 +73,7 @@
7273
ax1.set_ylabel('Classification accuracy (val)')
7374
ax1.set_xlabel('n_components')
7475

76+
plt.xlim(-1, 70)
77+
7578
plt.tight_layout()
7679
plt.show()

0 commit comments

Comments
 (0)