MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Unsupervised Learning in Python

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Perform the necessary imports
import matplotlib.pyplot as plt
from ____ import ____, ____

# Calculate the linkage: mergings
mergings = ____

# Plot the dendrogram
____
plt.show()
Edit dan Jalankan Kode