FunkSVD Recommender example

Let's load the modules and data first


In [1]:
from reco.recommender import FunkSVD
from reco.datasets import loadMovieLens100k
from reco.metrics import rmse

import warnings
warnings.filterwarnings('ignore')

# load the movielens data, we can only use the userid, itemid and rating information in SVD, so we don't need all the columns.
train, test, _, _ = loadMovieLens100k(train_test_split=True)

print(train.head())


   userId  itemId  rating
0       1       1       5
1       1       2       3
2       1       3       4
3       1       4       3
4       1       5       3

Now let's train the model with the train data


In [2]:
f = FunkSVD(k=64, learning_rate=0.006, regularizer = 0.2, iterations = 5, method = 'stochastic', bias=True)
f.fit(X=train, formatizer={'user':'userId', 'item':'itemId', 'value':'rating'},verbose=True)


Epoch 0: Error: 0.8441571398213386
Epoch 1: Error: 0.7822678932236562
Epoch 2: Error: 0.7654325442429628
Epoch 3: Error: 0.7573459516338433
Epoch 4: Error: 0.7524747980348503

Now let's use the trained model to predict ratings on the test set.


In [3]:
preds = f.predict(test, formatizer={'user':'userId', 'item':'itemId'})
error = rmse(preds, test['rating'])


time taken 0.024410398688348593 secs

In [4]:
print(error)


0.9749679006002432