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())
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)
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'])
In [4]:
print(error)