โ† All projects

Classifying Songs by Genre

Can audio features alone separate rock from hip-hop?

Real-world dataMachine LearningPythonscikit-learnpandasMatplotlib
4,802tracks
6PCA components keep 85% of variance
82%logistic regression, balanced data

The question

Streaming services recommend music from audio traits. I tested how far a few simple features go when the task is to label a track as rock or hip-hop.

What I did

Joined track metadata with Echo Nest audio features such as danceability, energy and acousticness.
Checked pairwise correlations, then scaled the features.
Used PCA to cut dimensions and picked the component count from the cumulative variance curve.
Compared a decision tree with logistic regression, first on the raw split and then on balanced classes.

What I found

Six principal components explain 85% of the variance in the audio features.
On the imbalanced data both models reached about 88% overall, but logistic regression found only 59% of hip-hop tracks.
After balancing the classes, logistic regression scored 82% against 76% for the decision tree, with even precision and recall on both genres.

Charts from the analysis

Variance explained by each principal component.
Variance explained by each principal component.

Limits to keep in mind

Real-world data

Plain accuracy hides the minority class here. Rock outnumbers hip-hop four to one, which is why the balanced comparison is the one to trust.

View the code on GitHub โ†—
โ† PreviousFIFA Player Performance and Market ValueNext โ†’A Visual History of Nobel Prize Winners