Added a bit of padding to prevent label from overlapping graph title.
Browse files
app.py
CHANGED
|
@@ -15,12 +15,13 @@ def initial_points(X, y_true, n_components, n_clust):
|
|
| 15 |
centers_init, indices = kmeans_plusplus(X, n_clusters=n_clust, random_state=0)
|
| 16 |
|
| 17 |
# Plot init seeds along side sample data
|
| 18 |
-
init_points_plot = plt.
|
| 19 |
|
| 20 |
for k in range(n_components):
|
| 21 |
cluster_data = y_true == k
|
| 22 |
plt.scatter(X[cluster_data, 0], X[cluster_data, 1], marker=".", s=10)
|
| 23 |
|
|
|
|
| 24 |
plt.scatter(centers_init[:, 0], centers_init[:, 1], c="b", s=50)
|
| 25 |
plt.title("K-Means++ Initialization")
|
| 26 |
plt.xticks([])
|
|
@@ -31,11 +32,12 @@ def one_step(X, n_clust):
|
|
| 31 |
kmeans = KMeans(n_clusters=n_clust, max_iter=1, n_init=1, random_state=0).fit(X)
|
| 32 |
y_hat = kmeans.predict(X)
|
| 33 |
|
| 34 |
-
one_step = plt.
|
| 35 |
plt.scatter(X[:, 0], X[:, 1], marker=".", s=10, c=y_hat)
|
| 36 |
centers = kmeans.cluster_centers_
|
| 37 |
plt.scatter(centers[:, 0], centers[:, 1], c="b", s=50)
|
| 38 |
|
|
|
|
| 39 |
plt.title("K-Means After One Step")
|
| 40 |
plt.xticks([])
|
| 41 |
plt.yticks([])
|
|
|
|
| 15 |
centers_init, indices = kmeans_plusplus(X, n_clusters=n_clust, random_state=0)
|
| 16 |
|
| 17 |
# Plot init seeds along side sample data
|
| 18 |
+
init_points_plot, ax = plt.subplots()
|
| 19 |
|
| 20 |
for k in range(n_components):
|
| 21 |
cluster_data = y_true == k
|
| 22 |
plt.scatter(X[cluster_data, 0], X[cluster_data, 1], marker=".", s=10)
|
| 23 |
|
| 24 |
+
plt.subplots_adjust(top=0.8)
|
| 25 |
plt.scatter(centers_init[:, 0], centers_init[:, 1], c="b", s=50)
|
| 26 |
plt.title("K-Means++ Initialization")
|
| 27 |
plt.xticks([])
|
|
|
|
| 32 |
kmeans = KMeans(n_clusters=n_clust, max_iter=1, n_init=1, random_state=0).fit(X)
|
| 33 |
y_hat = kmeans.predict(X)
|
| 34 |
|
| 35 |
+
one_step, ax = plt.subplots()
|
| 36 |
plt.scatter(X[:, 0], X[:, 1], marker=".", s=10, c=y_hat)
|
| 37 |
centers = kmeans.cluster_centers_
|
| 38 |
plt.scatter(centers[:, 0], centers[:, 1], c="b", s=50)
|
| 39 |
|
| 40 |
+
plt.subplots_adjust(top=0.8)
|
| 41 |
plt.title("K-Means After One Step")
|
| 42 |
plt.xticks([])
|
| 43 |
plt.yticks([])
|