Collaborative filtering

Hi , I have this question about the cost function of the Collaborative filtering,
I would like to know how the cost function work , since we have a lot of different users and
that means a lot of different ratings and ( A lot of vectors of W) , so how is it even possible to minimize it, it seems complicated , we are summing all the predictions for all the different users minus the real ones !
if we had only one user that seems more reasonable !
thank you

Hi @Radouane_BEY_OMAR

The cost function of Collaborative filtering is simple like another cost function as you compute the prediction for user j of film of by writing w.x + b after that you minus the prediction from the real rate for same thing user j of film i and take the square of the subtraction after that if to make sure you predict the rate of films i that has already been rated by user j we made a matrix called r which if the the user j nor rate the film i the value of r = 0 so we didn’t want to compute predict the rate of this film i by user j …so after we compute square of( predictions minus real rate ) we multiply(it is element wise multiplication) it by r to remove any prediction for the user who hasn’t rate this film and doing sum over all films and users to value of the wrong prediction like this photo

regularization it is the same what we took before
Note the code is easy don’t worry about that but make sure you understand the concept


1 Like

Hello @Radouane_BEY_OMAR,

You said “if we had only one user that seems more reasonable”, then we can start with looking at Abdelrahman’s equation in this way (that equation AND the one below are equivalent):

J = J^{\text{user }0} + J^{\text{user 1}} + J^{\text{user }2} + ... + J^{\text{user }n_u}

So what we are doing is instead of minimizing the cost given just what user 1 is telling us, but all of them! We tune the NN’s parameters not just based on user 1, but all of them to make everybody as a whole happier.

Would this give you more feeling about what the cost function in that screenshot is doing?



yes that makes it more clear thank you !
sometimes I just want to understand things very deeply that’s why I get confused !
thank you so much !

You are welcome @Radouane_BEY_OMAR!