title: How do I color clusters after k-means and TSNE in either seaborn or matplotlib?
body: <p>I have a dataframe that look something like this:</p>
  <pre><code>transformed_centroids = model2.fit_transform(everything)
  df = pd.DataFrame()
  df[&quot;y&quot;] = model.labels_
  df[&quot;comp-1&quot;] = transformed_centroids[-true_k:, 0]
  df[&quot;comp-2&quot;] = transformed_centroids[-true_k:, 1]
  </code></pre>
  <p>The 'y' are the k-means labels I want to color by, and &quot;comp-1&quot; and &quot;comp-2&quot; are the results from the TSNE model. When I try to plot like this:</p>
  <pre><code>sns.scatterplot(transformed_centroids[:-true_k, 0], transformed_centroids[:-true_k, 1], marker='x')
  sns.scatterplot(df['comp-1'], df['comp-2'], marker='o', hue=df['y'])
  plt.show()
  </code></pre>
  <p>It gives me this error:</p>
  <p>ValueError: Length of values (2) does not match length of index (35104) (from this line: df[&quot;comp-1&quot;] = transformed_centroids[-true_k:, 0])</p>
  <p>This happens even if I do this:</p>
  <pre><code>sns.scatterplot(transformed_centroids[:-true_k, 0], transformed_centroids[:-true_k, 1], marker='x')
  sns.scatterplot(df['comp-1'], df['comp-2'], marker='o', hue=df.y.astype('category').cat.codes)
  plt.show()
  </code></pre>
  <p>I've tried several other pieces of code scattered around random tutorials and here, but I haven't found a solution. I feel silly having successfully completed the clustering but failing on the colors.</p>
  <p>EDIT: I realized I was using the wrong plot-points. The updates code and error is below:</p>
  <pre><code>df[&quot;y&quot;] = model.labels_
  df[&quot;comp-1&quot;] = transformed_centroids[:, 0]
  df[&quot;comp-2&quot;] = transformed_centroids[:, 1]
  </code></pre>
  <p>ValueError: Length of values (35106) does not match length of index (35104)</p>
  <p>I'm not sure where the two dropped data-points are being... dropped.</p>
  <p>EDIT2: Here is the TSNE code:</p>
  <pre><code>centroids = model.cluster_centers_
  tweets_df2['labels'] = model.labels_
  everything = np.concatenate((X.todense(), centroids))
  
  tsne_init = 'pca'  # could also be 'random'
  tsne_perplexity = 20.0
  tsne_early_exaggeration = 4.0
  tsne_learning_rate = 1000
  model2 = TSNE(n_components=2, random_state=0, init=tsne_init, perplexity=tsne_perplexity,
                early_exaggeration=tsne_early_exaggeration, learning_rate=tsne_learning_rate)
  transformed_centroids = model2.fit_transform(everything)
  df = pd.DataFrame()
  </code></pre>
  <p>I took this code from another stacked overflow post and fit it to my data so I can't explain it 100%, I just know I needed to use TSNE to get my data-points to become 2D plottable since the data was words vectorized using TD-IDF</p>