Clusters and Strays

Machine Learning in CodeEasy+10 XP+10

Clusters and Strays

A wildlife camera logs where foxes were spotted, as [x, y] points in hundreds of metres. Some spots are busy dens; others are one-off sightings.

DBSCAN finds the busy areas without being told how many there are, and labels lone points as noise with -1.

Task: write clusters_and_noise(points, eps, min_samples).

  • Fit DBSCAN(eps=eps, min_samples=min_samples) on the points as given.
  • Count the clusters found. Noise (-1) is not a cluster.
  • Count the points labelled -1.
  • Return [number_of_clusters, number_of_noise_points], both plain ints.

Examples

points = [[6.14, 5.9], [-0.11, 0.03], [5.9, 6.45], [-0.16, -0.51], [5.93, 5.35], [6.33, 6.65], [5.64, 6.57], [0.26, -0.06], [5.71, 6.38], [-0.71, -0.61], [0.17, -0.41], [-0.12, -0.04], [-0.43, 0.49], [3.0, 10.0], [10.0, 0.0]]
eps = 1.0
min_samples = 4
returns [2, 2]
points = [[10.66, -0.18], [9.6, 0.05], [-0.0, -0.26], [-0.25, -0.2], [5.37, -0.83], [0.29, 0.01], [0.01, -0.15], [0.22, -0.29], [10.1, 0.48], [-0.07, 0.37], [5.26, 0.18], [10.44, -0.43], [5.31, 0.01], [4.9, -0.26], [4.95, 0.36], [5.41, -0.02], [9.69, -0.62], [9.67, 0.75], [5.0, 6.0]]
eps = 1.0
min_samples = 4
returns [3, 1]

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