Round Groups Versus Moons

Machine Learning in CodeMedium+10 XP+10

Round Groups Versus Moons

Two interlocking crescent moons are the classic shape that k-means gets wrong. Measure how wrong, and how DBSCAN does on the same points.

Task: write moon_scores(n_samples, noise, eps).

  • Make the data with make_moons(n_samples=n_samples, noise=noise, random_state=0). It returns X, y.
  • Fit KMeans(n_clusters=2, random_state=0, n_init=10) on X.
  • Fit DBSCAN(eps=eps, min_samples=5) on X.
  • Score each one against y with adjusted_rand_score.
  • Return [kmeans_score, dbscan_score], each as a plain float rounded to 3 decimal places.

Leave DBSCAN's noise points (-1) in the labels as they are. The score treats them as one more group.

Examples

n_samples = 200
noise = 0.05
eps = 0.3
returns [0.256, 1.0]
n_samples = 200
noise = 0.05
eps = 0.05
returns [0.256, 0.0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run