Open sophryu99 opened 3 years ago
Steps
def recommend_songs(self, song_list, n_songs=10):
song_center = self.get_mean_vector(song_list, self.df)
scaler = self.cluster().steps[0][1]
scaled_data = scaler.transform(self.df[self.number_cols])
scaled_song_center = scaler.transform(song_center.reshape(1, -1))
distances = cdist(scaled_song_center, scaled_data, 'cosine')
index = list(np.argsort(distances)[:, :n_songs][0])
rec_songs = self.df.iloc[index]
# Exclude tracks data in input
rec_songs = rec_songs[~rec_songs['track_id'].isin(song_list)]
track_ids = [i for i in rec_songs['track_id']]
rec_results = self.song_features(track_ids)
return rec_results
Content-based Filtering
Content-based filtering uses item features to recommend other items similar to what the user likes, based on their previous actions or explicit feedback. Considers only one user.