DBSCAN Clustering — ML Technical Interview Questions & Answers

Density-based clustering that finds arbitrary-shaped clusters.

DBSCAN Clustering

  • Simple meaning: DBSCAN groups dense piles and marks lonely points as noise. You set a neighbourhood size (eps) and min points. No k up front.
  • Picture: Two banana-shaped clouds and some stray dots. K-means would cut bananas badly. DBSCAN can keep each banana and flag strays as outliers.
  • sklearn: DBSCAN(eps=0.5, min_samples=5). Scale first. eps is sensitive — try a k-distance plot.
  • Trap: one eps for mixed densities (one tight cluster, one loose). Trap: calling every noise point a fraud without a check.

Technical Interview Tip: Dense regions = clusters. Loners = noise. Good for odd shapes.

Code Examples for DBSCAN Clustering

DBSCAN Clustering — working example

# Tiny 1D k-means-style update (k=2)
points = [1.0, 1.5, 2.0, 8.0, 8.5, 9.0]
c1, c2 = 1.0, 9.0
for _ in range(3):
    g1 = [p for p in points if abs(p - c1) <= abs(p - c2)]
    g2 = [p for p in points if abs(p - c1) > abs(p - c2)]
    c1 = sum(g1) / len(g1)
    c2 = sum(g2) / len(g2)
print(round(c1, 2), round(c2, 2), len(g1), len(g2))

DBSCAN Clustering — clustering groups unlabeled points; k-means alternates assignment and centroid updates.

How to Explain DBSCAN Clustering to an Interviewer

What can DBSCAN label besides clusters?

Noise / outliers

Do you pick k?

No You pick eps and min_samples