Dhruvin Dave

MusicAI

A content-based music recommender served through Django: search a track, get similar songs, songs with the same mood, and more from the same artist.

Problem

Given a track, find other tracks a listener is likely to enjoy when no listening history exists. The only signal is a set of Spotify audio features for 43,998 tracks: danceability, energy, loudness, valence, tempo and five more.

The Django app turns that into three lists for any track you search for: the nearest tracks overall, the nearest tracks within its mood, and more from the same artist. The trained artifacts are committed to the repository and loaded once per process, so a request is a lookup and a matrix-vector product, not a training run.

Approach

Cleaning drops rows with missing features and duplicate track IDs, and keeps only the most popular copy of a song that was re-released on several albums. The ten audio features are standardised.

Similar songs come from exact cosine k-NN. Rows are scaled to unit length once, so scoring the whole catalogue is one matrix-vector product plus a partial sort, and nothing is refit per request. That is also why the demo above runs in your browser, on an exported sample of the catalogue.

Moods come from K-Means with six clusters on the same features, each labelled from the sign of its centre’s valence and energy. “Same mood” recommendations are the nearest neighbours inside the query’s cluster.

For 2,000 random queries the evaluation scores the top ten against two baselines: ten random tracks, and the ten most popular. It reports how often the results share the query’s artist, how often they match its language, and how different the ten results are from one another. Silhouette and Davies-Bouldin scores for every k from 2 to 12 check the clusters.

The evaluation is offline and uses proxies. The top ten share the query’s artist more than half the time, against 16.5% for random picks.

Results

Every figure links to the file it was drawn from.

Artist hit-rate@10

Offline proxies, not user satisfaction. Accurate, but low diversity.

Share of the top ten that have the query's artist. Higher is better.

Artist hit-rate@10Bar chart: k-NN 0.565; Random 0.165; Popularity 0.011.k-NN0.565Random0.165Popularity0.011
Artist hit-rate@10
MethodValue
k-NN0.565
Random0.165
Popularity0.011

Share of the top ten in the query's language. Higher is better.

Language precision@10Bar chart: k-NN 0.441; Random 0.233; Popularity 0.328.k-NN0.441Random0.233Popularity0.328
Language precision@10
MethodValue
k-NN0.441
Random0.233
Popularity0.328

How different the ten results are from each other. Higher means more varied lists; k-NN is far lower.

Intra-list diversityBar chart: k-NN 0.062; Random 0.987; Popularity 0.784.k-NN0.062Random0.987Popularity0.784
Intra-list diversity
MethodValue
k-NN0.062
Random0.987
Popularity0.784

k = 10, 2,000 queries, 43,998 tracks.

Source

Try the recommender

3,000-track sample of 43,998. Exact cosine k-NN on the same ten audio features, running in your browser.

Loading 3,000 tracks…

Source

Limits

There is no interaction data, so there is no collaborative signal. Artist and language are imperfect proxies for taste, and the metrics are not user satisfaction.

The lists are accurate but low in diversity: intra-list diversity is 0.062, against 0.987 for random picks, and there is no diversity re-ranking. The K-Means silhouette is between 0.17 and 0.27, so the cluster structure is weak, and the mood labels are heuristic and unvalidated. Search is a literal substring match on track, artist and album names, not a ranked text search.

Code

Source, evaluation notes and the Django app are on GitHub.