Challenge - 5 Problems
Hierarchical Clustering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of linkage matrix with single linkage
What is the output of the linkage matrix when using single linkage on the given data points?
SciPy
from scipy.cluster.hierarchy import linkage import numpy as np X = np.array([[1, 2], [3, 4], [5, 6]]) Z = linkage(X, method='single') print(Z)
Attempts:
2 left
💡 Hint
Remember single linkage merges clusters based on the smallest distance between points.
✗ Incorrect
Single linkage merges clusters by the minimum distance between points. The distances between points are Euclidean. The linkage matrix shows the pairs merged, the distance, and the cluster size.
❓ data_output
intermediate1:30remaining
Number of clusters from dendrogram cut
Given the linkage matrix below, how many clusters remain if we cut the dendrogram at distance 3.0?
SciPy
import numpy as np Z = np.array([[0, 1, 1.5, 2], [2, 3, 2.5, 2], [4, 5, 4.0, 4]])
Attempts:
2 left
💡 Hint
Clusters merge when linkage distance is less than the cut distance.
✗ Incorrect
Cutting at distance 3.0 means merges with distance <= 3.0 are joined. The first two merges are below 3.0, so they form clusters. The last merge at 4.0 is above 3.0, so it is not merged. Thus, 2 clusters remain.
🔧 Debug
advanced1:30remaining
Identify the error in linkage method usage
What error will this code raise when running linkage with an invalid method name?
SciPy
from scipy.cluster.hierarchy import linkage import numpy as np X = np.array([[1, 2], [3, 4], [5, 6]]) Z = linkage(X, method='invalid_method')
Attempts:
2 left
💡 Hint
Check the allowed method names for linkage.
✗ Incorrect
The linkage function checks if the method name is valid. If not, it raises a ValueError with a message about unknown linkage method.
🚀 Application
advanced2:00remaining
Choosing linkage method for compact clusters
Which linkage method is best to produce compact, spherical clusters in hierarchical clustering?
Attempts:
2 left
💡 Hint
Ward linkage minimizes variance within clusters.
✗ Incorrect
Ward linkage merges clusters to minimize the total within-cluster variance, producing compact and spherical clusters. Other methods may produce elongated or irregular clusters.
🧠 Conceptual
expert2:30remaining
Effect of linkage method on dendrogram shape
How does the choice of linkage method affect the shape of the dendrogram in hierarchical clustering?
Attempts:
2 left
💡 Hint
Think about how distances between clusters are computed.
✗ Incorrect
Different linkage methods compute distances between clusters differently, affecting which clusters merge first and at what distance. This changes the dendrogram's branch heights and merge order.