Star Clusters
Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 50 of 51.
An astronomy club photographed one patch of sky. Some of its 225 stars belong together, born in the same cloud; the rest are strangers in front or behind:
Both positions are in arcminutes, one unit, so eps is a distance on the photo.
The club wants each cluster and its size, with the lone field stars left out. Would k-means do as well?
Challenge
HardThe program reads eps; the starter sets up two maps, left and right.
- Run DBSCAN with that eps and
min_samples=5on the two positions. Print its clusters and field stars (label -1). - Fit k-means with as many clusters (
n_init=10,random_state=0). Print the biggest and smallest cluster of each method. - On
left, map the DBSCAN clusters,cluster 1the biggest, then thefield starsin gray. Onright, the k-means clusters, numbered the same way. Legends, show.
For another photo and eps 2.5:
DBSCAN: 3 clusters and 29 field stars
Biggest cluster: 63 stars by DBSCAN, 77 by k-means
Smallest cluster: 41 stars by DBSCAN, 48 by k-meansand its maps:
Then Coddy describes yours. Which method would you trust with the field stars?
Try it yourself
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.cluster import DBSCAN, KMeans
# One row per star in the photo: position (arcminutes) and brightness (magnitude)
field = pd.read_csv("field.csv")
eps = float(input())
# Two maps side by side: DBSCAN on the left, k-means on the right
fig, axs = plt.subplots(1, 2, figsize=(10, 4))
left = axs[0]
right = axs[1]
left.set_title("DBSCAN")
right.set_title("k-means")
for ax in axs:
ax.set_xlabel("x (arcmin)")
ax.set_ylabel("y (arcmin)")
# 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