MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / main

Function main

unsupervised_class2/pca.py:14–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12from util import getKaggleMNIST
13
14def 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
35if __name__ == '__main__':
36 main()

Callers 1

pca.pyFile · 0.70

Calls 2

getKaggleMNISTFunction · 0.90
fit_transformMethod · 0.45

Tested by

no test coverage detected