top of page

COLLABORATIVE FILTERING

The Premise

For our next model, we chose to implement a collaborative filtering model using sklearn’s NearestNeighbors. This model (KN_model) would make song recommendations based on which songs showed up in existing playlists (obtained through the million playlist data) that were most similar to the starting playlist. 
The first step was to create a sparse matrix of playlists by tracks; each playlist had a row, and each track had a column. If playlist r contained track c, the matrix entry at [r, c] would be 1, and 0 otherwise. For example:

Screen Shot 2019-12-11 at 00.32.38.png
Collaborative Filtering: Intro

Thus, each playlist could be considered an array in “track-space,” meaning that the distance or similarity between playlists could be calculated using a dot product,

Collaborative Filtering: Text
Screen Shot 2019-12-11 at 00.35_edited.j
Collaborative Filtering: Image

Thus, we used “cosine” as our metric in our KN_model. Given the sparse matrix, this model would return the n nearest neighboring playlists, from which we could make our song suggestions.
Once we had the n nearest neighboring playlists, we iterated through every song in each neighboring playlist and returned the desired number of non-overlapping songs based on two factors: playlist similarity score and song occurrence frequency. Playlist similarity was based on the notion that our model should favor selecting songs from playlists that were scored as more similar to the original playlist. Thus, the candidate songs were given a score of 1/i, where i is the index of its playlist as ordered by similarity. This method assumes that the difference in similarity from Playlists 4 and 5 vs. Playlists 1 and 2 is proportional to the difference between ¼ and ⅕ vs. 1 and ½, which may not be the case, but this inverse method was a suitable metric for us to score and rank the candidate songs.
The other factor we used was song occurrence frequency, which ensured that songs that appeared in multiple similar playlists would be considered as better recommendations. To implement this, we added the playlist similarity scores for each occurrence of a song to calculate the final score for each song. Then, the desired number of song recommendations in order of highest score was returned to the user. The model was trained using a 30-70 test-train split on 100 randomly selected playlists from the million playlists dataset. This choice of sample size was mainly due to the limitations in the computing power/time of our laptops.

Collaborative Filtering: Text

Model Performance

The number of neighbors that had the highest combined NDCG and R-precision scores was 23 neighbors; this gave an NDCG score of 0.139 and an R-precision score of 0.038.

Screen Shot 2019-12-11 at 01.09.38.png
Collaborative Filtering: Text
Screen Shot 2019-12-11 at 01.09.30.png
Collaborative Filtering: Image

EXAMPLE PLAYLIST RECOMMENDATIONS

STARTING PLAYLIST

'Aftergold', "Ain't My Fault - R3hab Remix", 'Candyman', 'Casanova (feat. Skizzy Mars & G Eazy)', 'Cold Water (feat. Justin Bieber & MØ)', "Don't Let Me Down", 'Gone', 'History', 'I Love It (feat. Charli XCX) - Cobra Starship Remix Radio Edit', 'Into You', 'Let Me Love You', 'No Problem (feat. Lil Wayne & 2 Chainz)', 'Once In a While', 'Say It', 'Sober', 'Talk', 'That Love', 'Weekend'

PREDICTED SONGS

'CAN\'T STOP THE FEELING! (Original Song from DreamWorks Animation\'s "TROLLS")', 'Cheap Thrills', 'Closer', 'Controlla', 'Heathens', 'I Took A Pill In Ibiza - Seeb Remix', 'In the Name of Love', 'Never Be Like You', 'One Dance', 'Panda', 'Perfect Strangers', 'Ride', 'Sucker For Pain (with Wiz Khalifa, Imagine Dragons, Logic & Ty Dolla $ign feat. X Ambassadors)', 'This Is What You Came For', 'Treat You Better', "We Don't Talk Anymore (feat. Selena Gomez)", 'Work from Home', "You Don't Own Me"

ACTUAL FULL PLAYLIST

'All Night (feat. Knox Fortune)', 'CAN\'T STOP THE FEELING! (Original Song from DreamWorks Animation\'s "TROLLS")', 'Closer', "Don't Wanna Fall In Love", 'False Alarm', 'Fast Car', 'Final Song', 'Hello Friday (feat. Jason Derulo)', 'I Took A Pill In Ibiza - Seeb Remix', 'In the Name of Love', 'Kiss The Sky (feat. Wyclef Jean)', 'Make Me... (feat. G-Eazy)', 'Middle', 'Millionaire (feat. Nelly)', 'My House', 'Never Be Like You', 'Setting Fires - Boxinbox & Lionsize Remix', 'What Lovers Do (feat. SZA)'

Collaborative Filtering: List
bottom of page