ryubsmile / spotify-song-recommender

Song Recommender
2 stars 1 forks source link

Recommendation Algorithm #22

Closed sophryu99 closed 3 years ago

sophryu99 commented 3 years ago

Content-based recommendation algorithm

Input Data format

recommend_songs([{'name': 'Butter', 'year': 2021},
                {'name': 'Permission to Dance', 'year': 2021},
                {'name': 'Dynamite', 'year': 2020}],  track_data)
sophryu99 commented 3 years ago

Features to train with

# Get Track info API
    track_id = models.IntegerField(default=0)
    artist_id = models.IntegerField(default=0)
    year = models.IntegerField(default=0)
    popularity = models.IntegerField(default=0)
    release_date = models.IntegerField(default=0)

    # Get audio_features API
    acousticness = models.FloatField(default=0)
    danceability = models.FloatField(default=0)
    duration_ms = models.FloatField(default=0)
    energy = models.FloatField(default=0)
    instrumentalness = models.FloatField(default=0)
    liveness = models.FloatField(default=0)
    loudness = models.FloatField(default=0)
    valence = models.FloatField(default=0)
    speechiness = models.FloatField(default=0)
    tempo = models.FloatField(default=0)
    key = models.IntegerField(default=0)
    mode = models.IntegerField(default=0)
sophryu99 commented 3 years ago

Training Metrics

from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.decomposition import PCA
sophryu99 commented 3 years ago

Basic idea of the recommendation algorithm

sophryu99 commented 3 years ago

1. Get the average vector of the audio features for each tracks

Cosine distance function for two vectors u and v

Screen Shot 2021-07-26 at 1 18 31 PM
# find the distance between two pairs of collections of points
from scipy.spatial.distance import cdist

2. Find the n-closest data points in the dataset to this average vector 3. Take these n-points and recommend the songs corresponding to them