Recommendation Systems: Notes and Interview Questions

What is Content-based Filtering?
Recommends items based on a user's purchase history, ratings and feedback. Eg: Flipkart.

What is Collaborative Filtering?
Matches customers who bought/watched similar items/movies to recommend products. Eg: Netflix.

How items are recommended in Content-based Filtering?
Let's take example of Netflix.
They save all the information related to each user in a vector form which contains the past behavior of the user (movies liked/disliked by the user and the ratings given by them). This vector is known as the profile vector. All the information related to movies is stored in item vector. Item vector contains the details of each movie, like genre, cast, director, etc. The content-based filtering algorithm finds the cosine of the angle between the profile vector and item vector, i.e. cosine similarity. Suppose A is the profile vector and B is the item vector, then the similarity between them can be calculated as:

Based on the cosine value (between -1 to 1), movies are arranged  in descending order and one of the two approaches is used for recommendations:
Top-n approach: where the top n movies are recommended.
Rating scale approach: Where a threshold is set and all the movies above that threshold are recommended.

Other methods to calculate similarity:
Euclidean Distance: Similar items will lie in close proximity to each other. Calculate the distance between items and based on that distance, recommend items to the user.
Pearson’s Correlation: It tells us how much two items are correlated. Higher the correlation, more will be the similarity.

Disadvantages of Content-based Filtering?
- Limited to recommending items that are of the same type.
- It will never recommend products which the user has not bought or liked in the past.

How items are recommended in Collaborative Filtering?

User based collaborative filtering

This algorithm first finds the similarity score between users. Based on this similarity score, it then picks out the most similar users and recommends products which these similar users have bought previously.

Item based collaborative filtering

ITEM-ITEM collaborative filtering look for items that are similar to the items that user has already rated and recommend most similar items.

What is Matrix Factorization?

If the matrix is mostly empty, reducing dimensions can improve the performance of the algorithm in terms of both space and time. We can use various methods like matrix factorization or autoencoders to do this.
Matrix factorization method is used to reduce the features in the data by reducing the dimensions from N to K where (K<N). Matrix factorization can be seen as breaking down a large matrix into a product of smaller ones. Matrix A with dimensions m x n can be reduced to a product of two matrices X and Y with dimensions m x p and p x n respectively. 

A(mxn) = X(mxp) Y(pxn)

The reduced matrices actually represent the users and items individually. The m rows in the first matrix represent the m users, and the p columns tell you about the features/latent factors of the users. The same goes for the item matrix with n items and p features.
For user vector (u,v) -> u: how much a user likes Horror, v: likes Romance
For item vector (i,j) -> i: how much movie belongs to Horror, j: belongs to Romance

Popular algorithms to factorize a matrix is SVD, PCA, NMF, etc.

How do we find the right factorization for a matrix?

The model learns to find latent factors to factorize the rating matrix. To arrive at the best approximation of the factors, RMSE is the cost function to be minimized. After MF is done, squared error is calculated for every movie rating in the rating matrix and RMSE are minimized. In order to minimize RMSE to learn the factors, Gradient Descent and Alternating Least Squares are the two most used techniques.

How to use Matrix Factorization for Recommendation?

In real-life scenarios, every user wouldn’t have seen all possible movies. So the rating matrix will look more empty - Sparse Matrix. In this case, the model still learns to factorize the sparse matrix, but RMSE will be calculated only for the ratings that are actually present in the matrix. After obtaining the best factors to approximate the ratings we have, we then perform dot product of the factor matrices to fill in the missing entries in the rating matrix. These filled in ratings are then used to provide recommendations to the users.

Evaluation metrics for recommendation engines.

MAE, RMSE, Recall@k and Precision@k, Average Precision, Mean Average Precision.

**All questions and notes have been compiled from various sources.

Comments

Popular posts from this blog

Linear Regression: Notes and Interview Questions

Logistic Regression: Notes and Interview Questions