In [1]:
import graphlab

Load music data


In [2]:
song_data = graphlab.SFrame('song_data.gl/')


[INFO] This non-commercial license of GraphLab Create is assigned to akshay.narayan@u.nus.eduand will expire on September 26, 2016. For commercial licensing options, visit https://dato.com/buy/.

[INFO] Start server at: ipc:///tmp/graphlab_server-25016 - Server binary: /usr/local/lib/python2.7/dist-packages/graphlab/unity_server - Server log: /tmp/graphlab_server_1445932858.log
[INFO] GraphLab Server Version: 1.6.1

In [3]:
song_data.head()


Out[3]:
user_id song_id listen_count title artist
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOAKIMP12A8C130995 1 The Cove Jack Johnson
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOBBMDR12A8C13253B 2 Entre Dos Aguas Paco De Lucia
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOBXHDL12A81C204C0 1 Stronger Kanye West
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOBYHAJ12A6701BF1D 1 Constellations Jack Johnson
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SODACBL12A8C13C273 1 Learn To Fly Foo Fighters
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SODDNQT12A6D4F5F7E 5 Apuesta Por El Rock 'N'
Roll ...
Héroes del Silencio
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SODXRTY12AB0180F3B 1 Paper Gangsta Lady GaGa
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOFGUAY12AB017B0A8 1 Stacked Actors Foo Fighters
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOFRQTD12A81C233C0 1 Sehr kosmisch Harmonia
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOHQWYZ12A6D4FA701 1 Heaven's gonna burn your
eyes ...
Thievery Corporation
feat. Emiliana Torrini ...
song
The Cove - Jack Johnson
Entre Dos Aguas - Paco De
Lucia ...
Stronger - Kanye West
Constellations - Jack
Johnson ...
Learn To Fly - Foo
Fighters ...
Apuesta Por El Rock 'N'
Roll - Héroes del ...
Paper Gangsta - Lady GaGa
Stacked Actors - Foo
Fighters ...
Sehr kosmisch - Harmonia
Heaven's gonna burn your
eyes - Thievery ...
[10 rows x 6 columns]


In [4]:
graphlab.canvas.set_target('ipynb')

In [5]:
song_data['song'].show()



In [6]:
len(song_data)


Out[6]:
1116609

Count number of users


In [7]:
users = song_data['user_id'].unique()

In [8]:
len(users)


Out[8]:
66346

In [9]:
users.head()


Out[9]:
dtype: str
Rows: 10
['c66c10a9567f0d82ff31441a9fd5063e5cd9dfe8', '279292bb36dbfc7f505e36ebf038c81eb1d1d63e', 'c067c22072a17d33310d7223d7b79f819e48cf42', 'f6c596a519698c97f1591ad89f540d76f6a04f1a', '696787172dd3f5169dc94deef97e427cee86147d', '3a7111f4cdf3c5a85fd4053e3cc2333562e1e0cb', '31f6fd9d9936adb9f7d0f157fd960c0a676ccfd6', '532e98155cbfd1e1a474a28ed96e59e50f7c5baf', 'ee43b175ed753b2e2bce806c903d4661ad351a91', 'e372c27f6cb071518ae500589ae02c126954c148']

Create song recommender


In [10]:
train_data, test_data = song_data.random_split(0.8, seed = 0)

Simple popularity based recommender


In [11]:
popularity_mode = graphlab.popularity_recommender.create(train_data,
                                                        user_id='user_id',
                                                        item_id='song')


PROGRESS: Recsys training: model = popularity
PROGRESS: Warning: Ignoring columns song_id, listen_count, title, artist;
PROGRESS:     To use one of these as a target column, set target = <column_name>
PROGRESS:     and use a method that allows the use of a target.
PROGRESS: Preparing data set.
PROGRESS:     Data has 893580 observations with 66085 users and 9952 items.
PROGRESS:     Data prepared in: 1.28225s
PROGRESS: 893580 observations to process; with 9952 unique items.

In [12]:
# use popularity model to make predictions

In [13]:
popularity_mode.recommend(users=[users[0]])


Out[13]:
user_id song score rank
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Sehr kosmisch - Harmonia 4754.0 1
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Undo - Björk 4227.0 2
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
You're The One - Dwight
Yoakam ...
3781.0 3
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Dog Days Are Over (Radio
Edit) - Florence + The ...
3633.0 4
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Revelry - Kings Of Leon 3527.0 5
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Horn Concerto No. 4 in E
flat K495: II. Romance ...
3161.0 6
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Secrets - OneRepublic 3148.0 7
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Fireflies - Charttraxx
Karaoke ...
2532.0 8
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Tive Sim - Cartola 2521.0 9
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Drop The World - Lil
Wayne / Eminem ...
2053.0 10
[10 rows x 4 columns]


In [14]:
popularity_mode.recommend(users=[users[1]])


Out[14]:
user_id song score rank
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Sehr kosmisch - Harmonia 4754.0 1
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Undo - Björk 4227.0 2
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
You're The One - Dwight
Yoakam ...
3781.0 3
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Dog Days Are Over (Radio
Edit) - Florence + The ...
3633.0 4
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Revelry - Kings Of Leon 3527.0 5
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Horn Concerto No. 4 in E
flat K495: II. Romance ...
3161.0 6
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Secrets - OneRepublic 3148.0 7
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Hey_ Soul Sister - Train 2538.0 8
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Fireflies - Charttraxx
Karaoke ...
2532.0 9
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Tive Sim - Cartola 2521.0 10
[10 rows x 4 columns]

Build recommender with personalization


In [20]:
personalized_model = graphlab.item_similarity_recommender.create(train_data, user_id='user_id', item_id='song')


PROGRESS: Recsys training: model = item_similarity
PROGRESS: Warning: Ignoring columns song_id, listen_count, title, artist;
PROGRESS:     To use one of these as a target column, set target = <column_name>
PROGRESS:     and use a method that allows the use of a target.
PROGRESS: Preparing data set.
PROGRESS:     Data has 893580 observations with 66085 users and 9952 items.
PROGRESS:     Data prepared in: 0.949743s
PROGRESS: Computing item similarity statistics:
PROGRESS: Computing most similar items for 9952 items:
PROGRESS: +-----------------+-----------------+
PROGRESS: | Number of items | Elapsed Time    |
PROGRESS: +-----------------+-----------------+
PROGRESS: | 1000            | 0.50985         |
PROGRESS: | 2000            | 0.558927        |
PROGRESS: | 3000            | 0.60756         |
PROGRESS: | 4000            | 0.656676        |
PROGRESS: | 5000            | 0.703706        |
PROGRESS: | 6000            | 0.750407        |
PROGRESS: | 7000            | 0.796623        |
PROGRESS: | 8000            | 0.842149        |
PROGRESS: | 9000            | 0.894828        |
PROGRESS: +-----------------+-----------------+
PROGRESS: Finished training in 1.11008s

In [21]:
del personalized_mode

In [22]:
personalized_model.recommend(users=[users[0]])


Out[22]:
user_id song score rank
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Cuando Pase El Temblor -
Soda Stereo ...
0.0194504525792 1
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Fireflies - Charttraxx
Karaoke ...
0.0144929970884 2
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Love Is A Losing Game -
Amy Winehouse ...
0.0143118613046 3
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Marry Me - Train 0.0141749911143 4
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Secrets - OneRepublic 0.0136187790382 5
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Sehr kosmisch - Harmonia 0.0134409838941 6
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
No Dejes Que... -
Caifanes ...
0.0134191754754 7
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Y solo se me ocurre
amarte (Unplugged) - ...
0.0133210385369 8
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Te Hacen Falta Vitaminas
- Soda Stereo ...
0.0129302853556 9
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
OMG - Usher featuring
will.i.am ...
0.0127998267634 10
[10 rows x 4 columns]


In [24]:
personalized_model.recommend(users=[users[1]])


Out[24]:
user_id song score rank
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Riot In Cell Block Number
Nine - Dr Feelgood ...
0.0375 1
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Sei Lá Mangueira -
Elizeth Cardoso ...
0.0331632653061 2
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
The Stallion - Ween 0.0322580645161 3
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Rain - Subhumans 0.0314716312057 4
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
West One (Shine On Me) -
The Ruts ...
0.0306772028826 5
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Back Against The Wall -
Cage The Elephant ...
0.0301204819277 6
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Life Less Frightening -
Rise Against ...
0.0284431137725 7
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
A Beggar On A Beach Of
Gold - Mike And The ...
0.0230024907156 8
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Audience Of One - Rise
Against ...
0.0193938442211 9
279292bb36dbfc7f505e36ebf
038c81eb1d1d63e ...
Blame It On The Boogie -
The Jacksons ...
0.0189873417722 10
[10 rows x 4 columns]


In [25]:
personalized_model.get_similar_items(['With Or Without You - U2'])


PROGRESS: Getting similar items completed in 0.001134
Out[25]:
song similar score rank
With Or Without You - U2 I Still Haven't Found
What I'm Looking For ...
0.0428571428571 1
With Or Without You - U2 Hold Me_ Thrill Me_ Kiss
Me_ Kill Me - U2 ...
0.033734939759 2
With Or Without You - U2 Window In The Skies - U2 0.0328358208955 3
With Or Without You - U2 Vertigo - U2 0.0300751879699 4
With Or Without You - U2 Sunday Bloody Sunday - U2 0.0271317829457 5
With Or Without You - U2 Bad - U2 0.0251798561151 6
With Or Without You - U2 A Day Without Me - U2 0.0237154150198 7
With Or Without You - U2 Another Time Another
Place - U2 ...
0.020325203252 8
With Or Without You - U2 Walk On - U2 0.020202020202 9
With Or Without You - U2 Get On Your Boots - U2 0.0196850393701 10
[10 rows x 4 columns]


In [26]:
personalized_model.get_similar_items(['Chan Chan (Live) - Buena Vista Social Club'])


PROGRESS: Getting similar items completed in 0.001122
Out[26]:
song similar score rank
Chan Chan (Live) - Buena
Vista Social Club ...
Murmullo - Buena Vista
Social Club ...
0.188118811881 1
Chan Chan (Live) - Buena
Vista Social Club ...
La Bayamesa - Buena Vista
Social Club ...
0.187192118227 2
Chan Chan (Live) - Buena
Vista Social Club ...
Amor de Loca Juventud -
Buena Vista Social Club ...
0.184834123223 3
Chan Chan (Live) - Buena
Vista Social Club ...
Diferente - Gotan Project 0.0214592274678 4
Chan Chan (Live) - Buena
Vista Social Club ...
Mistica - Orishas 0.0205761316872 5
Chan Chan (Live) - Buena
Vista Social Club ...
Hotel California - Gipsy
Kings ...
0.019305019305 6
Chan Chan (Live) - Buena
Vista Social Club ...
Nací Orishas - Orishas 0.0191570881226 7
Chan Chan (Live) - Buena
Vista Social Club ...
Le Moulin - Yann Tiersen 0.0187969924812 8
Chan Chan (Live) - Buena
Vista Social Club ...
Gitana - Willie Colon 0.0187969924812 9
Chan Chan (Live) - Buena
Vista Social Club ...
Criminal - Gotan Project 0.018779342723 10
[10 rows x 4 columns]

Quantitative comparison between the 2 models


In [28]:
%matplotlib inline
model_performance = graphlab.recommender.util.compare_models(test_data, 
                                                             [popularity_mode, personalized_model], \
                                                             user_sample=0.05)


compare_models: using 2931 users to estimate model performance
PROGRESS: Evaluate model M0
PROGRESS: recommendations finished on 1000/2931 queries. users per second: 14196.7
PROGRESS: recommendations finished on 2000/2931 queries. users per second: 16118.1

Precision and recall summary statistics by cutoff
[WARNING] Model trained without a target. Skipping RMSE computation.
+--------+-----------------+------------------+
| cutoff |  mean_precision |   mean_recall    |
+--------+-----------------+------------------+
|   1    | 0.0307062436029 | 0.00789820513464 |
|   2    | 0.0308768338451 | 0.0174905215335  |
|   3    | 0.0280905265552 |  0.024004939486  |
|   4    | 0.0261856021836 | 0.0289051910597  |
|   5    | 0.0232685090413 | 0.0319274815181  |
|   6    | 0.0220061412487 | 0.0362627875934  |
|   7    | 0.0211531900375 | 0.0399942498458  |
|   8    | 0.0197031729785 | 0.0420882142991  |
|   9    | 0.0187649266462 | 0.0451102339792  |
|   10   | 0.0179802115319 | 0.0479031753341  |
+--------+-----------------+------------------+
[10 rows x 3 columns]

PROGRESS: Evaluate model M1
PROGRESS: recommendations finished on 1000/2931 queries. users per second: 2177.57
PROGRESS: recommendations finished on 2000/2931 queries. users per second: 2238.46

Precision and recall summary statistics by cutoff
+--------+-----------------+-----------------+
| cutoff |  mean_precision |   mean_recall   |
+--------+-----------------+-----------------+
|   1    |  0.206073012624 | 0.0647629304999 |
|   2    |  0.172296144661 |  0.10201725139  |
|   3    |  0.147958603435 |  0.12731557555  |
|   4    |  0.131780962129 |  0.148380099468 |
|   5    |  0.119481405664 |  0.165306536123 |
|   6    |  0.109860116001 |  0.180497358606 |
|   7    |  0.101818004582 |  0.19467662015  |
|   8    | 0.0950614124872 |  0.206881758826 |
|   9    | 0.0887448349066 |  0.216388824603 |
|   10   | 0.0837598089389 |  0.225427610318 |
+--------+-----------------+-----------------+
[10 rows x 3 columns]
[WARNING] Model trained without a target. Skipping RMSE computation.


In [29]:
song_data.head()


Out[29]:
user_id song_id listen_count title artist
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOAKIMP12A8C130995 1 The Cove Jack Johnson
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOBBMDR12A8C13253B 2 Entre Dos Aguas Paco De Lucia
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOBXHDL12A81C204C0 1 Stronger Kanye West
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOBYHAJ12A6701BF1D 1 Constellations Jack Johnson
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SODACBL12A8C13C273 1 Learn To Fly Foo Fighters
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SODDNQT12A6D4F5F7E 5 Apuesta Por El Rock 'N'
Roll ...
Héroes del Silencio
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SODXRTY12AB0180F3B 1 Paper Gangsta Lady GaGa
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOFGUAY12AB017B0A8 1 Stacked Actors Foo Fighters
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOFRQTD12A81C233C0 1 Sehr kosmisch Harmonia
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOHQWYZ12A6D4FA701 1 Heaven's gonna burn your
eyes ...
Thievery Corporation
feat. Emiliana Torrini ...
song
The Cove - Jack Johnson
Entre Dos Aguas - Paco De
Lucia ...
Stronger - Kanye West
Constellations - Jack
Johnson ...
Learn To Fly - Foo
Fighters ...
Apuesta Por El Rock 'N'
Roll - Héroes del ...
Paper Gangsta - Lady GaGa
Stacked Actors - Foo
Fighters ...
Sehr kosmisch - Harmonia
Heaven's gonna burn your
eyes - Thievery ...
[10 rows x 6 columns]


In [51]:
cpListeners= song_data[song_data['artist'] == 'Coldplay']

In [32]:
kwListeners


Out[32]:
artist listen_count song song_id title
Kanye West 1 Graduation Day - Kanye
West ...
SOWZAHB12AF72A4B46 Graduation Day
Kanye West 1 Graduation Day - Kanye
West ...
SOWZAHB12AF72A4B46 Graduation Day
Kanye West 1 Through The Wire - Kanye
West ...
SOIBSWV12A6D4F6AB3 Through The Wire
Kanye West 1 We Don't Care - Kanye
West ...
SOFRVNS12A6701D924 We Don't Care
Kanye West 1 Say You Will - Kanye West SOYIUDO12AB01838F5 Say You Will
Kanye West 1 Through The Wire - Kanye
West ...
SOIBSWV12A6D4F6AB3 Through The Wire
Kanye West 3 Flashing Lights - Kanye
West ...
SOOLPFK12A58A7BDE3 Flashing Lights
Kanye West 1 Flashing Lights - Kanye
West ...
SOOLPFK12A58A7BDE3 Flashing Lights
Kanye West 1 Flashing Lights - Kanye
West ...
SOOLPFK12A58A7BDE3 Flashing Lights
Kanye West 8 Homecoming - Kanye West SOIYWPZ12A81C204EF Homecoming
user_id
b4c75391d49ce797c1af18468
f1aa3ae5943f9de ...
71c17371dff96abe86663a7dc
83e4334f3e4a67f ...
d042c8587bde6221a8a02f650
6805cb95288aba4 ...
4b9499ca6452ebefeb7fe57c5
92bc6f0ac38aa80 ...
acfe56f70a87e2df5e78c7500
183ad660ea187a4 ...
94be0c8807e72979251a0bfff
bef207963aefbf3 ...
a5dc0aed99b94b35ea941445d
62cd646c079d92b ...
7e2325a9e56525c2c373ed2ef
f8e9d80c212e38a ...
5806ce75f6d8340c11c320a2f
ed1ecf76fe5faf6 ...
41165837b569688f022d13179
4e61999ca4c3192 ...
[3775 rows x 6 columns]
Note: Only the head of the SFrame is printed.
You can use print_rows(num_rows=m, num_columns=n) to print more rows and columns.


In [40]:
len(kwListeners['user_id'].unique())


Out[40]:
2522

In [42]:
len(ffListeners['user_id'].unique())


Out[42]:
2055

In [43]:
len(tsListeners['user_id'].unique())


Out[43]:
3246

In [44]:
len(lgListeners['user_id'].unique())


Out[44]:
2928

In [45]:
kwListeners['listen_count']


Out[45]:
dtype: int
Rows: ?
[1, 1, 2, 2, 5, 2, 1, 1, 1, 2, 3, 1, 4, 1, 5, 3, 2, 2, 1, 7, 3, 1, 3, 2, 6, 4, 2, 2, 1, 1, 1, 1, 3, 1, 2, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 23, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1, 4, 1, 1, 1, 12, 14, 8, 13, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 10, 1, 1, 2, 1, 2, 1, ... ]

In [46]:
sum(kwListeners['listen_count'])


Out[46]:
9992

In [47]:
sum(ffListeners['listen_count'])


Out[47]:
9504

In [48]:
sum(tsListeners['listen_count'])


Out[48]:
19376

In [49]:
sum(lgListeners['listen_count'])


Out[49]:
12224

In [52]:
sum(kleonListeners['listen_count'])


Out[52]:
0

In [53]:
kleonListeners


Out[53]:
user_id song_id listen_count title artist song
[? rows x 6 columns]
Note: Only the head of the SFrame is printed. This SFrame is lazily evaluated.
You can use len(sf) to force materialization.


In [54]:
sum(cpListeners['listen_count'])


Out[54]:
35362

In [57]:
tccListeners= song_data[song_data['artist'] == 'The Cool Kids']

In [58]:
sum(wtListeners['listen_count'])


Out[58]:
14

In [59]:
sum(vuListeners['listen_count'])


Out[59]:
80

In [60]:
sum(kwListeners['listen_count'])


Out[60]:
9992

In [61]:
sum(tccListeners['listen_count'])


Out[61]:
73

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')


PROGRESS: Recsys training: model = item_similarity
PROGRESS: Warning: Ignoring columns song_id, listen_count, title, artist;
PROGRESS:     To use one of these as a target column, set target = <column_name>
PROGRESS:     and use a method that allows the use of a target.
PROGRESS: Preparing data set.
PROGRESS:     Data has 893580 observations with 66085 users and 9952 items.
PROGRESS:     Data prepared in: 0.939361s
PROGRESS: Computing item similarity statistics:
PROGRESS: Computing most similar items for 9952 items:
PROGRESS: +-----------------+-----------------+
PROGRESS: | Number of items | Elapsed Time    |
PROGRESS: +-----------------+-----------------+
PROGRESS: | 1000            | 0.484104        |
PROGRESS: | 2000            | 0.533371        |
PROGRESS: | 3000            | 0.583948        |
PROGRESS: | 4000            | 0.632983        |
PROGRESS: | 5000            | 0.681523        |
PROGRESS: | 6000            | 0.728324        |
PROGRESS: | 7000            | 0.775375        |
PROGRESS: | 8000            | 0.820616        |
PROGRESS: | 9000            | 0.869594        |
PROGRESS: +-----------------+-----------------+
PROGRESS: Finished training in 1.04935s

In [64]:
testUsers = test_data['user_id'].unique()

In [65]:
len(testUsers)


Out[65]:
58628

In [66]:
personalized_model.recommend(users=testUsers[:10000])


PROGRESS: recommendations finished on 1000/10000 queries. users per second: 2108.2
PROGRESS: recommendations finished on 2000/10000 queries. users per second: 2299.33
PROGRESS: recommendations finished on 3000/10000 queries. users per second: 2370.86
PROGRESS: recommendations finished on 4000/10000 queries. users per second: 2397.35
PROGRESS: recommendations finished on 5000/10000 queries. users per second: 2411.72
PROGRESS: recommendations finished on 6000/10000 queries. users per second: 2408.9
PROGRESS: recommendations finished on 7000/10000 queries. users per second: 2411.67
PROGRESS: recommendations finished on 8000/10000 queries. users per second: 2420.32
PROGRESS: recommendations finished on 9000/10000 queries. users per second: 2426.7
PROGRESS: recommendations finished on 10000/10000 queries. users per second: 2424.17
Out[66]:
user_id song score rank
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Cuando Pase El Temblor -
Soda Stereo ...
0.0194504525792 1
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Fireflies - Charttraxx
Karaoke ...
0.0145013892289 2
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Love Is A Losing Game -
Amy Winehouse ...
0.0142865986808 3
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Marry Me - Train 0.0141532454586 4
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Secrets - OneRepublic 0.0136141061467 5
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Sehr kosmisch - Harmonia 0.0134248221659 6
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
No Dejes Que... -
Caifanes ...
0.0134191754754 7
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Y solo se me ocurre
amarte (Unplugged) - ...
0.0133210385369 8
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Te Hacen Falta Vitaminas
- Soda Stereo ...
0.0129302853556 9
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
OMG - Usher featuring
will.i.am ...
0.0128079309607 10
[100000 rows x 4 columns]
Note: Only the head of the SFrame is printed.
You can use print_rows(num_rows=m, num_columns=n) to print more rows and columns.


In [67]:
personalized_model.recommend(users=testUsers[:10000-1])


PROGRESS: recommendations finished on 1000/9999 queries. users per second: 2213.89
PROGRESS: recommendations finished on 2000/9999 queries. users per second: 2342.39
PROGRESS: recommendations finished on 3000/9999 queries. users per second: 2385.08
PROGRESS: recommendations finished on 4000/9999 queries. users per second: 2403.25
PROGRESS: recommendations finished on 5000/9999 queries. users per second: 2420.3
PROGRESS: recommendations finished on 6000/9999 queries. users per second: 2415.79
PROGRESS: recommendations finished on 7000/9999 queries. users per second: 2410.1
PROGRESS: recommendations finished on 8000/9999 queries. users per second: 2417.98
PROGRESS: recommendations finished on 9000/9999 queries. users per second: 2419.98
Out[67]:
user_id song score rank
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Cuando Pase El Temblor -
Soda Stereo ...
0.0194504525792 1
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Fireflies - Charttraxx
Karaoke ...
0.0145013892289 2
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Love Is A Losing Game -
Amy Winehouse ...
0.0142865986808 3
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Marry Me - Train 0.0141532454586 4
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Secrets - OneRepublic 0.0136141061467 5
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Sehr kosmisch - Harmonia 0.0134248221659 6
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
No Dejes Que... -
Caifanes ...
0.0134191754754 7
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Y solo se me ocurre
amarte (Unplugged) - ...
0.0133210385369 8
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
Te Hacen Falta Vitaminas
- Soda Stereo ...
0.0129302853556 9
c66c10a9567f0d82ff31441a9
fd5063e5cd9dfe8 ...
OMG - Usher featuring
will.i.am ...
0.0128079309607 10
[99990 rows x 4 columns]
Note: Only the head of the SFrame is printed.
You can use print_rows(num_rows=m, num_columns=n) to print more rows and columns.


In [68]:
dir()


Out[68]:
['In',
 'Out',
 '_',
 '_13',
 '_14',
 '_18',
 '_19',
 '_22',
 '_24',
 '_25',
 '_26',
 '_29',
 '_3',
 '_32',
 '_33',
 '_40',
 '_42',
 '_43',
 '_44',
 '_45',
 '_46',
 '_47',
 '_48',
 '_49',
 '_52',
 '_53',
 '_54',
 '_58',
 '_59',
 '_6',
 '_60',
 '_61',
 '_65',
 '_66',
 '_67',
 '_8',
 '_9',
 '__',
 '___',
 '__builtin__',
 '__builtins__',
 '__doc__',
 '__name__',
 '__package__',
 '_dh',
 '_i',
 '_i1',
 '_i10',
 '_i11',
 '_i12',
 '_i13',
 '_i14',
 '_i15',
 '_i16',
 '_i17',
 '_i18',
 '_i19',
 '_i2',
 '_i20',
 '_i21',
 '_i22',
 '_i23',
 '_i24',
 '_i25',
 '_i26',
 '_i27',
 '_i28',
 '_i29',
 '_i3',
 '_i30',
 '_i31',
 '_i32',
 '_i33',
 '_i34',
 '_i35',
 '_i36',
 '_i37',
 '_i38',
 '_i39',
 '_i4',
 '_i40',
 '_i41',
 '_i42',
 '_i43',
 '_i44',
 '_i45',
 '_i46',
 '_i47',
 '_i48',
 '_i49',
 '_i5',
 '_i50',
 '_i51',
 '_i52',
 '_i53',
 '_i54',
 '_i55',
 '_i56',
 '_i57',
 '_i58',
 '_i59',
 '_i6',
 '_i60',
 '_i61',
 '_i62',
 '_i63',
 '_i64',
 '_i65',
 '_i66',
 '_i67',
 '_i68',
 '_i7',
 '_i8',
 '_i9',
 '_ih',
 '_ii',
 '_iii',
 '_oh',
 '_sh',
 'cpListeners',
 'exit',
 'ffListeners',
 'get_ipython',
 'graphlab',
 'kleonListeners',
 'kwListeners',
 'lgListeners',
 'model_performance',
 'personalized_model',
 'popularity_mode',
 'quit',
 'song_data',
 'tccListeners',
 'testUsers',
 'test_data',
 'train_data',
 'tsListeners',
 'users',
 'vuListeners',
 'wtListeners']

In [70]:
len(kwListeners['user_id'].unique())


Out[70]:
2522

In [71]:
len(ffListeners['user_id'].unique())


Out[71]:
2055

In [72]:
len(tsListeners['user_id'].unique())


Out[72]:
3246

In [73]:
len(lgListeners['user_id'].unique())


Out[73]:
2928

In [74]:
sum(tsListeners['listen_count'])


Out[74]:
19376

In [77]:
kleonListeners.head()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-77-5d93690a49b7> in <module>()
----> 1 kleonListeners.head()

AttributeError: 'dict' object has no attribute 'head'

In [91]:
kleonListeners = song_data[song_data['artist'] == 'Kings Of Leon']

In [92]:
kleonListeners.head()


Out[92]:
user_id song_id listen_count title artist
b80344d063b5ccb3212f76538
f3d9e43d87dca9e ...
SOWQLXP12AF72A08A2 1 Trani Kings Of Leon
e006b1a48f466bf59feefed32
bec6494495a4436 ...
SOSXLTC12AF72A7F54 2 Revelry Kings Of Leon
e006b1a48f466bf59feefed32
bec6494495a4436 ...
SOWCKVR12A8C142411 3 Use Somebody Kings Of Leon
0afaa5d9d04bf85af720fe8cc
566a41ca3e41c97 ...
SOSXLTC12AF72A7F54 11 Revelry Kings Of Leon
0afaa5d9d04bf85af720fe8cc
566a41ca3e41c97 ...
SOWCKVR12A8C142411 1 Use Somebody Kings Of Leon
2b6c2f33bc0e887ea7c4411f5
8106805a1923280 ...
SOSXLTC12AF72A7F54 7 Revelry Kings Of Leon
99d57b8925d3c30c534d2e651
cc029fcaaa86cce ...
SOWCKVR12A8C142411 1 Use Somebody Kings Of Leon
8cbb5066924ec788e3fea9a4a
ae59586f46f38fa ...
SOGFFET12A58A7ECA9 1 Molly's Chambers Kings Of Leon
8cbb5066924ec788e3fea9a4a
ae59586f46f38fa ...
SOGIDSA12A8C142829 1 Camaro Kings Of Leon
8cbb5066924ec788e3fea9a4a
ae59586f46f38fa ...
SOIGHWG12A8C136A37 1 Velvet Snow Kings Of Leon
song
Trani - Kings Of Leon
Revelry - Kings Of Leon
Use Somebody - Kings Of
Leon ...
Revelry - Kings Of Leon
Use Somebody - Kings Of
Leon ...
Revelry - Kings Of Leon
Use Somebody - Kings Of
Leon ...
Molly's Chambers - Kings
Of Leon ...
Camaro - Kings Of Leon
Velvet Snow - Kings Of
Leon ...
[10 rows x 6 columns]


In [80]:
sum(cpListeners['listen_count'])


Out[80]:
35362

In [81]:
sum(lgListeners['listen_count'])


Out[81]:
12224

In [82]:
sum(wtListeners['listen_count'])


Out[82]:
14

In [83]:
sum(vuListeners['listen_count'])


Out[83]:
80

In [84]:
sum(tccListeners['listen_count'])


Out[84]:
73

In [93]:
sum(kleonListeners['listen_count'])


Out[93]:
43218

In [88]:
artists = song_data['artist'].unique()

In [89]:
len(artists)


Out[89]:
3375

In [90]:
print artists


['The Dells', 'Lil Jon / The East Side Boyz', 'Tom Petty And The Heartbreakers', 'Blackstreet', 'Ratatat', 'Shotta', 'Airscape', 'Mecano', 'Moimir Papalescu & The Nihilists', 'Brad Paisley', '16Volt', 'Prohom', 'Gogol Bordello', 'The Stray Cats', 'Billy Preston / Syreeta', 'Emma Shapplin', 'Manu Chao', 'Lil Jon & The East Side Boyz / Ludacris / Usher', 'Trapt', 'George Younce', 'Rammstein', 'Caifanes', 'Everly Brothers', 'Spoon', 'Sam & Dave', 'Giannis Aggelakas', 'Blue Swede', 'Scooter', "The Men They Couldn't Hang", 'Serj Tankian', 'Fionn Regan', 'Crystal Gayle', 'Kid Rock', 'The Cat Empire', 'No Doubt / Bounty Killer', 'Jonathan Butler', 'Forever The Sickest Kids', 'Young Money / Shawt Dawg', 'Michael Nyman', 'Dido', 'Steps', 'MIMS', 'Rob De Nijs', 'Devotchka', 'Bayside', 'Randy Houser', 'All That Remains', 'Stevie Nicks / Tom Petty And The Heartbreakers', 'Secret Garden', 'DUNCAN SHEIK', 'DESTRUCTION', 'Streetlight Manifesto', 'No Doubt', 'Sugar Ray feat. Super Cat', 'Sugar Pie DeSanto', 'Neutral Milk Hotel', 'Bone Thugs-N-Harmony / Akon', 'The Subways', 'Custom Blue', 'Lady & Bird', 'Simon Patterson', 'Melendi', 'Eric Prydz', 'Sabrina Malheiros', 'Big Punisher featuring Joe', 'Wilson Pickett', 'Love', 'Faithless', 'Charlie Louvin', 'CCCP - Fedeli Alla Linea', 'Dakis', 'Mudvayne', "Kanye West / Consequence / Cam'Ron", 'Mondo Marcio', 'DHT Feat. Edmée', 'Demi Lovato/Joe Jonas', 'Gang Starr', 'Big Tymers / Tateeze / Boo And Gotti', 'Arctic Monkeys', 'Elizeth Cardoso', 'Noosa Head Feat. Marshall Jefferson', 'José González', 'John Legend featuring The Stephens Family', 'Fountains Of Wayne', 'Rosana', 'Cows', 'Aaliyah', 'Jim Jones & Ron Browz featuring Juelz Santana', 'Armin van Buuren feat. Nadia Ali', 'Joao Gilberto', 'Junip', 'Pohlmann.', 'Metronomy', 'Del Tha Funkee Homosapien', 'Gabriella Cilmi', 'Jodeci', 'Clara Hill', 'Richard Souther', 'Kanye West / T-Pain', 'Newsboys', ... ]

In [ ]: