A delivery company has plotted its drop-off points on a map and wants to find the crowded areas, without saying in advance how many there are. That is DBSCAN's job. It asks the same question at every point: how many other points lie within of me?
Task: write dbscan_roles(points, eps, min_pts), where points is a list of (x, y) pairs. Return a tuple (roles, clusters):
roles: one entry per point, in the same order as points, each "core", "border" or "noise";clusters: the number of clusters DBSCAN finds.Use these rules:
eps. A distance of exactly eps counts.min_pts neighbours. The point itself is not one of its own neighbours.scikit-learn's
min_samplescounts the point itself, so it is always one more thanmin_ptshere. Follow the rules above.