9.4 Collaborative Filtering | Binary labels: favs, likes and clicks-- [Machine Learning| Andrew Ng]
 Many important applications of recommended systems or collaborative filtering algorithms involve binary labels where instead of a user giving you a 1 to 5 star or 0 to 5 star rating, they just somehow give you a sense of they like this item or they did not like this item. Let's take a look at how to generalize the algorithm you've seen to this setting. The process we'll use to generalize the algorithm will be very much reminiscent to how we had gone from linear regression to logistic regression to predicting numbers to predicting a binary label back in course 1. Let's take a look. Here's an example of a collaborative filtering dataset with binary labels. A 1 denotes that the user liked or engaged with a particular movie, so label 1 could mean that Alice watched the movie Love at Last all the way to the end and watched Romance Forever all the way to the end, but after playing a few minutes of non-stop car chases decided to stop the video and move on. Or it could mean that she explicitly hit like or favorite on an app to indicate that she liked these movies, but after checking out non-stop car chases and Souls vs Karate did not hit like, and the question mark usually means the user has not yet seen the item and so they weren't in a position to decide whether or not to hit like or favorite on that particular item. So the question is, how can we take the collaborative filtering algorithm that you saw in the last video and get it to work on this dataset? And by predicting how likely Alice, Bob, Carol and Dave are to like the items that they have not yet rated, we can then decide how much we should recommend these items to them. There are many ways of defining what is a label 1 and what is a label 0 and what is a label question mark in collaborative filtering with binary labels. Let's take a look at a few examples. In an online shopping website, the label could denote whether or not user J chose to purchase an item after they were exposed to it, after they were shown the item. So 1 would denote that they purchased it, 0 would denote that they did not purchase it and the question mark would denote that they were not even shown, were not even exposed to the item. Or in a social media setting, the labels 1 or 0 could denote to the user favorites or like an item after they were shown it and question mark would be if they've not yet been shown the item. For many sites, instead of asking for explicit user rating, we'll use the user behavior to try to guess if the user liked the item. So for example, you can measure if a user spends at least 30 seconds of an item and if they did, then assign that a label 1 because the user found the item engaging or if a user was shown an item but did not spend at least 30 seconds with it, then assign that a label 0 or if the user was not shown the item yet then assign it a question mark. Another way to generate a rating implicitly as a function of the user behavior will be to see that the user clicked on an item. This is often done in online advertising where if the user has been shown an ad, if they clicked on it, assign it a label 1, if they did not click, assign it a label 0 and the question mark will refer to if the user has not even been shown that ad in the first place. So often these binary labels will have a rough meaning as follows. A label of 1 means that the user engaged after being shown an item. An engaged could mean that they clicked or spent 30 seconds or explicitly favored or liked or purchased the item. A 0 would reflect the user not engaging after being shown the item and the question mark would reflect the item not yet having been shown to the user. So given these binary labels, let's look at how we can generalize our algorithm which is a lot like linear regression from the previous couple of videos to predicting these binary outputs. Previously, we were predicting label yij as wj.prime.xi plus b. So this was a lot like a linear regression model. But binary labels were going to predict that the probability of yij being equal to 1 is given by not wj.xi plus b but instead by g of this formula where now g of z is 1 over 1 plus e to the negative z. So this is the logistic function just like we saw in logistic regression. And what we would do is take what was a lot like a linear regression model and turn it into something that would be a lot like a logistic regression model where we'll now predict the probability of yij being 1 that is of the user having engaged with or liked the item using this model. In order to build this algorithm, we'll also have to modify the cost function from the squared error cost function to a cost function that is more appropriate for binary labels for a logistic regression like model. So previously, this was the cost function that we had where this term played a role similar to f of x, the prediction of the algorithm. When you now have binary labels yij when the labels are 1 or 0 or question mark, then the prediction f of x becomes instead of wj.xi plus bj, it becomes g of this where g is the logistic function. And similar to when we had derived logistic regression, we had written out the following loss function for a single example, which was that the loss, if the algorithm predicts f of x and the true label was y, the loss was this. It was negative y log f minus 1 minus y log 1 minus f. This is also sometimes called the binary cross entropy cost function, but this is the standard cost function that we had used for logistic regression as well as for the binary classification problems when we were training neural networks. And so to adapt this to the collaborative filtering setting, let me write out the cost function, which is now a function of all the parameters w and b, as well as all the parameters x, which are the features of the individual rubies or items of, we now need to sum over all the pairs ij where r ij is equal to 1. Notice this is just similar to the summation up on top. And now instead of this squared error cost function, we're going to use that loss function as a function of f of x comma y ij, where f of x here, that's my abbreviation, my shorthand for g of w j dot x i plus v j. And if you plug this into here, then this gives you the cost function they can use for collaborative filtering on binary labels. So that's it. That's how you can take the linear regression like collaborative filtering algorithm and generalize it to work with binary labels. And this actually very significantly opens up the set of applications you can address with this algorithm. Now even though you've seen the key structure and cost function of the algorithm, there are also some implementational tips that will make your algorithm work much better. Let's go on to the next video to take a look at some details of how you implement this and some little modifications that will make the algorithm run much faster. Let's go on to the next video.
[{"start": 0.0, "end": 8.22, "text": " Many important applications of recommended systems or collaborative filtering algorithms"}, {"start": 8.22, "end": 15.700000000000001, "text": " involve binary labels where instead of a user giving you a 1 to 5 star or 0 to 5 star rating,"}, {"start": 15.700000000000001, "end": 21.32, "text": " they just somehow give you a sense of they like this item or they did not like this item."}, {"start": 21.32, "end": 25.5, "text": " Let's take a look at how to generalize the algorithm you've seen to this setting."}, {"start": 25.5, "end": 30.44, "text": " The process we'll use to generalize the algorithm will be very much reminiscent to how we had"}, {"start": 30.44, "end": 37.04, "text": " gone from linear regression to logistic regression to predicting numbers to predicting a binary"}, {"start": 37.04, "end": 39.0, "text": " label back in course 1."}, {"start": 39.0, "end": 40.0, "text": " Let's take a look."}, {"start": 40.0, "end": 45.8, "text": " Here's an example of a collaborative filtering dataset with binary labels."}, {"start": 45.8, "end": 53.28, "text": " A 1 denotes that the user liked or engaged with a particular movie, so label 1 could"}, {"start": 53.28, "end": 58.44, "text": " mean that Alice watched the movie Love at Last all the way to the end and watched Romance"}, {"start": 58.44, "end": 63.44, "text": " Forever all the way to the end, but after playing a few minutes of non-stop car chases"}, {"start": 63.44, "end": 66.64, "text": " decided to stop the video and move on."}, {"start": 66.64, "end": 73.32, "text": " Or it could mean that she explicitly hit like or favorite on an app to indicate that she"}, {"start": 73.32, "end": 77.88, "text": " liked these movies, but after checking out non-stop car chases and Souls vs Karate did"}, {"start": 77.88, "end": 83.6, "text": " not hit like, and the question mark usually means the user has not yet seen the item and"}, {"start": 83.6, "end": 89.52, "text": " so they weren't in a position to decide whether or not to hit like or favorite on that particular"}, {"start": 89.52, "end": 90.52, "text": " item."}, {"start": 90.52, "end": 94.91999999999999, "text": " So the question is, how can we take the collaborative filtering algorithm that you saw in the last"}, {"start": 94.91999999999999, "end": 97.94, "text": " video and get it to work on this dataset?"}, {"start": 97.94, "end": 103.91999999999999, "text": " And by predicting how likely Alice, Bob, Carol and Dave are to like the items that they have"}, {"start": 103.92, "end": 111.6, "text": " not yet rated, we can then decide how much we should recommend these items to them."}, {"start": 111.6, "end": 116.92, "text": " There are many ways of defining what is a label 1 and what is a label 0 and what is"}, {"start": 116.92, "end": 121.76, "text": " a label question mark in collaborative filtering with binary labels."}, {"start": 121.76, "end": 123.72, "text": " Let's take a look at a few examples."}, {"start": 123.72, "end": 131.88, "text": " In an online shopping website, the label could denote whether or not user J chose to purchase"}, {"start": 131.88, "end": 136.68, "text": " an item after they were exposed to it, after they were shown the item."}, {"start": 136.68, "end": 140.6, "text": " So 1 would denote that they purchased it, 0 would denote that they did not purchase"}, {"start": 140.6, "end": 145.04, "text": " it and the question mark would denote that they were not even shown, were not even exposed"}, {"start": 145.04, "end": 146.2, "text": " to the item."}, {"start": 146.2, "end": 152.84, "text": " Or in a social media setting, the labels 1 or 0 could denote to the user favorites or"}, {"start": 152.84, "end": 157.16, "text": " like an item after they were shown it and question mark would be if they've not yet"}, {"start": 157.16, "end": 158.84, "text": " been shown the item."}, {"start": 158.84, "end": 165.36, "text": " For many sites, instead of asking for explicit user rating, we'll use the user behavior"}, {"start": 165.36, "end": 168.92000000000002, "text": " to try to guess if the user liked the item."}, {"start": 168.92000000000002, "end": 175.44, "text": " So for example, you can measure if a user spends at least 30 seconds of an item and"}, {"start": 175.44, "end": 181.36, "text": " if they did, then assign that a label 1 because the user found the item engaging or if a user"}, {"start": 181.36, "end": 187.08, "text": " was shown an item but did not spend at least 30 seconds with it, then assign that a label"}, {"start": 187.08, "end": 192.92000000000002, "text": " 0 or if the user was not shown the item yet then assign it a question mark."}, {"start": 192.92000000000002, "end": 198.60000000000002, "text": " Another way to generate a rating implicitly as a function of the user behavior will be"}, {"start": 198.60000000000002, "end": 201.52, "text": " to see that the user clicked on an item."}, {"start": 201.52, "end": 207.08, "text": " This is often done in online advertising where if the user has been shown an ad, if they"}, {"start": 207.08, "end": 212.96, "text": " clicked on it, assign it a label 1, if they did not click, assign it a label 0 and the"}, {"start": 212.96, "end": 217.92000000000002, "text": " question mark will refer to if the user has not even been shown that ad in the first place."}, {"start": 217.92000000000002, "end": 223.08, "text": " So often these binary labels will have a rough meaning as follows."}, {"start": 223.08, "end": 227.52, "text": " A label of 1 means that the user engaged after being shown an item."}, {"start": 227.52, "end": 232.32, "text": " An engaged could mean that they clicked or spent 30 seconds or explicitly favored or"}, {"start": 232.32, "end": 234.28, "text": " liked or purchased the item."}, {"start": 234.28, "end": 239.3, "text": " A 0 would reflect the user not engaging after being shown the item and the question mark"}, {"start": 239.3, "end": 243.56, "text": " would reflect the item not yet having been shown to the user."}, {"start": 243.56, "end": 249.52, "text": " So given these binary labels, let's look at how we can generalize our algorithm which"}, {"start": 249.52, "end": 255.52, "text": " is a lot like linear regression from the previous couple of videos to predicting these binary"}, {"start": 255.52, "end": 256.52, "text": " outputs."}, {"start": 256.52, "end": 263.04, "text": " Previously, we were predicting label yij as wj.prime.xi plus b."}, {"start": 263.04, "end": 266.28000000000003, "text": " So this was a lot like a linear regression model."}, {"start": 266.28, "end": 274.28, "text": " But binary labels were going to predict that the probability of yij being equal to 1 is"}, {"start": 274.28, "end": 287.03999999999996, "text": " given by not wj.xi plus b but instead by g of this formula where now g of z is 1 over"}, {"start": 287.03999999999996, "end": 288.47999999999996, "text": " 1 plus e to the negative z."}, {"start": 288.47999999999996, "end": 292.52, "text": " So this is the logistic function just like we saw in logistic regression."}, {"start": 292.52, "end": 298.79999999999995, "text": " And what we would do is take what was a lot like a linear regression model and turn it"}, {"start": 298.79999999999995, "end": 304.68, "text": " into something that would be a lot like a logistic regression model where we'll now"}, {"start": 304.68, "end": 313.0, "text": " predict the probability of yij being 1 that is of the user having engaged with or liked"}, {"start": 313.0, "end": 316.47999999999996, "text": " the item using this model."}, {"start": 316.47999999999996, "end": 322.03999999999996, "text": " In order to build this algorithm, we'll also have to modify the cost function from the"}, {"start": 322.04, "end": 331.08000000000004, "text": " squared error cost function to a cost function that is more appropriate for binary labels"}, {"start": 331.08000000000004, "end": 334.56, "text": " for a logistic regression like model."}, {"start": 334.56, "end": 340.56, "text": " So previously, this was the cost function that we had where this term played a role"}, {"start": 340.56, "end": 344.48, "text": " similar to f of x, the prediction of the algorithm."}, {"start": 344.48, "end": 352.68, "text": " When you now have binary labels yij when the labels are 1 or 0 or question mark, then the"}, {"start": 352.68, "end": 365.24, "text": " prediction f of x becomes instead of wj.xi plus bj, it becomes g of this where g is the"}, {"start": 365.24, "end": 366.86, "text": " logistic function."}, {"start": 366.86, "end": 372.14000000000004, "text": " And similar to when we had derived logistic regression, we had written out the following"}, {"start": 372.14, "end": 378.2, "text": " loss function for a single example, which was that the loss, if the algorithm predicts"}, {"start": 378.2, "end": 382.68, "text": " f of x and the true label was y, the loss was this."}, {"start": 382.68, "end": 391.47999999999996, "text": " It was negative y log f minus 1 minus y log 1 minus f."}, {"start": 391.47999999999996, "end": 397.4, "text": " This is also sometimes called the binary cross entropy cost function, but this is the standard"}, {"start": 397.4, "end": 402.35999999999996, "text": " cost function that we had used for logistic regression as well as for the binary classification"}, {"start": 402.35999999999996, "end": 405.76, "text": " problems when we were training neural networks."}, {"start": 405.76, "end": 411.44, "text": " And so to adapt this to the collaborative filtering setting, let me write out the cost"}, {"start": 411.44, "end": 418.79999999999995, "text": " function, which is now a function of all the parameters w and b, as well as all the parameters"}, {"start": 418.79999999999995, "end": 426.59999999999997, "text": " x, which are the features of the individual rubies or items of, we now need to sum over"}, {"start": 426.6, "end": 432.88, "text": " all the pairs ij where r ij is equal to 1."}, {"start": 432.88, "end": 436.86, "text": " Notice this is just similar to the summation up on top."}, {"start": 436.86, "end": 443.08000000000004, "text": " And now instead of this squared error cost function, we're going to use that loss function"}, {"start": 443.08000000000004, "end": 453.16, "text": " as a function of f of x comma y ij, where f of x here, that's my abbreviation, my shorthand"}, {"start": 453.16, "end": 458.04, "text": " for g of w j dot x i plus v j."}, {"start": 458.04, "end": 465.36, "text": " And if you plug this into here, then this gives you the cost function they can use for"}, {"start": 465.36, "end": 468.52000000000004, "text": " collaborative filtering on binary labels."}, {"start": 468.52000000000004, "end": 469.52000000000004, "text": " So that's it."}, {"start": 469.52000000000004, "end": 474.68, "text": " That's how you can take the linear regression like collaborative filtering algorithm and"}, {"start": 474.68, "end": 477.64000000000004, "text": " generalize it to work with binary labels."}, {"start": 477.64000000000004, "end": 482.56, "text": " And this actually very significantly opens up the set of applications you can address"}, {"start": 482.56, "end": 484.92, "text": " with this algorithm."}, {"start": 484.92, "end": 490.92, "text": " Now even though you've seen the key structure and cost function of the algorithm, there"}, {"start": 490.92, "end": 496.08, "text": " are also some implementational tips that will make your algorithm work much better."}, {"start": 496.08, "end": 501.06, "text": " Let's go on to the next video to take a look at some details of how you implement this"}, {"start": 501.06, "end": 505.6, "text": " and some little modifications that will make the algorithm run much faster."}, {"start": 505.6, "end": 512.6, "text": " Let's go on to the next video."}]