Data is available at Download and save to your own directory

Latent factor model (Surprise)

Using the library's inbuilt data reader, extract tsv-formatted data

Standard latent-factor model

Inbuilt functions to split into training and test fractions

Fit the model and extract predictions

Estimate for a single (test) rating

MSE for model predictions (test set)

Bayesian Personalized Ranking (Implicit)

Full dataset of Goodreads fantasy reviews (fairly memory-hungry, could be replaced by something smaller)

Example from the dataset

Build a few utility data structures. Since we'll be converting the data to a sparse interaction matrix, the main structure here is to assign each user/item to an ID from 0 to nUsers/nItems.

Convert dataset to sparse matrix. Only storing positive feedback instances (i.e., rated items).

Bayesian Personalized Ranking model with 5 latent factors

Fit the model

Get recommendations for a particular user (the first one) and to get items related to (similar latent factors) to a particular item

Extract user and item factors

Latent factor model (Tensorflow)

Goodreads comic book data

Split into train and test sets

Mean rating, just for initialization

Gradient descent optimizer, could experiment with learning rate

Latent factor model tensorflow class

Initialize the model. Could experiment with number of factors and regularization rate.

Training step (for the batch-based model from Chapter 5)

Run 100 iterations (really 100 batches) of gradient descent

Prediction for a particular user/item pair

Bayesian personalized ranking (Tensorflow)

Batch-based version from Chapter 5

Run 100 batches of gradient descent

Prediction for a particular user/item pair. Note that this is an unnormalized score (which can be used for ranking)



Adapt the latent factor model above, simply deleting any terms associated with latent factors

Compute the MSEs for a model which always predicts the mean, versus one which involves bias terms


Performance of a complete latent factor model (using the latent factor model implementation in the examples above)

(probably needs a little more tuning in terms of number of latent factors, learning rate, etc.)


Experiment with rounding the predictions

Seems to result in worse performance. For a rough explanation, consider a random variable that takes a value of "1" half the time and "2" half the time; in terms of the MSE, always predicting 1.5 (and always incurring moderate errors) is preferable to always predicting either of 1 or 2 (and incurring a large error half the time).


Following the BPR code from examples above

AUC implementation