Hierarchical clustering: complete method
For the third and final time, let us use the same footfall dataset and check if any changes are seen if we use a different method for clustering.
The data is stored in a pandas DataFrame, comic_con
. x_scaled
and y_scaled
are the column names of the standardized X and Y coordinates of people at a given point in time.
Cet exercice fait partie du cours
Cluster Analysis in Python
Instructions
- Import
fcluster
andlinkage
fromscipy.cluster.hierarchy
. - Use the
complete
method in the.linkage()
function.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Import the fcluster and linkage functions
____
# Use the linkage() function
distance_matrix = ____(____, ____, ____)
# Assign cluster labels
comic_con['cluster_labels'] = ____
# Plot clusters
sns.scatterplot(x='x_scaled', y='y_scaled',
hue='cluster_labels', data = comic_con)
plt.show()