title: changing cluster labels for kmeans model
body: <p>I have fit a Kmeans model on document embeddings from a Doc2Vec model to cluster the embeddings and get a visualization as well as the most frequent terms per cluster. I have been able to do this fine and get the same visualization each time.</p>
  
  <p>When I run the kmeans.fit_predict on the model it gives me a list of cluster labels according to the clusters I have specified of the same length as the number of document embeddings I have. The issue comes when running the model multiple times it gives a similar spread per cluster each time but the cluster labels will change after running it multiple times. For example,</p>
  
  <ol>
  <li>Run 1 - 0:100, 1:100, 2:10 </li>
  <li>Run 2 - 0:99 , 1:101, 2:10 </li>
  <li>Run 3 - 2:100, 0:100, 1:10 </li>
  <li>Run 4 - 0:100, 1:100, 2:10</li>
  </ol>
  
  <p>I tried saving the model and using the same model multiple times but encountered the same issue. This causes the most frequent terms per cluster and position of the cluster in the visualization to change, which changes the way it is interpreted. I was planning to use the labels as a classification method but doesn't this make that impossible? I'm not sure if its an issue with my code or if this is normal behavior if anyone can help it would be much appreciated.</p>
  
  <pre><code>df = pd.read_csv("data.csv")
  d2v_model = Doc2Vec.load("d2vmodel")
  
  clusters = 3
  iterations = 100
  
  kmeans_model = KMeans(n_clusters=clusters, init='k-means++', max_iter=iterations) 
  X = kmeans_model.fit(d2v_model.docvecs.vectors_docs)
  l = kmeans_model.fit_predict(d2v_model.docvecs.vectors_docs)
  labels = kmeans_model.labels_.tolist()
  
  pca = PCA(n_components=2).fit(d2v_model.docvecs.vectors_docs)
  datapoint = pca.transform(d2v_model.docvecs.vectors_docs)
  
  df["clusters"] = labels
  cluster_list = []
  cluster_colors = ["#FFFF00", "#008000", "#0000FF"] 
  plt.figure
  color = [cluster_colors[i] for i in labels]
  plt.scatter(datapoint[:, 0], datapoint[:, 1], c=color)
  centroids = kmeans_model.cluster_centers_
  centroidpoint = pca.transform(centroids)
  plt.scatter(centroidpoint[:, 0], centroidpoint[:, 1], marker="^", s=150, c="#000000")
  
  plt.show()
  
  for i in range(clusters):
      df_temp = df[df["clusters"]==i]
      cluster_words = Counter(" ".join(df_temp["Body"].str.lower()).split()).most_common(25)
      [cluster_list.append(x[0]) for x in cluster_words]
      cluster_list.clear()
  </code></pre>