Revolutionize Your Music Experience: Building A Spotify Recommendation App

Keegan Fernandes
3 min readJul 9, 2023
Photo by Omid Armin on Unsplash

Introduction

So I decided to build a Spotify recommendation app. Why? While scrolling through my recommended playlist. I realized that the algorithm assumes that we like a particular genre and artist and groups us into these clusters, not letting us discover and experience new music.

I wanted an app that would let me choose certain qualities of the music while completely randomizing the selection of the song. So I decided to make an app based on the Moodify Dataset, which extracted features of themes such as danceability, energy etc, of a piece. And classifies them into happy, sad etc.

For the purpose of the explanation, I won’t go into the detail of the code. However, You can find the github link and the Kaggle Notebook below:

Building the Notebook and Flask App

I began by visualizing the app data and feature engineering.

I removed features that would lead to data leakage and were irrelevant to the problem. I then scaled the data to build the minimum viable product (MVP). I went through a rapid training and testing phase.
After scaling the data, I used the XGBoost algorithm to train the model to classify the data and joblib to save the model.

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaled_data = scaler.fit_trapynsform(df[list(selected_cols)])
from sklearn.model_selection import train_test_split
X_train,x_test, Y_train,y_test = train_test_split(scaled_data,df[list(label)] , random_state = 42,test_size = 0.3 )
import xgboost as xgb
from xgboost import XGBClassifier
xgc = XGBClassifier()
xgc.fit(X_train,Y_train)
xgc.score(x_test,y_test)

0.9658199611426926

The Flask App

I then designed a python flask app and an edited template to build the model’s front end. I then posted it on github built the app on Azure web pages.

It gives us this final result:

Conclusion

The app definitely isn’t perfect. In fact, It’s probably worse than the existing Spotify algorithm, but it can build the groundwork for other such apps and help create a better Spotify algorithm. You can check a live demo of the app using the link below:

BECOME a WRITER at MLearning.ai // invisible ML // 800+ AI tools

--

--

Keegan Fernandes

First year student in Msc Data Science. Writes about data science and machine learning tutorials and the impact it has on the world.