In [1]:
import graphlab
In [2]:
song_data = graphlab.SFrame('song_data.gl/')
In [3]:
song_data.head()
Out[3]:
In [4]:
graphlab.canvas.set_target('ipynb')
In [5]:
song_data['song'].show()
In [6]:
len(song_data)
Out[6]:
In [7]:
users = song_data['user_id'].unique()
In [8]:
len(users)
Out[8]:
In [9]:
users.head()
Out[9]:
In [10]:
train_data, test_data = song_data.random_split(0.8, seed = 0)
In [11]:
popularity_mode = graphlab.popularity_recommender.create(train_data,
user_id='user_id',
item_id='song')
In [12]:
# use popularity model to make predictions
In [13]:
popularity_mode.recommend(users=[users[0]])
Out[13]:
In [14]:
popularity_mode.recommend(users=[users[1]])
Out[14]:
In [20]:
personalized_model = graphlab.item_similarity_recommender.create(train_data, user_id='user_id', item_id='song')
In [21]:
del personalized_mode
In [22]:
personalized_model.recommend(users=[users[0]])
Out[22]:
In [24]:
personalized_model.recommend(users=[users[1]])
Out[24]:
In [25]:
personalized_model.get_similar_items(['With Or Without You - U2'])
Out[25]:
In [26]:
personalized_model.get_similar_items(['Chan Chan (Live) - Buena Vista Social Club'])
Out[26]:
In [28]:
%matplotlib inline
model_performance = graphlab.recommender.util.compare_models(test_data,
[popularity_mode, personalized_model], \
user_sample=0.05)
In [29]:
song_data.head()
Out[29]:
In [51]:
cpListeners= song_data[song_data['artist'] == 'Coldplay']
In [32]:
kwListeners
Out[32]:
In [40]:
len(kwListeners['user_id'].unique())
Out[40]:
In [42]:
len(ffListeners['user_id'].unique())
Out[42]:
In [43]:
len(tsListeners['user_id'].unique())
Out[43]:
In [44]:
len(lgListeners['user_id'].unique())
Out[44]:
In [45]:
kwListeners['listen_count']
Out[45]:
In [46]:
sum(kwListeners['listen_count'])
Out[46]:
In [47]:
sum(ffListeners['listen_count'])
Out[47]:
In [48]:
sum(tsListeners['listen_count'])
Out[48]:
In [49]:
sum(lgListeners['listen_count'])
Out[49]:
In [52]:
sum(kleonListeners['listen_count'])
Out[52]:
In [53]:
kleonListeners
Out[53]:
In [54]:
sum(cpListeners['listen_count'])
Out[54]:
In [57]:
tccListeners= song_data[song_data['artist'] == 'The Cool Kids']
In [58]:
sum(wtListeners['listen_count'])
Out[58]:
In [59]:
sum(vuListeners['listen_count'])
Out[59]:
In [60]:
sum(kwListeners['listen_count'])
Out[60]:
In [61]:
sum(tccListeners['listen_count'])
Out[61]:
In [62]:
train_data, test_data = song_data.random_split(.8, seed=0)
In [63]:
personalized_model = graphlab.item_similarity_recommender.create(train_data, user_id='user_id', item_id='song')
In [64]:
testUsers = test_data['user_id'].unique()
In [65]:
len(testUsers)
Out[65]:
In [66]:
personalized_model.recommend(users=testUsers[:10000])
Out[66]:
In [67]:
personalized_model.recommend(users=testUsers[:10000-1])
Out[67]:
In [68]:
dir()
Out[68]:
In [70]:
len(kwListeners['user_id'].unique())
Out[70]:
In [71]:
len(ffListeners['user_id'].unique())
Out[71]:
In [72]:
len(tsListeners['user_id'].unique())
Out[72]:
In [73]:
len(lgListeners['user_id'].unique())
Out[73]:
In [74]:
sum(tsListeners['listen_count'])
Out[74]:
In [77]:
kleonListeners.head()
In [91]:
kleonListeners = song_data[song_data['artist'] == 'Kings Of Leon']
In [92]:
kleonListeners.head()
Out[92]:
In [80]:
sum(cpListeners['listen_count'])
Out[80]:
In [81]:
sum(lgListeners['listen_count'])
Out[81]:
In [82]:
sum(wtListeners['listen_count'])
Out[82]:
In [83]:
sum(vuListeners['listen_count'])
Out[83]:
In [84]:
sum(tccListeners['listen_count'])
Out[84]:
In [93]:
sum(kleonListeners['listen_count'])
Out[93]:
In [88]:
artists = song_data['artist'].unique()
In [89]:
len(artists)
Out[89]:
In [90]:
print artists
In [ ]: