()
| 12 | from util import getKaggleMNIST |
| 13 | |
| 14 | def main(): |
| 15 | Xtrain, Ytrain, Xtest, Ytest = getKaggleMNIST() |
| 16 | |
| 17 | pca = PCA() |
| 18 | reduced = pca.fit_transform(Xtrain) |
| 19 | plt.scatter(reduced[:,0], reduced[:,1], s=100, c=Ytrain, alpha=0.5) |
| 20 | plt.show() |
| 21 | |
| 22 | plt.plot(pca.explained_variance_ratio_) |
| 23 | plt.show() |
| 24 | |
| 25 | # cumulative variance |
| 26 | # choose k = number of dimensions that gives us 95-99% variance |
| 27 | cumulative = [] |
| 28 | last = 0 |
| 29 | for v in pca.explained_variance_ratio_: |
| 30 | cumulative.append(last + v) |
| 31 | last = cumulative[-1] |
| 32 | plt.plot(cumulative) |
| 33 | plt.show() |
| 34 | |
| 35 | if __name__ == '__main__': |
| 36 | main() |
no test coverage detected