Recap: City Lights
Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 23 of 51.
Challenge
MediumRemember the valley map from DBSCAN? Now you make one. A satellite photographed a valley at night; group its lights into towns and find the lone ones: farms, a lighthouse, a camper. The program reads eps in km.
- Run DBSCAN with that eps and
min_samples=5. - Print the number of towns, the number of lone lights, and the biggest town's size.
- Map them: each town its own scatter labelled
town of N lights, lone lights as grayxmarks labelledlone lights, a legend. Show it.
For another valley and eps 1.3:
Towns: 3
Lone lights: 10
Biggest town: 77 lightsCoddy describes your map. Then try eps 5: which towns merge?
Try it yourself
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.cluster import DBSCAN
# A satellite's night photo of a valley: one row per light, position in km
lights = pd.read_csv("lights.csv")
X = np.column_stack([lights["east_km"], lights["north_km"]])
eps = float(input())
fig, ax = plt.subplots()
ax.set_title("Valley at Night")
ax.set_xlabel("East (km)")
ax.set_ylabel("North (km)")
# Write your code below
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