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:
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
MediumReindeer 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.
- Print how many herds there are.
- Print how many reindeer are alone.
- 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
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Unsupervised Learning
1Finding Groups
Learning Without LabelsMeasuring SimilarityK-Means by HandK-Means in scikit-learnRecap: Gym Members7PCA in Practice
Seeing 64 DimensionsComponents as PatternsCompress and RebuildPCA Before a ModelRecap: Face Scanner10Project: Digit Explorer
Look at the DigitsShrink with PCACluster the DigitsName the ClustersFind the Odd OnesPractice on your own: Online Python compiler