Lecture 16: Recommender Systems
An introduction to recommender systems, including content-based recommendation methods, collaborative filtering algorithms, low-rank matrix factorization, and mean normalization.
Recommender systems - introduction
Two motivations for talking about recommender systems
- Important application of ML systems
- Many technology companies find recommender systems to be absolutely key.
- Think about websites (Amazon, eBay, iTunes Genius):
- Try and recommend new content for you based on past purchases.
- Substantial part of Amazon's revenue generation.
- Improvement in recommender system performance can bring in more income.
- Kind of a funny problem:
- In academic learning, recommender systems receive a small amount of attention.
- But in industry, it's an absolutely crucial tool.
- Talk about the big ideas in machine learning
- Not so much a technique, but an idea.
- As seen, features are really important:
- There's a big idea in machine learning that for some problems you can learn what a good set of features are (so not select those features, but learn them).
- Recommender systems do this — try and identify the crucial and relevant features.
Example - predict movie ratings
- You're a company who sells movies:
- You let users rate movies using a 1–5 star rating (to make the example nicer, allow 0–5; makes math easier).
- You have five movies and four users.
- Admittedly, business isn't going well, but you're optimistic about the future as a result of your truly outstanding (if limited) inventory.

- To introduce some notation:
- — Number of users (called occasionally as we can't subscript in superscript)
- — Number of movies
- if user has rated movie (i.e. bitmap)
- — rating given by user to movie (defined only if )
- So for this example:
- Summary of scoring:
- Alice and Bob gave good ratings to rom coms, but low scores to action films.
- Carol and Dave gave good ratings for action films, but low ratings for rom coms.
- We have the data given above.
- The problem is as follows:
- Given and , go through and try and predict missing values (
?s). - Come up with a learning algorithm that can fill in these missing values.
- Given and , go through and try and predict missing values (
Content based recommendation
Using our example above, how do we predict?
- For each movie we have a feature vector which measures the degree to which a movie is a romantic movie () or an action movie ().

- If we have features like these, each film can be represented by a feature vector.
- Add an extra feature (bias unit):
- So for each film we have a vector, which for film number 1 ("Love at Last") would be:

- We'll explain later how we derived these values, but for now just take it that we have a feature vector associated with movie :
- For movie 1:
- For movie 2:
- For movie 3:
- For movie 4:
- For movie 5:

- So here (number of features, not counting ).
- For each user , we can learn a parameter vector .
- Predict user 's rating for movie as:

-
Predicted rating = stars.
-
Detailed Example: User 1 (Alice)
- Suppose Alice has parameter vector .
- For Movie 3 ("Cute Puppies of Love"), .
- Predicted rating: stars.
- This fits with Alice's known preferences!
How do we learn ?
- To learn (parameter for user ):
- Create parameters which give values as close as those seen in the data when applied.
- Sum over all movies rated by user :

- Where is the number of movies rated by user .
- To make this a little bit clearer, you can get rid of the term (it's just a constant so shouldn't affect the optimal value):

- So to learn for a single user :

- To learn parameter vectors for all users ():

- Gradient Descent Update Rules
- In order to do the minimization, we use the following gradient descent updates:

-
For (bias term, no regularization):
-
For (with regularization):
-
We can define the error derivative term as:

- This algorithm is called content-based recommendation because we assume we have features available for our content (movies) that describe their features (e.g. romance, action).
Collaborative filtering - overview
- The collaborative filtering algorithm has a very interesting property — it does feature learning, i.e. it can learn what features to use by itself!

- So — let's change the problem and pretend we have a dataset where we don't know any of the features associated with the movies (i.e. and are unknown).
- BUT suppose we have collected parameters from our users:

-
(Alice likes romance)
-
(Bob likes romance)
-
(Carol likes action)
-
(Dave likes action)
-
Given these user parameters, can we infer the feature vector for movie ?
-
Consider Movie 1 ("Love at Last"):
- Alice and Bob gave it 5 stars.
- Carol and Dave gave it 0 stars.
- We want , , , .
- From this, we can infer , meaning Movie 1 is a strong romantic movie with zero action content!

Formalizing the collaborative filtering problem
- Given , we want to learn features for movie :

- To learn all features :
How does this work with the previous recommendation system?
- Content-based recommendation systems:
- Given movie features , we can learn user parameters .
- Feature learning (given parameters):
- Given user parameters , we can learn movie features .
- This is a chicken-and-egg problem:
- Which comes first, or ?
- We can actually iterate back and forth!
- Randomly initialize Learn Learn Learn
- This converges to a good set of features and parameters!
Collaborative filtering Algorithm
- Here we combine both ideas into a single joint optimization objective to solve for and simultaneously.


- We can write a single joint cost function :

Understanding this optimization objective
- The squared error term sums over all pairs for which (all user-movie pairs with ratings).

- Notice that in collaborative filtering, we eliminate the bias term and . Thus and . If the algorithm needs a constant feature, it can learn automatically!
Algorithm Structure
- Initialize and to small random values (similar to neural network weight initialization; breaks symmetry).
- Minimize using gradient descent (or advanced optimization algorithms like Conjugate Gradient, L-BFGS):


- For a user with parameters and a movie with learned features , predict rating as:
Vectorization: Low rank matrix factorization
- Now let's look at how to vectorize collaborative filtering calculations.

- Group all ratings into a rating matrix of dimension ( in our example):
- We can vectorize the predicted ratings matrix as:

- Define movie feature matrix :

- Define user parameter matrix :

-
Then the matrix of predicted ratings is given by:
-
This vectorized algorithm is also called Low Rank Matrix Factorization because is a low-rank matrix approximation of .
Recommending new movies to a user
- How can we find movies related to a movie ?
- For each movie , we learn a feature vector .
- If a user is looking at movie , how do we find a movie that is most similar to movie ?
- Find movie such that the distance is small!
Implementation detail: Mean Normalization
- Let's look at one final implementation detail to make the collaborative filtering algorithm work much better for users with no ratings.

- Problem Case: Consider user 5 ("Eve") who has not rated any movies.
- What does the algorithm predict for Eve?
- Let's look at Eve's parameter vector (for ):

- For Eve, for all movies .
- Thus, the first term in has no terms involving !
- The only term involving is the regularization term:

- The value of that minimizes this is .
- If , then for any movie , predicted rating is:
- We predict 0 stars for every movie for Eve! That is useless — we can't make any meaningful recommendations to her.
How does mean normalization work?
- Group all ratings into matrix (with a column of
?s for Eve):

- Compute average rating for each movie into vector :

- Subtract off the mean ratings from to get normalized matrix :

-
Now every movie has an average rating of 0 in the normalized matrix.
-
Train collaborative filtering on normalized matrix to learn and .
-
For user and movie , predict rating as:
-
For user 5 (Eve), (since no ratings):

-
Now, for a user who has rated no movies, we predict the average rating for movie ! This is logical and provides a reasonable baseline for recommendations.
-
Summary / Aside:
- Mean normalization allows the system to handle new users with zero ratings gracefully by predicting average item ratings.
- (Similarly, column-wise normalization can handle brand new unrated movies, though usually unrated movies shouldn't be recommended until evaluated).
Lecture 15: Anomaly Detection
Learn about anomaly detection algorithms, Gaussian distribution modeling, evaluation metrics, feature engineering, and multivariate Gaussian distributions for detecting outliers.
Lecture 17: Large Scale Machine Learning
An in-depth guide to scaling machine learning algorithms for large datasets using Stochastic Gradient Descent, Mini-Batch Gradient Descent, Online Learning, and MapReduce.