Different linkage, different hierarchical clustering!
In the video, you saw a hierarchical clustering of the voting countries at the Eurovision song contest using 'complete'
linkage. Now, perform a hierarchical clustering of the voting countries with 'single'
linkage, and compare the resulting dendrogram with the one in the video. Different linkage, different hierarchical clustering!
You are given an array samples
. Each row corresponds to a voting country, and each column corresponds to a performance that was voted for. The list country_names
gives the name of each voting country. This dataset was obtained from Eurovision.
This exercise is part of the course
Unsupervised Learning in Python
Exercise instructions
- Import
linkage
anddendrogram
fromscipy.cluster.hierarchy
. - Perform hierarchical clustering on
samples
using thelinkage()
function with themethod='single'
keyword argument. Assign the result tomergings
. - Plot a dendrogram of the hierarchical clustering, using the list
country_names
as thelabels
. In addition, specify theleaf_rotation=90
, andleaf_font_size=6
keyword arguments as you have done earlier.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Perform the necessary imports
import matplotlib.pyplot as plt
from ____ import ____, ____
# Calculate the linkage: mergings
mergings = ____
# Plot the dendrogram
____
plt.show()