()
| 131 | |
| 132 | |
| 133 | def 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 | |
| 157 | if __name__ == "__main__": |
no test coverage detected