Unit 6 of 8 · about 4 hours · explain, measure

DBSCAN, agglomerative clustering and cluster validation

Real groups are rarely spheres. Density and merge views find moons and hierarchies that k-means smears, but their knobs decide the answer.

You'll be able to

  • Explain DBSCAN core, border and noise labels from eps and min_samples and linkage choices in agglomerative clustering.
  • Measure eps sensitivity, linkage disagreement and seed and sample stability on one dataset.
  • State what silhouette and Rand indices can and cannot justify for non-convex clusters.

Covers

DBSCAN and agglomerative clustering geometryCluster stability, usefulness and internal-metric limits
1

Read

In this order, only the parts listed

0 of 2 done

  1. DBSCAN contrast and agglomerative exampleHands-On Machine Learning with Scikit-Learn and PyTorch - dimensionality reduction and unsupervised learning

    Book Chapter 8: DBSCAN and Other Clustering Algorithms (printed pp. 265-269). Notebook 08 cells: DBSCAN: make_moons(1000, noise=0.05) at eps=0.05 (7 clusters, many points labeled -1) versus eps=0.2 (two clusters, no noise), core_sample_indices_, components_, and KNN on the cores with a 0.2 distance cutoff to label new points; Other Clustering Algorithms: AgglomerativeClustering with complete linkage on

    Skim the Spectral Clustering bonus code; keep the eps contrast and the linkage example.

  2. Density, linkage and metric limitsscikit-learn - decomposition, clustering and outlier detection

    2.3.7 DBSCAN: dense definition from eps and min_samples, core, border and outlier rules, the eps-must-be-tuned warning with all-noise and merged-cluster failures; 2.3.6 hierarchical clustering: Ward, complete, average and single linkage with the uneven-size guidance; 2.3.11 metrics: silhouette formula with its convex-cluster bias and the adjusted Rand index correcting for chance

2

Focus on

  • eps sets the neighborhood radius and min_samples the density floor. On the notebook moons, eps=0.05 breaks the two moons into 7 clusters and labels 7.7 percent as noise, while 0.2 finds the two moons with no noise; always sweep eps.
  • Linkage defines merge distance: single follows chains, complete compacts, Ward prefers equal-variance merges. On single splits off 8.5 while complete pairs neighbors.
  • DBSCAN labels new points only by extra machinery: the notebook trains KNN on cores. The clusterer itself has no predict.
  • Silhouette rewards dense convex separation and can punish correct density shapes. Pair it with stability and downstream checks.
Common mistakes · 3
  • Leaving eps at 0.5 on unscaled features. eps lives in feature units; scale first or the radius is meaningless.
  • Calling -1 a detected anomaly set. It means not dense enough under this eps; nearby eps values relabel it.
  • Reporting silhouette alone on moons. On the notebook moons a k-means split scores 0.49 and the true moon labels 0.33; the docs warn that silhouette favors convex clusters.
3

Try it yourself

Closed-book, before checking anything

Closed-book, hand-run DBSCAN with eps=2.0 and min_samples=2 on : two core groups with no noise. Then move one point to and show it becomes -1.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.On the notebook moons, eps=0.05 gives 7 clusters and 7.7 percent noise, while eps=0.2 gives two clean moons. What went wrong at 0.05, and what does the -1 label mean?Answer

    The radius is too small for the sampling density. A core needs min_samples points within eps, counting itself, so sparse stretches of each moon lose their cores and the moons fragment. A -1 point is within eps of no core: not dense enough under these settings, which is not the same as anomalous.

  2. 2.Single linkage gives and complete gives on . Which is right?Answer

    Both follow their definitions: single chains through small gaps, complete caps the largest within-cluster distance. The task decides which grouping is useful.

  3. 3.On the notebook moons, KMeans(2) scores silhouette 0.49 and the true moon labels score 0.33. Which clustering is better?Answer

    The true moons. Silhouette rewards compact convex groups, so it ranks the wrong spherical split higher. Use stability, adjusted Rand against any known structure, and downstream checks.

  4. 4.Two DBSCAN runs with close eps values disagree on 5 percent of labels. What do you report?Answer

    The disagreement rate and which points flip, usually borders. Stability is evidence; one label vector is not.

5

Practice

  • Deep-ML 259: Implement DBSCAN Clustering Algorithm

    Problem 259: implement dbscan(X, eps, min_samples) with Euclidean distance and -1 noise labels

    Test one checks [0 0 0 1 1 1] on two triplets; test two checks the far point becomes -1. Count the point itself toward min_samples, as scikit-learn does; with min_samples=2 test two needs that, or the pair , turns into noise. Expand clusters from core points only.

You're done when

Your implementation matches both Deep-ML label vectors, your eps sweep on moons shows the noise-to-merged transition, and two linkages disagree on record with reasons.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 6 more in the section

Also in this section

  • ISLP - Unsupervised LearningJames, Witten, Hastie, Tibshirani and Taylor · required

    Use Chapter 12 and its Python lab for the PCA derivations (12.2, including the low-rank approximation view and proportion of variance explained) and k-means (12.4.1), plus stability and interpretation limits, beside the notebook route.

  • Deep-ML - unsupervised problemsDeep-ML · support

    Use 17 K-Means Clustering, 19 PCA, 341 Gaussian Mixture Model with EM, 259 DBSCAN and 367 Isolation Forest as unit checks after the local implementation passes. Their tests were read in review; each card states what they pin, including the 367 path-length convention.

  • scikit-learn - preprocessing datascikit-learn · reference

    Read 8.3.1 standardization with the sparse with_mean=False rule, 8.3.1.3 scaling data with outliers, and 8.3.4 categorical encoding with handle_unknown, infrequent and sparse_output behavior. Apply after the HOML notebook build works.

  • scikit-learn - pipelines and composite estimatorsscikit-learn · reference

    Read 8.1.1 Pipeline chaining with the no-leakage rule and transformer caching, and 8.1.4 ColumnTransformer for heterogeneous columns with remainder and fitted-state behavior. Use it to assemble and serialize the feature-selection pipeline.

  • scikit-learn - imputation of missing valuesscikit-learn · reference

    Read 8.4.2 univariate median and most_frequent strategies, 8.4.6 Marking imputed values with MissingIndicator or add_indicator=True for missingness flags, and 8.4.7 estimators that accept NaN directly. Decide impute-only versus impute-plus-indicator per column.

  • UMAP - basic usage and parametersMcInnes, Healy and the UMAP contributors · reference

    Work the Penguin scaling and fit_transform section and the Digits fit and transform section, then read the parameters page for the n_neighbors local-global tradeoff and min_dist packing. Stay in 2D exploratory views with fixed seeds.