Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sample hierarchical clustering

# Import linkage and fcluster functions
from scipy.cluster.hierarchy import linkage, fcluster

# Use the linkage() function to compute distance
Z = linkage(df, 'ward')

# Generate cluster labels
df['cluster_labels'] = fcluster(Z, 2, criterion='maxclust')

# 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 #hierarchical #clustering
ADD COMMENT
Topic
Name
8+9 =