Recap: Playlist Moods
Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 42 of 51.
Challenge
MediumYour playlist's 98 songs are in songs.csv. Sort them into moods; the chart is set up.
- Scale the four features and cluster the songs into 4.
- Name each cluster from its mean energy and valence: both 0.5 or more is
happy, only energytense, only valencecalm, neithersad. - Biggest first, print each mood's size and anthem: the song nearest its center.
- Scatter valence across and energy up, one group per mood labelled with its name; legend, show.
For the chapter's first playlist:
happy: 26 songs, anthem Lucky Avenue
tense: 22 songs, anthem Midnight Highway
sad: 17 songs, anthem Grey Bridges
calm: 15 songs, anthem Soft Windowand its chart:
Then Coddy describes yours.
Try it yourself
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
# One row per song: energy and valence (0 sad to 1 happy) from 0 to 1, tempo, acousticness
songs = pd.read_csv("songs.csv")
features = ["energy", "valence", "tempo_bpm", "acousticness"]
fig, ax = plt.subplots()
ax.set_title("Playlist Moods")
ax.set_xlabel("Valence (sad to happy)")
ax.set_ylabel("Energy")
# 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