Menu
CoddyTech

Noise Points

Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 21 of 51.

Not every point joins a crowd. DBSCAN labels those -1: noise. In a park, picnics are crowds and people sitting alone are noise:

A park map with four picnics as tight groups of colored dots, sizes 16, 12, 20 and 14, and nine people alone as gray x marks scattered between them

Count both:

labels = DBSCAN(eps=3, min_samples=4).fit_predict(X)
print((labels == -1).sum())
print(labels.max() + 1)

This prints 9 and 4. Noise is -1, so the largest label still counts the crowds.

Noise is not a failure. Often the lone points are the story: a hiker off the trail, a reading unlike the rest.

challenge icon

Challenge

Medium

Reindeer wear GPS collars. Herds are crowds; a reindeer alone may be lost or hurt, so the herder visits those first. The starter runs DBSCAN with min_samples read from input.

  1. Print how many herds there are.
  2. Print how many reindeer are alone.
  3. Print their tags as a list, to check on.

For another herder's collars:

Herds: 2
Lone reindeer: 3
Check on: ['R011', 'R027', 'R040']

Try a bigger min_samples: a stricter crowd rule leaves more reindeer alone.

Try it yourself

import numpy as np
import pandas as pd
from sklearn.cluster import DBSCAN

# GPS collars at dawn: each reindeer's tag and position in km
reindeer = pd.read_csv("reindeer.csv")
X = np.column_stack([reindeer["east_km"], reindeer["north_km"]])
min_samples = int(input())
labels = DBSCAN(eps=0.6, min_samples=min_samples).fit_predict(X)

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Unsupervised Learning

Practice on your own: Online Python compiler