Get startedGet started for free

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

View Course

Exercise instructions

  • Import linkage and dendrogram from scipy.cluster.hierarchy.
  • Perform hierarchical clustering on samples using the linkage() function with the method='single' keyword argument. Assign the result to mergings.
  • Plot a dendrogram of the hierarchical clustering, using the list country_names as the labels. In addition, specify the leaf_rotation=90, and leaf_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()
Edit and Run Code