Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: defaultdict item count 
Python :: python import list from py file 
Python :: select element using Css selector in python 
Python :: unicode error python 
Python :: conv2d default stride 
Python :: how to convert string into list in python 
Python :: python loop to a tuple 
Python :: python debugging 
Python :: return the first occurence of duplicates pandas 
Python :: search in django 
Python :: sum values 
Python :: python combine two columns into matrix 
Python :: Python Switch case statement by Dictionary Mapping 
Python :: generate python 
Python :: python split string by specific word 
Python :: check if text is python 
Python :: docker compose cron 
Python :: lambda 
Python :: convolution operation pytorch 
Python :: how to check if digit in int python 
Python :: python power of natural number 
Python :: upgrade python version windows 
Python :: python check if number contains digit 
Python :: time converting module 
Python :: itertools count 
Python :: geodataframe get crs 
Python :: python how to vectorize a function 
Python :: google youtuve api python 
Python :: js choice function 
Python :: python in line elif 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =