MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / main

Function main

unsupervised_class/kmeans_mnist.py:133–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131
132
133def main():
134 # mnist data
135 X, Y = get_data(10000)
136
137 # simple data
138 # X = get_simple_data()
139 # Y = np.array([0]*300 + [1]*300 + [2]*300)
140
141 print("Number of data points:", len(Y))
142 M, R = plot_k_means(X, len(set(Y)))
143 # Exercise: Try different values of K and compare the evaluation metrics
144 print("Purity:", purity(Y, R))
145 print("Purity 2 (hard clusters):", purity2(Y, R))
146 print("DBI:", DBI(X, M, R))
147 print("DBI 2 (hard clusters):", DBI2(X, R))
148
149 # plot the mean images
150 # they should look like digits
151 for k in range(len(M)):
152 im = M[k].reshape(28, 28)
153 plt.imshow(im, cmap='gray')
154 plt.show()
155
156
157if __name__ == "__main__":

Callers 1

kmeans_mnist.pyFile · 0.70

Calls 6

purity2Function · 0.85
DBIFunction · 0.85
DBI2Function · 0.85
get_dataFunction · 0.70
plot_k_meansFunction · 0.70
purityFunction · 0.70

Tested by

no test coverage detected