-
-
Save amankharwal/e35290f8f355280c8d939e381f0b43ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Spotify_Recommendation(): | |
def __init__(self, dataset): | |
self.dataset = dataset | |
def recommend(self, songs, amount=1): | |
distance = [] | |
song = self.dataset[(self.dataset.name.str.lower() == songs.lower())].head(1).values[0] | |
rec = self.dataset[self.dataset.name.str.lower() != songs.lower()] | |
for songs in tqdm(rec.values): | |
d = 0 | |
for col in np.arange(len(rec.columns)): | |
if not col in [1, 6, 12, 14, 18]: | |
d = d + np.absolute(float(song[col]) - float(songs[col])) | |
distance.append(d) | |
rec['distance'] = distance | |
rec = rec.sort_values('distance') | |
columns = ['artists', 'name'] | |
return rec[columns][:amount] | |
recommendations = Spotify_Recommendation(data) | |
recommendations.recommend("Lovers Rock", 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment