A simple recommender system
Here is an item-to-item version in which the utility matrix is Boolean: .
Recommender algorithm 1 is as follows. Given an input list of (i, j) pairs, representing purchases of items yj bought by users xi:
Initialize the utility matrix (uij) with m rows and n columns, where m is the number of users and n is the number of items.
For each pair (i, j) in the input list, set uij = 1.
Initialize the similarity matrix (sjk) with n rows and n columns.
For each j = 1…n and each k = 1…n, set sjk = s(u, v), the cosine similarity of the jth column u and the kth column v of the utility matrix.
For a given user-purchase pair (i, j) (that is, uij = 1):
Find the set S of items not bought by user i
Sort the items in S according to how similar they are to item j
Recommend the top n1 elements of S, where n1 is a specified constant much less than n.
To implement this algorithm, we need an input list of purchases. The program in Listing 9.2 generates a random list of pairs, where the pair...