|
45 | 45 | pca.fit(X_scaled, y) |
46 | 46 | T_pca = pca.transform(X_scaled) |
47 | 47 |
|
48 | | -fig, axis = plt.subplots() |
49 | | -scatter = axis.scatter(T_pca[:, 0], T_pca[:, 1], c=y) |
50 | | -axis.set(xlabel="PC$_1$", ylabel="PC$_2$") |
51 | | -axis.legend( |
| 48 | +fig, ax = plt.subplots() |
| 49 | +scatter = ax.scatter(T_pca[:, 0], T_pca[:, 1], c=y) |
| 50 | +ax.set(xlabel="PC$_1$", ylabel="PC$_2$") |
| 51 | +ax.legend( |
52 | 52 | scatter.legend_elements()[0][::-1], |
53 | 53 | load_breast_cancer().target_names[::-1], |
54 | 54 | loc="upper right", |
|
66 | 66 |
|
67 | 67 | T_lda = lda.transform(X_scaled) |
68 | 68 |
|
69 | | -fig, axis = plt.subplots() |
70 | | -axis.scatter(-T_lda[:], np.zeros(len(T_lda[:])), c=y) |
71 | | -axis.set(xlabel="LD$_1$", ylabel="LD$_2$") |
| 69 | +fig, ax = plt.subplots() |
| 70 | +ax.scatter(T_lda[:], np.zeros(len(T_lda[:])), c=y) |
| 71 | +ax.set(xlabel="LDA$_1$", ylabel="LDA$_2$") |
72 | 72 |
|
73 | 73 | # %% |
74 | 74 | # |
|
91 | 91 |
|
92 | 92 | T_pcovc = pcovc.transform(X_scaled) |
93 | 93 |
|
94 | | -fig, axis = plt.subplots() |
95 | | -axis.scatter(T_pcovc[:, 0], T_pcovc[:, 1], c=y) |
96 | | -axis.set(xlabel="PCov$_1$", ylabel="PCov$_2$") |
| 94 | +fig, ax = plt.subplots() |
| 95 | +ax.scatter(T_pcovc[:, 0], T_pcovc[:, 1], c=y) |
| 96 | +ax.set(xlabel="PCov$_1$", ylabel="PCov$_2$") |
97 | 97 |
|
98 | 98 | # %% |
99 | 99 | # |
100 | 100 | # A side-by-side comparison of the |
101 | | -# three techniques (PCA, LDA, and PCovC): |
102 | | - |
103 | | -n_models = 3 |
104 | | - |
105 | | -fig, axes = plt.subplots(1, n_models, figsize=(6 * n_models, 5)) |
106 | | -axes[0].scatter(T_pca[:, 0], T_pca[:, 1], c=y) |
107 | | -axes[0].set_title("PCA") |
108 | | -axes[1].scatter(-T_lda[:], np.zeros(len(T_lda[:])), c=y) |
109 | | -axes[1].set_title("LDA") |
110 | | -axes[2].scatter(T_pcovc[:, 0], T_pcovc[:, 1], c=y) |
111 | | -axes[2].set_title("PCovC") |
| 101 | +# three maps (PCA, LDA, and PCovC): |
| 102 | + |
| 103 | +fig, axs = plt.subplots(1, 3, figsize=(18, 5)) |
| 104 | +axs[0].scatter(T_pca[:, 0], T_pca[:, 1], c=y) |
| 105 | +axs[0].set_title("PCA") |
| 106 | +axs[1].scatter(T_lda, np.zeros(len(T_lda)), c=y) |
| 107 | +axs[1].set_title("LDA") |
| 108 | +axs[2].scatter(T_pcovc[:, 0], T_pcovc[:, 1], c=y) |
| 109 | +axs[2].set_title("PCovC") |
| 110 | +plt.show() |
0 commit comments