Hello All... This blog is about my current project work. Here I will discuss how I am filtering songs based on user data.
I am using TensorFlow in python for the recommendation.
The following data is for the music - (danceability, energy, popularity), has been collected from Spotify. Same data for the user has been created.
Screenshot of database
The logic for the recommendation:
Consider a matrix = { danceability, energy, popularity}
Now we have a matrix of user data and song data. Now we will find the percentage difference of the song data from the user data. The least different song will be the most recommended. This a kind of supervised learning model I am working on
The logic for the music score :
Step 1:
Divide song data by user data -> will give you the percentage of the song data w.r.t user data
Example
user data energy level be 0.8
song data energy level be 0.72
0.72/0.80=0.9 ->90% i.e.. there is 10% difference in both
Step 2:
After division the resultant value will be x% example: 90% , 100% ,120%
If x% ==100% -> 100 % match 0% diiference
x% ==90% -> 90 % match 10% diiference
x% ==120% -> 80% match 20% diiference
So we subtract 100% from x% and get the absolute value
Step 3:
Then will add the resulting x% for all the three { danceability, energy, popularity}
For the Best Case :
There will be Zero difference and the resulting sum will be Zero, therefore The least different song will be the most recommended.
def get_song_score(user:list,song:list):# check before for non zero value
user_data=tf.constant(user,dtype=tf.float64)
song_data=tf.constant(song,dtype=tf.float64)
percentage_div=tf.divide(song_data,user_data)#find percentage difference
percentage_div=tf.subtract(percentage_div,1)# (-100 percent to make 0 if completely match)
percentage_div=tf.abs(percentage_div)# get abs value
sum=tf.reduce_sum(percentage_div).numpy()# add the three value
return sum
get_song_score() will be called for each music in the DataBase. The least score music will be the most recommended music for the user
Thank You.