(plot=False)
| 5 | |
| 6 | |
| 7 | def kmeans_example(plot=False): |
| 8 | X, y = make_blobs( |
| 9 | centers=4, n_samples=500, n_features=2, shuffle=True, random_state=42 |
| 10 | ) |
| 11 | clusters = len(np.unique(y)) |
| 12 | k = KMeans(K=clusters, max_iters=150, init="++") |
| 13 | k.fit(X) |
| 14 | k.predict() |
| 15 | |
| 16 | if plot: |
| 17 | k.plot() |
| 18 | |
| 19 | |
| 20 | if __name__ == "__main__": |