Hit Song Prediction

Hit Song Prediction
Photo by Benny on Dribbble

Can you predict the success of a song, just by listening to it? I know! at least we try to do it many times, and a lot of times our predictions do turn out to be true. While we do consider many things and most importantly the emotions involved. Can we expect a deep learning model to predict that!?.

Of course! In this article, we will figure out how though.

IMPORTING LIBRARIES AND DATASET

We will start with importing the necessary libraries and the dataset. For my model, I am using the dataset containing 90’s songs, though I’ll link datasets for different periods. All these songs in these datasets are taken from Spotify.

After importing all the necessary stuff we will first check if our dataset is balanced or not. A balanced dataset is one that contains equal or near to equal value count for different classes of the prediction feature. Our dataset is already balanced!!

PREPROCESSING

Now, our dataset does contain some irrelevant features (which are not much of use to us for model building), hence we will drop “track”,” artist”,”uri”.

For further preprocessing, we will also scale our data. I am using sklearn’s preprocessing.scale for this purpose.

Now, we will be diving our dataset into train, validation, and test. I am also saving all three of them for an easy and smooth process.

MODEL

Now I’ll be moving onto the model, I have used a Sequential model.

The structure of our sequential model looks like this:

and for compilation of the model, I have used: optimizer =”adam”, loss =”binary_crossentropy”, and metrics = [“accuracy”].

You can refer to these two videos for a better understanding of loss and activation functions.

ANALYSIS

I have trained my model on 20 epochs, You can really, play around with this for better accuracy or even less loss. In my case, I got 86.14% training accuracy and 84.78% validation accuracy using above mentioned parameters. That’s pretty cool no!

After training and saving the model, it is a good practice to visualize the results of our model. I have attached the model accuracy and model loss graph you can have a look at.

LOSS
LOSS

ACCURACY
ACCURACY

PREDICTION

Now, it’s prediction time! For our case predicted value, 1 indicates a song will be a hit, hence 0 indicates otherwise. I have used a very basic logic in my code to print them as Hit and Not a Hit you can check that out too.

Finally, do not forget to evaluate the performance of your very own model.

DATASETS

https://www.kaggle.com/yamaerenay/spotify-dataset-19212020-160k-tracks

Platform: cAInvas

Code: Here

Author: Bhavyaa Sharma

Also Read: Road Crack Detection