Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sample k-means clustering

from scipy.cluster.vq import kmeans, vq

# Compute cluster centers
centroids,_ = kmeans(df, 2)

# Assign cluster labels
df['cluster_labels'], _ = vq(df , centroids)

# Plot the points with seaborn
sns.scatterplot(x='x', y='y' , hue= 'cluster_labels', data=df)
plt.show()
Source by campus.datacamp.com #
 
PREVIOUS NEXT
Tagged: #sample #clustering
ADD COMMENT
Topic
Name
9+5 =