9.5 Recommender Systems implementation | Mean normalization-- [Machine Learning| Andrew Ng]
 Back in the first course, you had seen how for linear regression, feature normalization can help the algorithm run faster. In the case of building and recommend a system with numbers y, such as movie ratings from 1 to 5 or 0 to 5 stars, it turns out your algorithm will run more efficiently and also perform a bit better if you first carry out mean normalization. That is if you normalize the movie ratings to have a consistent average value. Let's take a look at what that means. So here's the data set that we've been using and down below is the cost function you would use to learn the parameters for the model. In order to explain mean normalization, I'm actually going to add a fifth user, Eve, who has not yet rated any movies. So you see in a little bit that adding mean normalization will help the algorithm make better predictions on the user Eve. In fact, if you were to train a collaborative filtering algorithm on this data, then because we are trying to make the parameters w small because of this regularization term, if you were to run the algorithm on this data set, you actually end up with the parameters w for the fifth user, for the user Eve, to be equal to 0, 0, as well as quite likely b5 equals 0. Because Eve hasn't rated any movies yet, the parameters w and b don't affect this first term in the cost function because none of Eve's movies rating play a role in this squared error cost function. And so minimizing this means making the parameters w as small as possible. We didn't really regularize b, but if you initialize b to 0 as a default, you end up with b5 equals 0 as well. But if these are the parameters for user 5, that is for Eve, then what the algorithm will end up doing is predict that all of Eve's movies ratings would be w5.x for movie i plus b5, and this is equal to 0 if w and b above equal to 0. And so this algorithm would predict that if you have a new user that has not yet rated anything, we think they'll rate all movies with 0 stars, and that's not particularly helpful. So in this video, we'll see that mean normalization will help this algorithm come up with better predictions of the movie ratings for a new user that has not yet rated any movies. In order to describe mean normalization, let me take all of the values here, including all the question marks for Eve, and put them in a two dimensional matrix like this, just to write out all the ratings, including the question marks, in a more succinct or a more compact way. To carry out mean normalization, what we're going to do is take all of these ratings and for each movie, compute the average rating that was given. So movie 1 had two 5s and two 0s, and so the average rating is 2.5. Movie 2 had a 5 and a 0, so that averages out to 2.5. Movie 3, 4 and 0, averages out to 2. Movie 4 averages out to 2.25 rating, and movie 5, not that popular, has an average 1.25 rating. So I'm going to take all of these five numbers and gather them into a vector, which I'm going to call mu, because this is the vector of the average ratings that each of the movies had, averaging over just the users that did rate that particular movie. Instead of using these original 0 to 5 star ratings over here, I'm going to take this and subtract from every rating the mean rating that it was given. So for example, this movie rating was 5, I'm going to subtract 2.5, giving me 2.5 over here. This movie had a 0 star rating, going to subtract 2.25, giving me a negative 2.25 rating, and so on. So I'm going to take all of the now five users, including the new user Eve, as well as for all five movies. Then these new values on the right become your new values of yij. We're going to pretend that user 1 had given a 2.5 rating to movie 1 and a negative 2.25 rating to movie 4. And using this, you can then learn wj, bj and xi. Same as before, for user j on movie i, you would predict wj.xi plus bj. But because we had subtracted off mu i for movie i during this mean normalization step, in order to predict not a negative star rating, which isn't possible if a user rates from zero to five stars, we have to add back this mu i, which is just the value we had subtracted out. So as a concrete example, if we look at what happens with user 5, with the new user Eve, because she had not yet rated any movies, the algorithm might learn parameters w5 equals zero and say b5 equals zero. And so if we look at the predicted rating for movie 1, we will predict that Eve would rate it w5.x1 plus b5, but this is zero, and then plus mu 1, which is equal to 2.5. So this seems more reasonable to think Eve was likely to rate this movie 2.5 rather than think Eve will rate all movies zero stars just because she hasn't rated any movies yet. And in fact, the effect of this algorithm is it will cause the initial guesses for the new user Eve to be just equal to the mean of whatever other users have rated these five movies. And that seems more reasonable to take the average rating of the movies rather than to guess that all the ratings by Eve will be zero. It turns out that by normalizing the mean of the different movies ratings to be zero, the optimization algorithm for the recommended system will also run just a little bit faster. But it does make the algorithm behave much better for users that have rated no movies or very small numbers of movies and the predictions will become more reasonable. In this example, what we did was normalize each of the rows of this matrix to have zero mean and we saw this helps when there's a new user that hasn't rated a lot of movies yet. There's one other alternative that you could use, which is to instead normalize the columns of this matrix to have zero mean. And that would be a reasonable thing to do too. But I think in this application, normalizing the rows so that you can give reasonable ratings for a new user seems more important than normalizing the columns. Normalizing the columns would help if there was a brand new movie that no one has rated yet. But if there's a brand new movie that no one has rated yet, you probably shouldn't show that movie to too many users initially because you don't know that much about that movie. So normalizing columns to help with the case of a movie with no ratings seems less important to me than normalizing the rows to help with the case of a new user that's hardly rated any movies yet. And when you're building your own recommender system in this week's practice lab, normalizing just the rows should work fine. So that's mean normalization. It makes the algorithm run a little bit faster, but even more important, it makes the algorithm give much better, much more reasonable predictions when there are users that have rated very few movies or even no movies at all. This implementational detail of mean normalization will make your recommender system work much better. Next, let's go on to the next video to talk about how you can implement this for yourself in TensorFlow.
[{"start": 0.0, "end": 7.16, "text": " Back in the first course, you had seen how for linear regression, feature normalization"}, {"start": 7.16, "end": 9.9, "text": " can help the algorithm run faster."}, {"start": 9.9, "end": 15.96, "text": " In the case of building and recommend a system with numbers y, such as movie ratings from"}, {"start": 15.96, "end": 20.98, "text": " 1 to 5 or 0 to 5 stars, it turns out your algorithm will run more efficiently and also"}, {"start": 20.98, "end": 25.560000000000002, "text": " perform a bit better if you first carry out mean normalization."}, {"start": 25.56, "end": 31.2, "text": " That is if you normalize the movie ratings to have a consistent average value."}, {"start": 31.2, "end": 34.0, "text": " Let's take a look at what that means."}, {"start": 34.0, "end": 39.32, "text": " So here's the data set that we've been using and down below is the cost function you would"}, {"start": 39.32, "end": 42.92, "text": " use to learn the parameters for the model."}, {"start": 42.92, "end": 51.019999999999996, "text": " In order to explain mean normalization, I'm actually going to add a fifth user, Eve, who"}, {"start": 51.019999999999996, "end": 53.96, "text": " has not yet rated any movies."}, {"start": 53.96, "end": 60.04, "text": " So you see in a little bit that adding mean normalization will help the algorithm make"}, {"start": 60.04, "end": 63.160000000000004, "text": " better predictions on the user Eve."}, {"start": 63.160000000000004, "end": 69.92, "text": " In fact, if you were to train a collaborative filtering algorithm on this data, then because"}, {"start": 69.92, "end": 76.2, "text": " we are trying to make the parameters w small because of this regularization term, if you"}, {"start": 76.2, "end": 83.48, "text": " were to run the algorithm on this data set, you actually end up with the parameters w"}, {"start": 83.48, "end": 92.36, "text": " for the fifth user, for the user Eve, to be equal to 0, 0, as well as quite likely b5"}, {"start": 92.36, "end": 93.96000000000001, "text": " equals 0."}, {"start": 93.96000000000001, "end": 100.68, "text": " Because Eve hasn't rated any movies yet, the parameters w and b don't affect this first"}, {"start": 100.68, "end": 107.32000000000001, "text": " term in the cost function because none of Eve's movies rating play a role in this squared"}, {"start": 107.32000000000001, "end": 109.36, "text": " error cost function."}, {"start": 109.36, "end": 116.03999999999999, "text": " And so minimizing this means making the parameters w as small as possible."}, {"start": 116.03999999999999, "end": 121.64, "text": " We didn't really regularize b, but if you initialize b to 0 as a default, you end up"}, {"start": 121.64, "end": 124.34, "text": " with b5 equals 0 as well."}, {"start": 124.34, "end": 130.76, "text": " But if these are the parameters for user 5, that is for Eve, then what the algorithm will"}, {"start": 130.76, "end": 141.84, "text": " end up doing is predict that all of Eve's movies ratings would be w5.x for movie i plus"}, {"start": 141.84, "end": 147.28, "text": " b5, and this is equal to 0 if w and b above equal to 0."}, {"start": 147.28, "end": 151.84, "text": " And so this algorithm would predict that if you have a new user that has not yet rated"}, {"start": 151.84, "end": 156.44, "text": " anything, we think they'll rate all movies with 0 stars, and that's not particularly"}, {"start": 156.44, "end": 158.23999999999998, "text": " helpful."}, {"start": 158.24, "end": 164.08, "text": " So in this video, we'll see that mean normalization will help this algorithm come up with better"}, {"start": 164.08, "end": 170.68, "text": " predictions of the movie ratings for a new user that has not yet rated any movies."}, {"start": 170.68, "end": 177.64000000000001, "text": " In order to describe mean normalization, let me take all of the values here, including"}, {"start": 177.64000000000001, "end": 183.12, "text": " all the question marks for Eve, and put them in a two dimensional matrix like this, just"}, {"start": 183.12, "end": 188.68, "text": " to write out all the ratings, including the question marks, in a more succinct or a more"}, {"start": 188.68, "end": 190.44, "text": " compact way."}, {"start": 190.44, "end": 196.6, "text": " To carry out mean normalization, what we're going to do is take all of these ratings and"}, {"start": 196.6, "end": 201.64000000000001, "text": " for each movie, compute the average rating that was given."}, {"start": 201.64000000000001, "end": 207.68, "text": " So movie 1 had two 5s and two 0s, and so the average rating is 2.5."}, {"start": 207.68, "end": 211.76, "text": " Movie 2 had a 5 and a 0, so that averages out to 2.5."}, {"start": 211.76, "end": 214.88, "text": " Movie 3, 4 and 0, averages out to 2."}, {"start": 214.88, "end": 225.39999999999998, "text": " Movie 4 averages out to 2.25 rating, and movie 5, not that popular, has an average 1.25 rating."}, {"start": 225.39999999999998, "end": 229.72, "text": " So I'm going to take all of these five numbers and gather them into a vector, which I'm going"}, {"start": 229.72, "end": 235.23999999999998, "text": " to call mu, because this is the vector of the average ratings that each of the movies"}, {"start": 235.23999999999998, "end": 240.07999999999998, "text": " had, averaging over just the users that did rate that particular movie."}, {"start": 240.08, "end": 245.96, "text": " Instead of using these original 0 to 5 star ratings over here, I'm going to take this"}, {"start": 245.96, "end": 251.28, "text": " and subtract from every rating the mean rating that it was given."}, {"start": 251.28, "end": 259.72, "text": " So for example, this movie rating was 5, I'm going to subtract 2.5, giving me 2.5 over"}, {"start": 259.72, "end": 261.04, "text": " here."}, {"start": 261.04, "end": 268.68, "text": " This movie had a 0 star rating, going to subtract 2.25, giving me a negative 2.25 rating, and"}, {"start": 268.68, "end": 269.68, "text": " so on."}, {"start": 269.68, "end": 274.12, "text": " So I'm going to take all of the now five users, including the new user Eve, as well as for"}, {"start": 274.12, "end": 275.92, "text": " all five movies."}, {"start": 275.92, "end": 279.44, "text": " Then these new values on the right become your new values of yij."}, {"start": 279.44, "end": 287.0, "text": " We're going to pretend that user 1 had given a 2.5 rating to movie 1 and a negative 2.25"}, {"start": 287.0, "end": 288.6, "text": " rating to movie 4."}, {"start": 288.6, "end": 294.92, "text": " And using this, you can then learn wj, bj and xi."}, {"start": 294.92, "end": 305.12, "text": " Same as before, for user j on movie i, you would predict wj.xi plus bj."}, {"start": 305.12, "end": 312.88, "text": " But because we had subtracted off mu i for movie i during this mean normalization step,"}, {"start": 312.88, "end": 318.56, "text": " in order to predict not a negative star rating, which isn't possible if a user rates from"}, {"start": 318.56, "end": 325.56, "text": " zero to five stars, we have to add back this mu i, which is just the value we had subtracted"}, {"start": 325.56, "end": 326.56, "text": " out."}, {"start": 326.56, "end": 333.52, "text": " So as a concrete example, if we look at what happens with user 5, with the new user Eve,"}, {"start": 333.52, "end": 338.76, "text": " because she had not yet rated any movies, the algorithm might learn parameters w5 equals"}, {"start": 338.76, "end": 343.14, "text": " zero and say b5 equals zero."}, {"start": 343.14, "end": 349.91999999999996, "text": " And so if we look at the predicted rating for movie 1, we will predict that Eve would"}, {"start": 349.91999999999996, "end": 365.59999999999997, "text": " rate it w5.x1 plus b5, but this is zero, and then plus mu 1, which is equal to 2.5."}, {"start": 365.59999999999997, "end": 371.97999999999996, "text": " So this seems more reasonable to think Eve was likely to rate this movie 2.5 rather than"}, {"start": 371.98, "end": 376.12, "text": " think Eve will rate all movies zero stars just because she hasn't rated any movies"}, {"start": 376.12, "end": 377.12, "text": " yet."}, {"start": 377.12, "end": 383.96000000000004, "text": " And in fact, the effect of this algorithm is it will cause the initial guesses for the"}, {"start": 383.96000000000004, "end": 390.28000000000003, "text": " new user Eve to be just equal to the mean of whatever other users have rated these five"}, {"start": 390.28000000000003, "end": 391.28000000000003, "text": " movies."}, {"start": 391.28000000000003, "end": 395.76, "text": " And that seems more reasonable to take the average rating of the movies rather than to"}, {"start": 395.76, "end": 400.38, "text": " guess that all the ratings by Eve will be zero."}, {"start": 400.38, "end": 406.44, "text": " It turns out that by normalizing the mean of the different movies ratings to be zero,"}, {"start": 406.44, "end": 412.15999999999997, "text": " the optimization algorithm for the recommended system will also run just a little bit faster."}, {"start": 412.15999999999997, "end": 417.76, "text": " But it does make the algorithm behave much better for users that have rated no movies"}, {"start": 417.76, "end": 424.28, "text": " or very small numbers of movies and the predictions will become more reasonable."}, {"start": 424.28, "end": 429.04, "text": " In this example, what we did was normalize each of the rows of this matrix to have zero"}, {"start": 429.04, "end": 433.84000000000003, "text": " mean and we saw this helps when there's a new user that hasn't rated a lot of movies"}, {"start": 433.84000000000003, "end": 434.84000000000003, "text": " yet."}, {"start": 434.84000000000003, "end": 441.0, "text": " There's one other alternative that you could use, which is to instead normalize the columns"}, {"start": 441.0, "end": 444.24, "text": " of this matrix to have zero mean."}, {"start": 444.24, "end": 446.88, "text": " And that would be a reasonable thing to do too."}, {"start": 446.88, "end": 453.20000000000005, "text": " But I think in this application, normalizing the rows so that you can give reasonable ratings"}, {"start": 453.2, "end": 460.0, "text": " for a new user seems more important than normalizing the columns."}, {"start": 460.0, "end": 464.24, "text": " Normalizing the columns would help if there was a brand new movie that no one has rated"}, {"start": 464.24, "end": 465.24, "text": " yet."}, {"start": 465.24, "end": 470.03999999999996, "text": " But if there's a brand new movie that no one has rated yet, you probably shouldn't show"}, {"start": 470.03999999999996, "end": 475.88, "text": " that movie to too many users initially because you don't know that much about that movie."}, {"start": 475.88, "end": 482.41999999999996, "text": " So normalizing columns to help with the case of a movie with no ratings seems less important"}, {"start": 482.42, "end": 487.94, "text": " to me than normalizing the rows to help with the case of a new user that's hardly rated"}, {"start": 487.94, "end": 489.62, "text": " any movies yet."}, {"start": 489.62, "end": 495.24, "text": " And when you're building your own recommender system in this week's practice lab, normalizing"}, {"start": 495.24, "end": 497.84000000000003, "text": " just the rows should work fine."}, {"start": 497.84000000000003, "end": 499.92, "text": " So that's mean normalization."}, {"start": 499.92, "end": 504.44, "text": " It makes the algorithm run a little bit faster, but even more important, it makes the algorithm"}, {"start": 504.44, "end": 510.1, "text": " give much better, much more reasonable predictions when there are users that have rated very"}, {"start": 510.1, "end": 513.44, "text": " few movies or even no movies at all."}, {"start": 513.44, "end": 518.24, "text": " This implementational detail of mean normalization will make your recommender system work much"}, {"start": 518.24, "end": 519.24, "text": " better."}, {"start": 519.24, "end": 524.5400000000001, "text": " Next, let's go on to the next video to talk about how you can implement this for yourself"}, {"start": 524.54, "end": 541.0799999999999, "text": " in TensorFlow."}]