I have unlabeled dataset. I am running k-means flat cluster with 2 number of clusters. Every time I run the below program the labels are different. How can I make labels not to change. Is it even possible?
X = np.array([[1, 2],
[5, 8],
[1.5, 1.8],
[8, 8],
[1, 0.6],
[9, 11]])
kmeans=KMeans(n_clusters=2)
kmeans.fit(X)
centeroids=kmeans.cluster_centers_
labels=kmeans.labels_
colors = ["g.","r."]
for i in range(len(X)):
print("coordinate:",X[i], "label:", labels[i])
plt.plot(X[i][0], X[i][1], colors[labels[i]], markersize = 10)
plt.scatter(centeroids[:, 0],centeroids[:, 1], marker = "x", s=150, linewidths = 5, zorder = 10)
print centeroids
print labels
plt.show()
On first run labels are [0 1 0 1 0 1]. One second run labels are [1 0 1 0 1 0]. How can I make it fixed?
On the first run, this is how clusters are assigned to the dataset.
[1, 2] ------>0
[5, 8] ---------->1
[1.5, 1.8] ---------> 0
[8, 8] ---------->1
[1, 0.6] ---------> 0
[9, 11]----------->1
On the second run, this is how clusters are assigned to the dataset.
[1, 2] ------>1
[5, 8] ---------->0
[1.5, 1.8] ---------> 1
[8, 8] ---------->0
[1, 0.6] ---------> 1
[9, 11]----------->0
How do I make it not change?