|
42 | 42 |
|
43 | 43 | # Parameters of pipelines can be set using ‘__’ separated parameter names: |
44 | 44 | 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), |
47 | 47 | } |
48 | 48 | search = GridSearchCV(pipe, param_grid, n_jobs=-1) |
49 | 49 | search.fit(X_digits, y_digits) |
|
54 | 54 | pca.fit(X_digits) |
55 | 55 |
|
56 | 56 | 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') |
59 | 60 |
|
60 | 61 | ax0.axvline(search.best_estimator_.named_steps['pca'].n_components, |
61 | 62 | linestyle=':', label='n_components chosen') |
|
72 | 73 | ax1.set_ylabel('Classification accuracy (val)') |
73 | 74 | ax1.set_xlabel('n_components') |
74 | 75 |
|
| 76 | +plt.xlim(-1, 70) |
| 77 | + |
75 | 78 | plt.tight_layout() |
76 | 79 | plt.show() |
0 commit comments