1

Very basic question:

How do I print the observations attributed to any one cluster?

data = pd.read_csv('my_file.csv')
X = data[['Var1','Var2','Var3']]
ms = MeanShift()
ms.fit(X)
labels = ms.labels_
cluster_centers = ms.cluster_centers_

I'd just like to see the values of 'Var1','Var2','Var3' for any one cluster.

Liam Hanninen
  • 1,525
  • 2
  • 19
  • 37

1 Answers1

2

It sounds like you want to view the predictions for your dataset. This can be done as follows:

y_pred = ms.predict(X)

You could then link these up to your samples by doing this:

df['y_pred'] = y_pred

And filter your dataframe as desired, e.g. to see the samples in cluster 1:

df[df.y_pred == 1]
Alex
  • 12,078
  • 6
  • 64
  • 74