◢◤ ARKANE_
SYS_TIME UTC+0
Work with me

Chapter 19 quiz · 23 questions

Unsupervised Learning

Tests K-Means by hand, choosing K, silhouette, GMM soft assignment, DBSCAN point types, linkage and dendrograms, and Isolation Forest's contamination rate.

Based on chapter 19. Every answer comes with an explanation and a link back to the section.

/Q19

Quiz

Question 1 of 23

K-Means: assign, update, inertia and scaling Level 1
Progress

Why does scikit-learn's KMeans run the algorithm several times (n_init=10) and keep the best result?

Choose one
/02

练习From the book

7 exercises

The chapter's own exercises are open questions. Try one, then compare with the model answer.

Exercise 19.1 [W]

Explain in one or two sentences why K-Means needs KK decided in advance while DBSCAN does not.

Show the model answer

K-Means's algorithm requires KK centroids to initialise and assign points to before it can even begin iterating. The number of centroids is a structural input to the procedure, not something it discovers. DBSCAN instead defines clusters implicitly, as whatever dense regions emerge from the eps/min_samples density criteria applied to the actual data. However many dense regions exist is however many clusters result, with no upfront count required.

Exercise 19.2 [W]

State which algorithm (K-Means or DBSCAN) is the better default for each: (a) a large, roughly spherical, well-separated set of customer segments; (b) an unknown number of irregularly shaped clusters with some genuine noise points mixed in.

Show the model answer

(a) K-Means: large, roughly spherical, well-separated segments are exactly K-Means's best-case assumption, and it scales better than DBSCAN on large data. (b) DBSCAN: an unknown cluster count with irregular shapes and genuine noise is exactly the case K-Means structurally cannot handle (fixed K, spherical assumption, no built-in outlier concept) and DBSCAN is built for.

Exercise 19.3 [A]

Using Listing 19.5's measured ARI scores (K-Means 0.479, DBSCAN 0.987), explain in your own words why a higher silhouette score for K-Means's own clustering wouldn't necessarily have revealed this failure: silhouette measures compactness given the clustering K-Means chose, not whether that clustering matches the true structure.

Show the model answer

Silhouette score measures how well each point fits its assigned cluster relative to the next-nearest cluster, using whatever clustering was produced. It has no access to the true crescent-shaped structure, and cannot detect that K-Means drew the wrong kind of boundary. A K-Means clustering on the moons data could report a moderate-to-decent silhouette score for the (wrong) roughly-circular split it found. That's precisely because silhouette only asks "is this point closer, on average, to the points in its own cluster than to the points in the nearest other one," which K-Means's convex clusters can satisfy reasonably well even while completely missing the true crescent shapes. Silhouette validates internal consistency with the algorithm's own assumptions, not correctness against ground truth.

Exercise 19.4 [A]

Using Listing 19.3's measured results (27 flagged, precision 0.852, recall 0.920), compute the number of false positives and false negatives, and state which of the two errors this particular run made more of.

Show the model answer

With 27 flagged, precision 0.852 means 27×0.852≈2327 \times 0.852 \approx 23 true positives, so false positives =27−23=4= 27 - 23 = 4. Recall 0.920 on 25 true anomalies means 25×0.920=2325 \times 0.920 = 23 true positives (consistent), so false negatives =25−23=2= 25 - 23 = 2. This run made more false positives (4) than false negatives (2): it over-flagged slightly more than it missed, though both error types are present.

Exercise 19.5 [E]

A customer wants to segment their customer base and reports "we found 6 clusters with a great silhouette score." Using this chapter's Trade-offs section, write the follow-up question you'd ask before treating those 6 clusters as actionable business segments.

Show the model answer

"How well do those 6 clusters hold up when you show them to someone who knows these customers? Do the groups correspond to real, distinct behaviours, or just to a geometrically tidy split of the feature space? A good silhouette score tells you the clusters are internally compact and well-separated; it says nothing about whether they're the useful 6 groups for your business decisions."

Exercise 19.6 [E]

A fraud team sets IsolationForest's contamination=0.20 "because that gives us the cleanest-looking separation in our validation plots." Using Procedure 19.3's common mistake, explain why this reasoning is circular.

Show the model answer

Setting contamination to whatever value produces the "cleanest-looking" separation is circular, because it's using the model's own output to justify the input that produced that output. Instead of contamination reflecting an actual prior belief about how much of the data is truly anomalous, it's being reverse-engineered from a desired visual result. This risks hiding real anomalies (if the "clean" contamination is set too low), or manufacturing fake ones (if set too high), rather than reflecting genuine fraud prevalence.

Exercise 19.7 [R]

Read the original Isolation Forest paper's (Liu et al., 2008) abstract. Identify the specific computational-complexity claim it makes relative to distance-based anomaly detection methods, and explain how that relates to this chapter's "scales well, works in high dimensions" summary.

Show the model answer

Discussion only. The Isolation Forest paper's key complexity claim is that it achieves roughly linear time complexity and constant memory with respect to dataset size. That's because it doesn't need to compute pairwise distances or density estimates the way distance-based methods (like LOF or One-Class SVM) do: isolation only requires random splits, not distance comparisons between all pairs of points. This directly explains this chapter's "scales well, works in high dimensions" summary. Avoiding pairwise distance computation is exactly what lets it scale where density- or distance-based alternatives struggle.

online /books/classical-data-science/quiz/19 Newcastle, UK v0.1.0 // rss