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

Function main

unsupervised_class2/tsne_mnist.py:21–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19
20
21def main():
22 Xtrain, Ytrain, _, _ = getKaggleMNIST()
23
24 sample_size = 1000
25 X = Xtrain[:sample_size]
26 Y = Ytrain[:sample_size]
27
28 tsne = TSNE()
29 Z = tsne.fit_transform(X)
30 plt.scatter(Z[:,0], Z[:,1], s=100, c=Y, alpha=0.5)
31 plt.show()
32
33 # purity measure from unsupervised machine learning pt 1
34 # maximum purity is 1, higher is better
35 gmm = GaussianMixture(n_components=10)
36 gmm.fit(X)
37 Rfull = gmm.predict_proba(X)
38 print("Rfull.shape:", Rfull.shape)
39 print("full purity:", purity(Y, Rfull))
40
41 # now try the same thing on the reduced data
42 gmm.fit(Z)
43 Rreduced = gmm.predict_proba(Z)
44 print("reduced purity:", purity(Y, Rreduced))
45
46if __name__ == '__main__':
47 main()

Callers 1

tsne_mnist.pyFile · 0.70

Calls 5

getKaggleMNISTFunction · 0.90
purityFunction · 0.90
fit_transformMethod · 0.45
fitMethod · 0.45
predict_probaMethod · 0.45

Tested by

no test coverage detected