Menu
CoddyTech

Recap: Bird Songs

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

challenge icon

Challenge

Medium

A birdwatcher recorded 160 songs from four species, 7 measurements each. Squeeze them into one map, like the wines that opened this chapter.

  1. Scale the measurements and fit a PCA() that keeps every component; keep its fit_transform output in points.
  2. Print the share of spread the first two components keep, 3 decimals, and how many components reach 90%.
  3. Scatter the first two components, one group per species labelled with its name, and a legend. Show it.

For another birdwatcher:

First two keep: 0.818
Components for 90%: 4

A chart titled Bird Songs in 2D, first component across and second up: four groups of songs, blackbird, chaffinch, robin and wren, each in its own color, with a legend

Coddy describes your map. Which two species sing most alike?

Try it yourself

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA

# A birdwatcher's recordings: 7 measurements for each of 160 songs, and the singer's species
songs = pd.read_csv("songs.csv")
X = songs.drop(columns="species")

fig, ax = plt.subplots()
ax.set_title("Bird Songs in 2D")
ax.set_xlabel("First component")
ax.set_ylabel("Second component")

# Write your code below

All lessons in Unsupervised Learning

Practice on your own: Online Python compiler