()
| 122 | |
| 123 | |
| 124 | def main(): |
| 125 | Xtrain, Ytrain, Xtest, Ytest = getKaggleMNIST() |
| 126 | dbn = DBN([1000, 750, 500], UnsupervisedModel=AutoEncoder) |
| 127 | # dbn = DBN([1000, 750, 500, 10]) |
| 128 | output = dbn.fit(Xtrain, pretrain_epochs=2) |
| 129 | print("output.shape", output.shape) |
| 130 | |
| 131 | # sample before using t-SNE because it requires lots of RAM |
| 132 | sample_size = 600 |
| 133 | tsne = TSNE() |
| 134 | reduced = tsne.fit_transform(output[:sample_size]) |
| 135 | plt.scatter(reduced[:,0], reduced[:,1], s=100, c=Ytrain[:sample_size], alpha=0.5) |
| 136 | plt.title("t-SNE visualization on data transformed by DBN") |
| 137 | plt.show() |
| 138 | |
| 139 | # t-SNE on raw data |
| 140 | reduced = tsne.fit_transform(Xtrain[:sample_size]) |
| 141 | plt.scatter(reduced[:,0], reduced[:,1], s=100, c=Ytrain[:sample_size], alpha=0.5) |
| 142 | plt.title("t-SNE visualization on raw data") |
| 143 | plt.show() |
| 144 | |
| 145 | pca = PCA() |
| 146 | reduced = pca.fit_transform(output) |
| 147 | plt.scatter(reduced[:,0], reduced[:,1], s=100, c=Ytrain, alpha=0.5) |
| 148 | plt.title("PCA visualization on data transformed by DBN") |
| 149 | plt.show() |
| 150 | |
| 151 | if __name__ == '__main__': |
| 152 | main() |
no test coverage detected