Matrix factorization for recommender systems
In this section, we will go over traditional techniques for recommending systems. As we will see, these techniques are really easy to implement in TensorFlow, and the resulting code is very flexible and easily allows modifications and improvements.
For this section, we will use the Online Retail Dataset. We first define the problem we want to solve and establish a few baselines. Then we implement the classical Matrix factorization algorithm as well as its modification based on Bayesian Personalized Ranking.
Dataset preparation and baseline
Now we are ready to start building a recommender system.
First, declare the imports:
import tensorflow as tf import pandas as pd import numpy as np import scipy.sparse as sp from tqdm import tqdm
Let us read the dataset:
df = pd.read_excel('Online Retail.xlsx')
Reading xlsx
files may take a while. To save time when we next want to read the file, we can save the loaded copy into a pickle
file:
import pickle with open...