Hierarchical clustering of the grain data
In the video, you learned that the SciPy linkage() function performs hierarchical clustering on an array of samples. Use the linkage() function to obtain a hierarchical clustering of the grain samples, and use dendrogram() to visualize the result. A sample of the grain measurements is provided in the array samples, while the variety of each grain sample is given by the list varieties.
Deze oefening maakt deel uit van de cursus
Unsupervised Learning in Python
Oefeninstructies
- Import:
linkageanddendrogramfromscipy.cluster.hierarchy.matplotlib.pyplotasplt.
- Perform hierarchical clustering on
samplesusing thelinkage()function with themethod='complete'keyword argument. Assign the result tomergings. - Plot a dendrogram using the
dendrogram()function onmergings. Specify the keyword argumentslabels=varieties,leaf_rotation=90, andleaf_font_size=6.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Perform the necessary imports
from ____ import ____, ____
import ____ as ____
# Calculate the linkage: mergings
mergings = ____
# Plot the dendrogram, using varieties as labels
dendrogram(____,
labels=____,
leaf_rotation=____,
leaf_font_size=____,
)
plt.show()