/Recommender-System-Using-SGD

Use SGD algorithm to predict the rating given User Id, and Movie Id.

Primary LanguageJupyter Notebook

Recommender-System-Using-SGD

  • use SGD algorithm to predict the rating given User Id, and Movie Id.

    equation

  • $\mu$ : scalar mean rating
  • $b_i$ : scalar bias term for user $i$
  • $c_j$ : scalar bias term for movie $j$
  • $u_i$ : K-dimensional vector for user $i$
  • $v_j$ : K-dimensional vector for movie $j$

Formulate as a Graph Problem

  • We can construct a weighted undirect graph from a given pair of user and movie, and weight will be rating given to movie by user.
  • we can construct this matrix like $A[i][j]=r_{ij}$ here $i$ is user_id, $j$ is movie_id and $r_{ij}$ is rating given by user $i$ to the movie $j$

Implicit User Feautures and Movie Features using Matrix Factorization

We will Apply SVD decomposition on the Adjaceny matrix $A$ and get three matrices $U, \sum, V$ such that $U \times \sum \times V^T = A$,
if $A$ is of dimensions $N \times M$ then
$U$ is of $N \times k$,
$\sum$ is of $k \times k$ and
$V$ is $M \times k$ dimensions.

  • Matrix $U$ can be represented as matrix representation of users, where each row $u_{i}$ represents a k-dimensional vector for a user

  • Matrix $V$ can be represented as matrix representation of movies, where each row $v_{j}$ represents a k-dimensional vector for a movie.

Dertivative of Loss Function

equation

equation

Training Optimizer

for each epoch:
    for each pair of (user, movie):
        b_i =  b_i - learning_rate * dL/db_i
        c_j =  c_j - learning_rate * dL/dc_j
predict the ratings with formula

$\hat{y}_{ij} = \mu + b_i + c_j + \text{dot_product}(u_i , v_j) $

mse_plot