Exercises
Exercises
Conceptual
Exercise 1 Conceptual
We have six points with the following pairwise Euclidean distances.
| 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|
| 1 | 0.3 | 0.4 | 0.7 | 0.9 | 0.8 |
| 2 | 0.5 | 0.8 | 1.0 | 0.9 | |
| 3 | 0.45 | 0.75 | 0.7 | ||
| 4 | 0.3 | 0.25 | |||
| 5 | 0.2 |
- Apply hierarchical clustering with complete linkage. Draw the dendrogram with the merges at the correct heights.
- Do the same with single linkage. Where do the two differ.
- Cut the complete linkage dendrogram to get two clusters. Which points are together.
Exercise 2 Conceptual
About k-means.
- Show that step (b) of the algorithm, moving each centroid to the mean, is the choice that minimizes \(W_k\) for fixed assignments.
- Argue that the algorithm converges in a finite number of steps.
- Why does it converge to a local and not a global minimum.
- After convergence, is every point in exactly one cluster. Is every cluster non-empty.
Exercise 3 Conceptual
Explain in two sentences each.
- Why does cross-validation on \(W_k\) not work for choosing \(k\).
- Why is k-means a special case of a Gaussian mixture model.
- Why can DBSCAN find clusters that k-means cannot.
- Why does standardizing the data change the result of every method on this page.
Applied
Exercise 4 Applied
Cluster the iris data.
- Load it and drop the class column. Standardize the four measurements.
- Run k-means for \(k = 2\) to \(8\) and plot \(W_k\) and the silhouette score.
- Which \(k\) would you choose from each of the two plots.
- Compare the clustering at your chosen \(k\) to the true species with a confusion matrix. Note that the cluster numbers are arbitrary.
Exercise 5 Applied
The same data with hierarchical clustering.
- Build the dendrogram with complete linkage and Euclidean distance.
- Cut it to get three clusters and compare to the species.
- Repeat with single, average and Ward linkage. Do the results change qualitatively.
- Repeat without standardizing. How much does it matter here.
Exercise 6 Applied · optional
Cluster the MNIST digits with k-means and ten clusters.
- Show five images from each cluster.
- Compute the confusion matrix against the true labels.
- Which digits end up in the same cluster, and can you say why from the images.
Exercise 7 Applied · optional
Generate data with no cluster structure at all, for example 500 points uniform on a square.
- Run k-means for \(k = 2\) to \(8\) and plot the silhouette score.
- Run it on data with three genuine clusters and plot the same curve.
- Compare the two curves. How would you tell, from the curve alone, that the first data set has no clusters.