In [1]:
# chargement des données de playlist
import numpy as np
data = np.load("./music_2.npy")
len(data)
Out[1]:
100000
In [2]:
# récupération uniquement des identifiant de morceaux // suppression des identifiant d'artiste
playlist_track = [list(filter(lambda w: w.split("_")[0]==u"track",playlist)) for playlist in data]
In [3]:
# nombre de morceaux != ?
tracks = np.unique(np.concatenate(playlist_track))
Vt = len(tracks)
Vt
Out[3]:
338509
In [4]:
# nombre d'occurence de chaque morceaux ?
track_counts = dict((tracks[i],0) for i in range(0, Vt))
for p in playlist_track:
    for a in p:
        track_counts[a]=track_counts[a]+1;
In [5]:
# filtrage des morceaux très peu fréquents
playlist_track_filter = [list(filter(lambda a : track_counts[a]> 7, playlist)) for playlist in playlist_track]
track_f = np.unique(np.concatenate(playlist_track_filter))
Vt = len(track_f)
In [6]:
# construction d'un dict id_morceaux id [0,Vt]
track_dict = dict((track_f[i],i) for i in range(0, Vt))
# conversion des playlisat en liste d'entier
corpus_num_track = [[track_dict[track] for track in play ] for play in playlist_track_filter]
In [7]:
# import de Keras
from keras.models import Sequential, Model
from keras.layers import Embedding, Reshape, Activation, Input, Dense
from keras.layers.merge import Dot
from keras.utils import np_utils
from keras.preprocessing.sequence import skipgrams
Using TensorFlow backend.
In [8]:
# hyper-paramètres de word2vec :
# dimension de l'espace latent
vector_dim = 50
# taille de la fenêtre de voisinage
window_width = 5
# sur-échantillonage des exemples négatifs
neg_sample = 4.
# taille des mini-batch
min_batch_size = 50
# coeff pour la loi de tirage des exemple negatif
samp_coef = -0.1
In [9]:
# comptage du nombre d'occurences des morceaux dans les playlist filtrées
tracks_counts_f = dict((track_f[i],0) for i in range(0, Vt))
for p in playlist_track_filter:
    for t in p:
        tracks_counts_f[t]=tracks_counts_f[t]+1;
# construction de la table de tirage des morceaux pour les exmeple negatif en utilisant ces fréquences
spt_tracks=np.array(list(map(lambda a:tracks_counts_f[a],track_f)),np.float)
sptn_tracks=np.power(spt_tracks,samp_coef)
sptn_tracks=sptn_tracks/np.sum(sptn_tracks)
sptn_tracks=np.cumsum(np.sort(sptn_tracks)[::-1])
In [20]:
# construction du réseau word2vec

# entrée deux entier (couple de morceaux)
input_target_t = Input((1,), dtype='int32')
input_context_t = Input((1,), dtype='int32')

# définition de l'embeding
embedding_t_t = Embedding(Vt, vector_dim, input_length=1, name='embedding_t')
# projection du premier morceau
target_t = embedding_t_t(input_target_t)
target_t = Reshape((vector_dim, 1))(target_t)

# projection du second morceaux
context_t = embedding_t_t(input_context_t)
context_t = Reshape((vector_dim, 1))(context_t)

# calcul de la sortie
dot_product_t = Dot(axes=0)([target_t, context_t])
dot_product_t = Reshape((1,))(dot_product_t)
output_t = Dense(1, activation='sigmoid',name="classif")(dot_product_t)

# definition du modèle
SkipGram_t = Model(inputs=[input_target_t, input_context_t], outputs=output_t)
SkipGram_t.compile(loss='binary_crossentropy', optimizer='adam')
In [21]:
# définition du générateur de couple de morceaux (y=0 <-> aléatoire, y=1 <-> proche dans une playlist)
import random
def track_ns_generator(corpus_num,nbm):
    while 1:
        Data=[]
        Labels=[]
        for i, doc in enumerate(random.sample(corpus_num,nbm)):
            data, labels = skipgrams(sequence=doc, vocabulary_size=Vt, window_size=window_width, negative_samples=neg_sample,sampling_table=sptn_tracks)
            if (len(data)>0):
                Data.append(np.array(data, dtype=np.int32))
                Labels.append(np.array(labels, dtype=np.int32))
        Data=np.concatenate(Data)
        Labels=np.concatenate(Labels)
        x=[Data[:,0],Data[:,1]]
        y=Labels
        yield (x,y)
In [22]:
# ensemble de test et d'apprentissage
index_tst = np.random.choice(100000,10000)
index_app  = np.setdiff1d(range(100000),index_tst)

play_app   = [corpus_num_track[i] for i in index_app]
play_tst  = [corpus_num_track[i] for i in index_tst]
In [23]:
# apprentissage
hist=SkipGram_t.fit_generator(track_ns_generator(play_app,min_batch_size),200,50)
Epoch 1/50
200/200 [==============================] - 5s 26ms/step - loss: 0.6651
Epoch 2/50
200/200 [==============================] - 5s 23ms/step - loss: 0.6125
Epoch 3/50
200/200 [==============================] - 5s 23ms/step - loss: 0.5500
Epoch 4/50
200/200 [==============================] - 5s 23ms/step - loss: 0.5026
Epoch 5/50
200/200 [==============================] - 5s 23ms/step - loss: 0.4743
Epoch 6/50
200/200 [==============================] - 5s 24ms/step - loss: 0.4482
Epoch 7/50
200/200 [==============================] - 5s 23ms/step - loss: 0.4324
Epoch 8/50
200/200 [==============================] - 5s 23ms/step - loss: 0.4109
Epoch 9/50
200/200 [==============================] - 5s 23ms/step - loss: 0.3951: 0s - loss: 0.39
Epoch 10/50
200/200 [==============================] - 5s 24ms/step - loss: 0.3832
Epoch 11/50
200/200 [==============================] - 5s 24ms/step - loss: 0.3692
Epoch 12/50
200/200 [==============================] - 5s 23ms/step - loss: 0.3539
Epoch 13/50
200/200 [==============================] - 5s 23ms/step - loss: 0.3420
Epoch 14/50
200/200 [==============================] - 5s 23ms/step - loss: 0.3303
Epoch 15/50
200/200 [==============================] - 5s 24ms/step - loss: 0.3239
Epoch 16/50
200/200 [==============================] - 5s 23ms/step - loss: 0.3105
Epoch 17/50
200/200 [==============================] - 4s 22ms/step - loss: 0.3055
Epoch 18/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2996
Epoch 19/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2906
Epoch 20/50
200/200 [==============================] - 5s 25ms/step - loss: 0.2838
Epoch 21/50
200/200 [==============================] - 5s 24ms/step - loss: 0.2787
Epoch 22/50
200/200 [==============================] - 5s 24ms/step - loss: 0.2711
Epoch 23/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2707
Epoch 24/50
200/200 [==============================] - 5s 24ms/step - loss: 0.2678
Epoch 25/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2574
Epoch 26/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2558
Epoch 27/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2519
Epoch 28/50
200/200 [==============================] - 4s 22ms/step - loss: 0.2504
Epoch 29/50
200/200 [==============================] - 5s 24ms/step - loss: 0.2478
Epoch 30/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2434
Epoch 31/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2394
Epoch 32/50
200/200 [==============================] - 4s 22ms/step - loss: 0.2375
Epoch 33/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2354
Epoch 34/50
200/200 [==============================] - 4s 22ms/step - loss: 0.2361
Epoch 35/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2322
Epoch 36/50
200/200 [==============================] - 4s 22ms/step - loss: 0.2304
Epoch 37/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2288
Epoch 38/50
200/200 [==============================] - 5s 24ms/step - loss: 0.2255
Epoch 39/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2228
Epoch 40/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2183
Epoch 41/50
200/200 [==============================] - 5s 24ms/step - loss: 0.2199
Epoch 42/50
200/200 [==============================] - 5s 24ms/step - loss: 0.2189
Epoch 43/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2167
Epoch 44/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2155
Epoch 45/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2134
Epoch 46/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2174
Epoch 47/50
200/200 [==============================] - 5s 25ms/step - loss: 0.2112
Epoch 48/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2138
Epoch 49/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2067
Epoch 50/50
200/200 [==============================] - 5s 23ms/step - loss: 0.2055
In [24]:
# récupérations des positions des morceaux dans l'espace de projection
vectors_tracks = SkipGram_t.get_weights()[0]
In [25]:
from sklearn.metrics import pairwise_distances
In [220]:
# fonction retpournant les indices des s plus proches voisins des seeds dans la matrice X
# a vous de jouer avec pairwise_distances, np.min, np.argsort,...
def predict(seeds,s,X):
    V = X.shape[0]
    others = np.setdiff1d(range(V),seeds)
    D = pairwise_distances(X[seeds,:],X[others,:],'cosine')
    return others[np.argsort(np.min(D,0))[:s]]
In [221]:
# exemple pour 4 suggestions avec les 2 premiers morceaux en seeds 
pr=predict([0,1],4,vectors_tracks)
pr
Out[221]:
array([10131,  6334,     2,     5])
In [115]:
# estimation des performances
# hit@10
# nombre de bonne prediction
goodpred = []
# nombre de predictions faites
nbpred   = []
# pour chaque playlist
for p in play_tst:
    # si au moins deux chansons
    if (len(p)>1):
        # recuperations des seeds 5 premiers morceaux ou moins si la playlist contient moins de 5 morceaux
        seeds  = p[:np.min([5,len(p)-1])]
        # recuperations de la suite de la playlist que nous allons comparer à nos suggestions
        topred = p[np.min([5,len(p)-1]):]
        # construction des suggestions 10 suggestions par morceaux a predire
        prediction = predict_opt(seeds,10*len(topred),vectors_tracks,kdt)
        # comptage du nombre de morceaux présent dans nos suggestions
        goodpred.append(len(np.intersect1d(prediction,topred)))
        # stockage du nombre de predictions
        nbpred.append(len(topred))
# proportions de morceux présents dans nos suggestions
hitat10 = np.sum(goodpred)/np.sum(nbpred)
In [116]:
hitat10
Out[116]:
0.2011281061029524

A faire

  • faire quelque graphique sen particulier pour discuter le choix de n'avoir garder que les morceaux présents dans plus de sept playlists
  • coder la fonction predict permetant de trouver les morceaux les plus proches des seeds (dans un premier temps de manière simple en utilisant la fonction pairwise_dist de sklearn)
  • tester l'influence des différents type de distance sur les les performances en terme de hit@10
  • vous pourrez ensuite essayé d'optimiser cette recherche https://scikit-learn.org/stable/modules/neighbors.html
  • faites varier un hyper-paramètres sur une plage raisonable
  • faire un graphique de hit@10 en fonction des valeurs de l'hyperparamètre
  • faire de même avec un second
  • proposer des valeures finales pour les hyper-paramètres
  • joindre avec les meta-données, url des morceaux ....
  • exporter // faire le liens avec le front-end

Aide

In [209]:
# aide jointure
import pandas as pd
tr_meta=pd.read_csv("./Tracks.csv")
jdf = pd.DataFrame({"id":track_f,"index":range(Vt)})
jdf["deezer_id"]=jdf["id"].apply(lambda x: float(x.split("_")[1]))
In [210]:
trj_meta = tr_meta.merge(jdf, left_on="id",right_on="deezer_id")
trj_meta.set_index("index",inplace=True)
In [211]:
trj_meta
Out[211]:
Unnamed: 0 album artist available_countries bpm contributors disk_number duration error explicit_lyrics ... readable release_date share title title_short title_version track_position type id_y deezer_id
index
0 0 {u'title': u'Alone', u'type': u'album', u'rele... {u'picture': u'http://api.deezer.com/artist/79... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 116.0 [{u'picture': u'http://api.deezer.com/artist/7... 1.0 273.0 NaN False ... True 2015-05-25 https://www.deezer.com/track/100001884?utm_sou... Alone Alone NaN 1.0 track track_100001884 100001884.0
1 1 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 103.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 239.0 NaN False ... False 2015-05-15 https://www.deezer.com/track/100004586?utm_sou... It Was Always You It Was Always You NaN 3.0 track track_100004586 100004586.0
2 2 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 130.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 238.0 NaN False ... False 2015-05-15 https://www.deezer.com/track/100004588?utm_sou... Unkiss Me Unkiss Me NaN 4.0 track track_100004588 100004588.0
3 3 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 119.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 235.0 NaN True ... False 2015-05-15 https://www.deezer.com/track/100004590?utm_sou... Sugar Sugar NaN 5.0 track track_100004590 100004590.0
4 4 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 97.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 203.0 NaN False ... False 2015-05-15 https://www.deezer.com/track/100004592?utm_sou... Leaving California Leaving California NaN 6.0 track track_100004592 100004592.0
5 5 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 126.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 219.0 NaN True ... False 2015-05-15 https://www.deezer.com/track/100004594?utm_sou... In Your Pocket In Your Pocket NaN 7.0 track track_100004594 100004594.0
6 6 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 164.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 196.0 NaN True ... False 2015-05-15 https://www.deezer.com/track/100004596?utm_sou... New Love New Love NaN 8.0 track track_100004596 100004596.0
7 7 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 114.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 226.0 NaN False ... False 2015-05-15 https://www.deezer.com/track/100004598?utm_sou... Coming Back For You Coming Back For You NaN 9.0 track track_100004598 100004598.0
8 8 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 122.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 194.0 NaN True ... False 2015-05-15 https://www.deezer.com/track/100004600?utm_sou... Feelings Feelings NaN 10.0 track track_100004600 100004600.0
9 9 {u'title': u'V (Deluxe)', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 98.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 224.0 NaN True ... False 2015-05-15 https://www.deezer.com/track/100004604?utm_sou... This Summer This Summer NaN 12.0 track track_100004604 100004604.0
10 14 {u'title': u'Ain't Nobody (Loves Me Better) (R... {u'picture': u'http://api.deezer.com/artist/50... [AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, A... 118.0 [{u'picture': u'http://api.deezer.com/artist/5... 1.0 306.0 NaN False ... True 2015-05-14 https://www.deezer.com/track/100031896?utm_sou... Ain't Nobody (Loves Me Better) (Extended Mix) Ain't Nobody (Loves Me Better) (Extended Mix) 1.0 track track_100031896 100031896.0
11 18 {u'title': u'V', u'type': u'album', u'release_... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 126.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 219.0 NaN True ... True 2015-05-15 https://www.deezer.com/track/100052804?utm_sou... In Your Pocket In Your Pocket NaN 7.0 track track_100052804 100052804.0
12 19 {u'title': u'V', u'type': u'album', u'release_... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 164.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 196.0 NaN True ... True 2015-05-15 https://www.deezer.com/track/100052806?utm_sou... New Love New Love NaN 8.0 track track_100052806 100052806.0
13 21 {u'title': u'V', u'type': u'album', u'release_... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 122.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 194.0 NaN True ... True 2015-05-15 https://www.deezer.com/track/100052810?utm_sou... Feelings Feelings NaN 10.0 track track_100052810 100052810.0
14 22 {u'title': u'V', u'type': u'album', u'release_... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 101.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 236.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/100052812?utm_sou... My Heart Is Open My Heart Is Open NaN 11.0 track track_100052812 100052812.0
15 23 {u'title': u'V', u'type': u'album', u'release_... {u'picture': u'http://api.deezer.com/artist/11... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 98.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 224.0 NaN True ... True 2015-05-15 https://www.deezer.com/track/100052814?utm_sou... This Summer This Summer NaN 12.0 track track_100052814 100052814.0
16 24 {u'title': u'Policeman - EP', u'type': u'album... {u'picture': u'http://api.deezer.com/artist/27... [FR] 104.0 [{u'picture': u'http://api.deezer.com/artist/2... 1.0 194.0 NaN False ... True 2015-06-16 https://www.deezer.com/track/100061660?utm_sou... Policeman (Radio Edit) [feat. Konshens] Policeman (Radio Edit) [feat. Konshens] NaN 1.0 track track_100061660 100061660.0
17 25 {u'title': u'What Did You Expect from the Vacc... {u'picture': u'http://api.deezer.com/artist/81... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 165.0 [{u'picture': u'http://api.deezer.com/artist/8... 1.0 174.0 NaN False ... True 2011-03-11 https://www.deezer.com/track/10006346?utm_sour... If You Wanna If You Wanna NaN 2.0 track track_10006346 10006346.0
18 26 {u'title': u'Times', u'type': u'album', u'rele... {u'picture': u'http://api.deezer.com/artist/10... [BE, CH, FR] 114.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 250.0 NaN False ... True 2015-09-18 https://www.deezer.com/track/100063586?utm_sou... Just Need Your Love Just Need Your Love NaN 2.0 track track_100063586 100063586.0
19 27 {u'title': u'Everyday', u'type': u'album', u'r... {u'picture': u'http://api.deezer.com/artist/15... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 149.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 260.0 NaN True ... True 2015-05-08 https://www.deezer.com/track/100067510?utm_sou... Everyday Everyday NaN 1.0 track track_100067510 100067510.0
20 32 {u'title': u'Amanecer', u'type': u'album', u'r... {u'picture': u'http://api.deezer.com/artist/47... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 98.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 237.0 NaN False ... True 2015-06-02 https://www.deezer.com/track/100115952?utm_sou... Somos Dos Somos Dos NaN 3.0 track track_100115952 100115952.0
21 33 {u'title': u'Amanecer', u'type': u'album', u'r... {u'picture': u'http://api.deezer.com/artist/47... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 117.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 159.0 NaN False ... True 2015-06-02 https://www.deezer.com/track/100115954?utm_sou... Soy Yo Soy Yo NaN 4.0 track track_100115954 100115954.0
22 34 {u'title': u'Amanecer', u'type': u'album', u'r... {u'picture': u'http://api.deezer.com/artist/47... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 110.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 239.0 NaN False ... True 2015-06-02 https://www.deezer.com/track/100115964?utm_sou... To My Love To My Love NaN 9.0 track track_100115964 100115964.0
23 35 {u'title': u'Ao Vivo em São Paulo', u'type': u... {u'picture': u'http://api.deezer.com/artist/49... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 140.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 369.0 NaN False ... True 2014-09-23 https://www.deezer.com/track/100123358?utm_sou... Há um Lugar (Ao Vivo) Há um Lugar (Ao Vivo) 4.0 track track_100123358 100123358.0
24 36 {u'title': u'Ao Vivo em São Paulo', u'type': u... {u'picture': u'http://api.deezer.com/artist/49... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 137.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 405.0 NaN False ... True 2014-09-23 https://www.deezer.com/track/100123370?utm_sou... Jesus É o Caminho (Ao Vivo) Jesus É o Caminho (Ao Vivo) 10.0 track track_100123370 100123370.0
25 37 {u'title': u'Vem, Esta É a Hora (Ao Vivo)', u'... {u'picture': u'http://api.deezer.com/artist/53... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 187.0 [{u'picture': u'http://api.deezer.com/artist/5... 1.0 367.0 NaN False ... True 2015-03-23 https://www.deezer.com/track/100123390?utm_sou... Quebrantado (Ao Vivo) Quebrantado (Ao Vivo) 4.0 track track_100123390 100123390.0
26 38 {u'title': u'Vem, Esta É a Hora (Ao Vivo)', u'... {u'picture': u'http://api.deezer.com/artist/53... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 117.0 [{u'picture': u'http://api.deezer.com/artist/5... 1.0 378.0 NaN False ... True 2015-03-23 https://www.deezer.com/track/100123396?utm_sou... Meu Respirar (Ao Vivo) Meu Respirar (Ao Vivo) 7.0 track track_100123396 100123396.0
27 39 {u'title': u'Ao Vivo no Hangar', u'type': u'al... {u'picture': u'http://api.deezer.com/artist/47... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 107.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 248.0 NaN False ... True 2015-03-23 https://www.deezer.com/track/100123432?utm_sou... Tão Profundo (Ao Vivo) Tão Profundo (Ao Vivo) 13.0 track track_100123432 100123432.0
28 41 {u'title': u'Madame Libertánah', u'type': u'al... {u'picture': u'http://api.deezer.com/artist/45... [AG, AI, AL, AR, AT, AU, BA, BB, BE, BG, BO, B... 0.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 254.0 NaN False ... True 2015-05-20 https://www.deezer.com/track/100131318?utm_sou... Wayward Hearts Wayward Hearts NaN 7.0 track track_100131318 100131318.0
29 42 {u'title': u'Le prince de la ville', u'type': ... {u'picture': u'http://api.deezer.com/artist/13... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 97.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 178.0 NaN False ... True 2015-05-11 https://www.deezer.com/track/100217436?utm_sou... Le prince de la ville Le prince de la ville NaN 1.0 track track_100217436 100217436.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
22703 15204 {u'title': u'Bernstein Sibelius - The Symphoni... {u'picture': u'http://api.deezer.com/artist/26... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 155.0 [{u'picture': u'http://api.deezer.com/artist/2... 7.0 228.0 NaN False ... True 2015-06-05 https://www.deezer.com/track/99692844?utm_sour... I. Morning Mood I. Morning Mood NaN 1.0 track track_99692844 99692844.0
22704 15205 {u'title': u'Battlecry', u'type': u'album', u'... {u'picture': u'http://api.deezer.com/artist/39... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 119.0 [{u'picture': u'http://api.deezer.com/artist/3... 1.0 320.0 NaN False ... True 2015-04-28 https://www.deezer.com/track/99710032?utm_sour... Victory Victory NaN 3.0 track track_99710032 99710032.0
22705 15207 {u'title': u'Roses', u'type': u'album', u'rele... {u'picture': u'http://api.deezer.com/artist/41... [AE, AF, AG, AI, AL, AM, AO, AR, AU, AZ, BA, B... 99.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 226.0 NaN False ... True 2015-06-15 https://www.deezer.com/track/99756342?utm_sour... Roses Roses NaN 1.0 track track_99756342 99756342.0
22706 15209 {u'title': u'Perreología', u'type': u'album', ... {u'picture': u'http://api.deezer.com/artist/18... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 164.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 218.0 NaN False ... True 2011-03-21 https://www.deezer.com/track/9975792?utm_sourc... Camuflaje Camuflaje NaN 12.0 track track_9975792 9975792.0
22707 15214 {u'title': u'Dawn EP', u'type': u'album', u're... {u'picture': u'http://api.deezer.com/artist/70... [AE, AF, AG, AI, AL, AM, AO, AR, AT, AU, AZ, B... 119.0 [{u'picture': u'http://api.deezer.com/artist/7... 1.0 198.0 NaN False ... True 2015-07-17 https://www.deezer.com/track/99765778?utm_sour... How Hard I Try How Hard I Try NaN 2.0 track track_99765778 99765778.0
22708 15215 {u'title': u'Another You', u'type': u'album', ... {u'picture': u'http://api.deezer.com/artist/10... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 128.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 192.0 NaN False ... True 2015-05-08 https://www.deezer.com/track/99827630?utm_sour... Another You Another You NaN 1.0 track track_99827630 99827630.0
22709 15217 {u'title': u'Icon', u'type': u'album', u'relea... {u'picture': u'http://api.deezer.com/artist/28... [AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, A... 96.0 [{u'picture': u'http://api.deezer.com/artist/2... 1.0 246.0 NaN False ... True 2011-03-01 https://www.deezer.com/track/9990584?utm_sourc... Shoop Shoop NaN 8.0 track track_9990584 9990584.0
22710 15218 {u'title': u'Reality', u'type': u'album', u're... {u'picture': u'http://api.deezer.com/artist/58... [FR] 122.0 [{u'picture': u'http://api.deezer.com/artist/5... 1.0 158.0 NaN False ... True 2015-05-24 https://www.deezer.com/track/99925946?utm_sour... Reality (feat. Janieck Devy) Reality (feat. Janieck Devy) 1.0 track track_99925946 99925946.0
22711 15220 {u'title': u'Dead', u'type': u'album', u'relea... {u'picture': u'http://api.deezer.com/artist/19... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 82.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 210.0 NaN True ... True 2015-06-02 https://www.deezer.com/track/99938832?utm_sour... 4u 4u NaN 5.0 track track_99938832 99938832.0
22712 15221 {u'title': u'Room with view Ep', u'type': u'al... {u'picture': u'http://api.deezer.com/artist/14... [AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, A... 124.0 [{u'picture': u'http://api.deezer.com/artist/1... 1.0 371.0 NaN False ... True 2011-03-21 https://www.deezer.com/track/9995248?utm_sourc... Air France Air France NaN 1.0 track track_9995248 9995248.0
22713 15224 {u'title': u'Sheer Heart Attack (2011 Remaster... {u'picture': u'http://api.deezer.com/artist/41... [AE, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, A... 136.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 310.0 NaN False ... True 2011-03-14 https://www.deezer.com/track/9996977?utm_sourc... Brighton Rock (Remastered 2011) Brighton Rock (Remastered 2011) 1.0 track track_9996977 9996977.0
22714 15225 {u'title': u'A Night At The Opera (2011 Remast... {u'picture': u'http://api.deezer.com/artist/41... [AE, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, A... 147.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 219.0 NaN False ... True 2011-03-14 https://www.deezer.com/track/9997016?utm_sourc... Love Of My Life (Remastered 2011) Love Of My Life (Remastered 2011) 9.0 track track_9997016 9997016.0
22715 15226 {u'title': u'A Night At The Opera (2011 Remast... {u'picture': u'http://api.deezer.com/artist/41... [AE, AG, AI, AL, AM, AO, AQ, AR, AT, AU, AZ, B... 141.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 358.0 NaN False ... True 2011-03-14 https://www.deezer.com/track/9997018?utm_sourc... Bohemian Rhapsody (Remastered 2011) Bohemian Rhapsody (Remastered 2011) 11.0 track track_9997018 9997018.0
22716 15227 {u'title': u'A Night At The Opera (Deluxe Edit... {u'picture': u'http://api.deezer.com/artist/41... [AE, AG, AI, AL, AM, AO, AQ, AR, AT, AU, AZ, B... 141.0 [{u'picture': u'http://api.deezer.com/artist/4... 1.0 358.0 NaN False ... True 2011-03-14 https://www.deezer.com/track/9997030?utm_sourc... Bohemian Rhapsody (Remastered 2011) Bohemian Rhapsody (Remastered 2011) 11.0 track track_9997030 9997030.0
22717 15228 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 130.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 234.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976950?utm_sour... Heavydirtysoul Heavydirtysoul NaN 1.0 track track_99976950 99976950.0
22718 15229 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 170.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 202.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976952?utm_sour... Stressed Out Stressed Out NaN 2.0 track track_99976952 99976952.0
22719 15230 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 149.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 214.0 NaN False ... True 2015-05-12 https://www.deezer.com/track/99976954?utm_sour... Ride Ride NaN 3.0 track track_99976954 99976954.0
22720 15231 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 114.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 207.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976956?utm_sour... Fairly Local Fairly Local NaN 4.0 track track_99976956 99976956.0
22721 15232 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 119.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 188.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976958?utm_sour... Tear In My Heart Tear In My Heart NaN 5.0 track track_99976958 99976958.0
22722 15233 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 160.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 253.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976960?utm_sour... Lane Boy Lane Boy NaN 6.0 track track_99976960 99976960.0
22723 15234 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 164.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 297.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976962?utm_sour... The Judge The Judge NaN 7.0 track track_99976962 99976962.0
22724 15235 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 123.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 191.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976964?utm_sour... Doubt Doubt NaN 8.0 track track_99976964 99976964.0
22725 15236 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 82.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 226.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976966?utm_sour... Polarize Polarize NaN 9.0 track track_99976966 99976966.0
22726 15237 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 119.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 177.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976968?utm_sour... We Don't Believe What's On TV We Don't Believe What's On TV NaN 10.0 track track_99976968 99976968.0
22727 15238 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 119.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 240.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976970?utm_sour... Message Man Message Man NaN 11.0 track track_99976970 99976970.0
22728 15239 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 119.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 234.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976972?utm_sour... Hometown Hometown NaN 12.0 track track_99976972 99976972.0
22729 15240 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 114.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 238.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976974?utm_sour... Not Today Not Today NaN 13.0 track track_99976974 99976974.0
22730 15241 {u'title': u'Blurryface', u'type': u'album', u... {u'picture': u'http://api.deezer.com/artist/64... [AE, AG, AI, AL, AM, AO, AR, AT, AU, AZ, BA, B... 95.0 [{u'picture': u'http://api.deezer.com/artist/6... 1.0 236.0 NaN False ... True 2015-05-15 https://www.deezer.com/track/99976976?utm_sour... Goner Goner NaN 14.0 track track_99976976 99976976.0
22731 15242 {u'title': u'Nobody Has To Know (feat. Ty Doll... {u'picture': u'http://api.deezer.com/artist/56... [AG, AI, AL, AM, AR, AT, AU, AZ, BA, BB, BE, B... 170.0 [{u'picture': u'http://api.deezer.com/artist/5... 1.0 227.0 NaN True ... True 2015-05-19 https://www.deezer.com/track/99976980?utm_sour... Nobody Has To Know (feat. Ty Dolla $ign) Nobody Has To Know (feat. Ty Dolla $ign) NaN 1.0 track track_99976980 99976980.0
22732 15243 {u'title': u'Cherie Coco', u'type': u'album', ... {u'picture': u'http://api.deezer.com/artist/73... [AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, A... 128.0 [{u'picture': u'http://api.deezer.com/artist/7... 1.0 216.0 NaN False ... True 2011-02-25 https://www.deezer.com/track/9997935?utm_sourc... Chérie Coco (feat. Soprano) Chérie Coco (feat. Soprano) 1.0 track track_9997935 9997935.0

22731 rows × 26 columns

In [224]:
#aide predict_opt
#créer un kd-tree
from sklearn.neighbors import KDTree
kdt = KDTree(vectors_tracks, leaf_size=30, metric='euclidean')
#fonction de recherche a compléter
#vérifer la cohérences des résulats avec predict
def predict_opt(seeds,s,X,kdt):
     return 0
In [ ]:
# vérification de la cohérences des résultats des suggestion
In [217]:
trj_meta.sort_values(by=['rank'],ascending=False)["title"].head(20)
Out[217]:
index
6346                                     Shape of You
9152                  I Will Survive (Single Version)
7090                                      Look At Me!
20466    I Will Survive (Lalala), Original Radio Edit
11875                                           IDGAF
7215                                          Perfect
7131                         Something Just Like This
20170           Magic In The Air (feat. Ahmed Chawki)
7500                                        Despacito
6458                                            Faded
15120                                  Jocelyn Flores
11879                                       New Rules
3043                                        One Dance
13197                    De Trás Pra Frente (Ao Vivo)
14386        Meant to Be (feat. Florida Georgia Line)
12572                                       Me Rehúso
15126                                       Fuck Love
15122              Everybody Dies In Their Nightmares
11523                 Ar Condicionado no 15 (Ao Vivo)
5555                               That's What I Like
Name: title, dtype: object
In [222]:
# les voisins de i will survive ?
b=predict([9152],4,vectors_tracks)
trj_meta.loc[b,"title"]
Out[222]:
index
21843                              Hot Stuff
19030           YMCA (Original Version 1978)
16915                             Daddy Cool
19029    In the Navy (Original Version 1979)
Name: title, dtype: object
In [216]:
# un peu de musique
import IPython
IPython.display.Audio(trj_meta.loc[19030,"preview"])
Out[216]:
In [ ]: