Skip to content

michaelmoschitto/AISongRecommender

Repository files navigation

AISongRecommender

A neural net that uses mood and genre to recommend the perfect song.

Libraries

import pandas as pd
import numpy as np
import altair as alt
import matplotlib.pyplot as plt
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from spotipy.oauth2 import SpotifyClientCredentials
from sklearn.preprocessing import MinMaxScaler, LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from keras.utils import np_utils
from sklearn.model_selection import cross_val_score, KFold

Environment

This project uses a virtual Python environment (venv) to control which packages have been downloaded and standardize across multiple machines.

To activate Unix/Linux:
* cd /AISongRecommender
* source AISongRec/bin/activate

To activate windows:

  • cd \ AISongRecommender
  • .\powershellEnv\Scripts\

Data Collection

With limited datasets available, a large part of this project was creating our own training and testing sets. This was done using the Spotify Web API and wrapper library Spotipy. Our model was trained on a dataset aggregated from mood labeled playlists created by various Spotify users. The testing set is an aggregation of songs from multiple playlists from Michael's account.

All data engineering related code can be found in the SpotifyWrapper.py file.

Final training set: Alt text

Model

The Model is a Keras sequential classifier with 10 input features and 4 outputs (Happy, Sad, Calm, Energetic). It features two dense layers with relu and softmax activation functions and the Adam optimizer. When classifying all 4 moods the model ranged from ~74-76 % accuracy and an F1-Score of ~73%. We found this reasonable as the feeling that one song elicits is often subjective with only slight variation between Calm/Sad and Happy/Energetic. When predicting opposites such as Energetic/Sad it was much higher in with accuracies in the mid 90's.

Hear the Results

This part always brings the biggest smile to my face!! Its so cool being able to listen to music I like, generated by code I wrote. Screw accuracys, F-Scores, and MSE's... go listen!

Dr.AsCalmMix: https://open.spotify.com/playlist/2D95LpUtwJqVYN1NG4rM8S

Dr.AsEnergeticMix: https://open.spotify.com/playlist/37XoFkuajvPUsLZfidsFAP

Dr.AsHappyMix: https://open.spotify.com/playlist/5FsxoaKvSUZyl9noSlYlwx

Dr.AsSadMix: https://open.spotify.com/playlist/4J6O4ytzIfPzjCIgToiEkY

But if you must know this was our final output, a measure of how likely each song was to align with a certain mood. Alt text The model was able to do this at ~76% accuracy with an F1 of ~73%.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

About

A neural net for building Spotify playlists based on mood

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published