Recap: Dog Breeds
Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 19 of 51.
Challenge
MediumA dog shelter has five kennel rooms and wants similar breeds to share one. breeds.csv holds 21 breeds; the starter sets the cut height, cut.
- Scale the
featuresand build a ward tree. - Draw its dendrogram on
ax: breed names turned 90 degrees, colors stopping at the cut, and a gray dashed cut line. Show it. - Cut the tree, profile the groups in real units, and print them from lightest to heaviest, each named after its first breed.
For another shelter:
5 breeds like Maltese: 4.1 kg, 24 cm, energy 3.2, 14.4 years
3 breeds like Whippet: 12.7 kg, 46 cm, energy 4.7, 13.3 yearsand its tree, cut into 2 groups:
Then Coddy describes your tree.
Try it yourself
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from scipy.cluster.hierarchy import linkage, dendrogram, fcluster
# 21 dog breeds: weight (kg), height (cm), energy from 1 to 5, lifespan (years)
breeds = pd.read_csv("breeds.csv")
features = ["weight_kg", "height_cm", "energy", "lifespan_yr"]
# The shelter has five kennel rooms, so it cuts its tree at this height
cut = 2.5
fig, ax = plt.subplots(figsize=(8, 5))
fig.subplots_adjust(bottom=0.35) # room for the names below the tree
ax.set_title("Dog Breeds")
ax.set_ylabel("Merge height")
# 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