0% found this document useful (0 votes)
7 views19 pages

M04 Matrix Factorization

The document discusses collaborative filtering techniques, focusing on matrix factorization (MF) as a more effective method for discovering latent features in user-item interactions. It explains the basic idea of MF, where two matrices are derived to approximate a user-item rating matrix, and introduces stochastic gradient descent as a method to optimize the matrices. Additionally, it provides practical exercises and references for further learning on the topic.

Uploaded by

Fa Putra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views19 pages

M04 Matrix Factorization

The document discusses collaborative filtering techniques, focusing on matrix factorization (MF) as a more effective method for discovering latent features in user-item interactions. It explains the basic idea of MF, where two matrices are derived to approximate a user-item rating matrix, and introduces stochastic gradient descent as a method to optimize the matrices. Additionally, it provides practical exercises and references for further learning on the topic.

Uploaded by

Fa Putra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Collaborative Filtering (3)

Matrix Factorization

ZK Abdurahman Baizal
Collaborative Filtering Techniques
Introduction
• While user-based or item-based collaborative Filtering
methods are simple and intuitive, matrix factorization
techniques are usually more effective because they allow us to
discover the latent features underlying the interactions
between users and items
Number Factorization
• Assumes you have a number, let says 𝑧.
• Factorization scenario run on :
– select two other numbers (e.g. 𝑥 and 𝑦), and make sure when you
multiply both of them you will obtain equal value of 𝑧
• So the factorization can be written in the following formula
𝑧 =𝑥 ∗𝑦
Matrix Factorization (MF)
• Assumes you have a matrix, let says 𝑍.
• Almost similar to factorization, our matrix factorization (MF)
task can be defined as
– select two other matrices (e.g. 𝑋 and 𝑌), and
– make sure when you multiply both of them you will obtain
̅
approximately similar to 𝑍 (we will notate as 𝑍).
• So the matrix factorization can be written in the following
formula
𝑍̅ ≈ 𝑋 ∗ 𝑌
MF-Basic Idea
Given a group of users and a set of items

D1 D2 D3 D4
U1 5 3 - 1
U2 4 - - 1
U3 1 1 - 5
U4 1 - - 4
U5 0 1 5 4
MF-Basic Idea
• The intuition behind using matrix factorization to solve this
problem is that there should be some latent features that
determine how a user rates an item.
• For example, two users would give high ratings to a certain movie if they both
like the actors/actresses of the movie, or if the movie is an action movie,
which is a genre preferred by both users.
• If we can discover these latent features, we should be able to
predict a rating with respect to a certain user and a certain
item, because the features associated with the user should
match with the features associated with the item
MF-Basic Idea
• We have a set 𝑈 of users, and a set 𝐷 of items. Let 𝑅 of size
𝑈 × 𝐷 be the matrix that contains all the ratings that the
users have assigned to the items.
• Also, we assume that we would like to discover 𝑘 latent
features. Our task, then, is to find two matrices 𝑃 𝑘× 𝑈
and 𝑄 𝑘× 𝐷 such that their product approximates 𝑅(

𝑅( ≈ 𝑃! ×𝑄
each row of 𝑃 would represent the strength of the associations
between a user and the features

each row of 𝑄 would represent the strength of the associations


between a item and the features
MF-Basic Idea
Illustration in Movie Domain
MF With Stochastic Gradient Descent
• To get the prediction of a rating of an item 𝑑! by 𝑢" we can calculate
the dot product of the two vectors corresponding to 𝑑! and 𝑢"
$

̂ = 𝑝"# 𝑞! = 0 𝑝"$ 𝑞$!


𝑟"!
$%&
• Now, we have to find a way to obtain 𝑃 and 𝑄
• One way to approach this problem is the first initialize the two matrices
with some values, and then try to minimize this difference iteratively –
random values
• Such a method is called gradient descent, aiming at finding a local
minimum of the difference
MF With Stochastic Gradient Descent
• The difference usually called the error between the estimated
rating and the real rating, can be calculated by the following
equation for each user-item pair
' #
# #
𝑒!" = 𝑟!" − 𝑟!"
̂ = 𝑟!" − / 𝑝!$ 𝑞$"
$%&
• To minimize the error, we have to know in which direction we
have to modify the values of 𝑝!$ and 𝑞$"
MF With Stochastic Gradient Descent
• In other words, we need to know the gradient at the current
values, and therefore we differentiate the above equation with
respect to these two variables separately
MF With Stochastic Gradient Descent
• Having obtained the gradient, we can now
formulate the update rules for both 𝑝!$ and
𝑞$"

• 𝛼 is a constant whose value determines


the rate of approaching the minimum.
Usually we will choose a small value for 𝛼,
say 0.0002
MF in Python
MF in Python
MF in Python
Practice
1. Open source code of matrix Factorization
https://drive.google.com/file/d/1kgUfakMfGpz883Bl2y0MScS
zX1jqns0W/view?usp=sharing
Copy and paste the codes to your google colaboratory, and
run
Explain the steps in that codes, and explain your conclusion
Practice
2. Use the codes to input your arbitrary rating matrix and k, and
explain your conclusion
Reference
• Ricci, Francesco, Lior Rokach, and Bracha Shapira.
"Introduction to recommender systems handbook."
Recommender systems handbook. Springer, Boston, MA, 2011
• http://www.quuxlabs.com/blog/2010/09/matrix-factorization-
a-simple-tutorial-and-implementation-in-python/

You might also like