I am trying to build a recommendation system in Python that recommends songs based on a playlist.

What I have is two datasets:
1. One dataset consists of 350 songs from my playlist and 13 acoustic features for each one like timber, energy, key, tempo, etc. that I extracted using the Spotify API
2. The other dataset consists of 340 000 songs and their acoustic features (got it from here: https://components.one/datasets/billboard-200/)
I've gotten both datasets in the same format and ready to be worked with.

Now what I am trying to do in Python is use my first dataset to get 30-40 songs with similar acoustic features from the second dataset but I have no idea how to approach this.
Should I use some machine-learning models or do something entirely else?
I thought about comparing the songs from my first dataset to the songs on my second dataset and pulling the ones with a similarity score of let's say over 70% or something like that but I feel like there is probably a much better way of doing this.


1 Answer 1


If the features are identical, good start would be to use n-neighbors approach.

It would be something like that

from sklearn.neighbors import NearestNeighbors
all_songs_features = [[0, 0, 2], [1, 0, 0], [0, 0, 1], [100, 100, 100], [0, 0, 1.5]]
neigh = NearestNeighbors()

my_song_features = [[0, 0, 1.3], [1.1, 0, 0]]
print(neigh.kneighbors(my_song_features, 2, return_distance=False))

These code returns the indexes of similar songs from the bigger dataset.

Note, if the features are with different range (i.e. one with values 0-1 and another 10000-1000000), then you need to scale them, for example with StandardScaler

  • $\begingroup$ Yes, the features are identical in both datasets. I used the nearest neighbor algorithm and I think it works but I'm wondering if you could get even more accurate results with something else. Anyway, thank you for the answer! $\endgroup$
    – Ladinsworm
    May 1, 2020 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.