9.8 Content-based Filtering | Collaborative filtering vs Content-based filtering-- [ML |Andrew Ng]
 In this video, we'll start to develop a second type of recommender system called a content-based filtering algorithm. To get started, let's compare and contrast the collaborative filtering approach that we've been looking at so far with this new content-based filtering approach. Let's take a look. With collaborative filtering, the general approach is that we would recommend items to you based on ratings of users who gave similar ratings as you. So we have some number of users give some ratings for some items, and the algorithm figures out how to use that to recommend new items to you. In contrast, content-based filtering takes a different approach to deciding what to recommend to you. A content-based filtering algorithm will recommend items to you based on the features of users and features of the items to find a good match. In other words, it requires having some features of each user as well as some features of each item, and it uses those features to try to decide which items and users might be a good match for each other. With a content-based filtering algorithm, you still have data where users have rated some items. So with content-based filtering, we'll continue to use our ij to denote whether or not user j has rated item i, and we'll continue to use yij to denote the rating that user j has given item i, if it's defined. But the key to content-based filtering is that we'll be able to make good use of features of the user and of the items to find better matches than potentially a pure collaborative filtering approach might be able to. Let's take a look at how this works. In the case of movie recommendations, here are some examples of features. You may know the age of the user, or you may have the gender of the user. So this could be a one-hot feature, similar to what you saw when we were talking about decision trees, where you could have a one-hot feature with three values based on whether the user's self-identified gender is male or female or unknown. And you may know the country of the user. So if there are about 200 countries in the world, then does it be a one-hot feature with about 200 possible values? You can also look at past behaviors of the user to construct this feature vector. For example, if you look at the top thousand movies in your catalog, you might construct a thousand features that tells you of the thousand most popular movies in the world, which of these has the user watched. And in fact, you can also take ratings the user might have already given in order to construct new features. So it turns out that if you have a set of movies and if you know what genre each movie is in, then the average rating per genre that the user has given. So of all the romance movies that the user has rated, what was the average rating? Of all the action movies that the user has rated, what was the average rating? And so on for all the other genres, this too can be a powerful feature to describe the user. One interesting thing about this feature is that it actually depends on the ratings that the user had given, but there's nothing wrong with that. Constructing a feature vector that depends on the user's ratings is a completely fine way to develop a feature vector to describe that user. So with such features like these, you can then come up with a feature vector X subscript U, U stands for user, superscript J for user J. Similarly, you can also come up with a set of features for each movie or for each item, such as what was the year of the movie? What's the genre or genres of the movie of known? If there are critic reviews of the movie, you can construct one or multiple features to capture something about what the critics are saying about the movie. Or once again, you can actually take user ratings of the movie to construct a feature of say the average rating of this movie. This feature again depends on the ratings that users had given, but again, there's nothing wrong with that. You can construct a feature for a given movie that depends on the ratings the movie had received, such as the average rating of the movie. Or if you wish, you can also have average rating per country or average rating per user demographic and so on to construct other types of features of the movies as well. And so with this for each movie, you can then construct a feature vector, which I'm going to denote X subscript M, M stands for movie and superscript I for movie I. Given features like this, the task is to try to figure out whether a given movie I is going to be a good match for user J. Notice that the user features and movie features can be very different in size. For example, maybe the user features could be 1500 numbers and the movie features could be just 50 numbers. And that's okay too. In content based filtering, we're going to develop an algorithm that learns to match users and movies. Previously, we were predicting the rating of user J on movie I as WJ dot product of XI plus BJ. In order to develop content based filtering, I'm going to get rid of BJ. It turns out this won't hurt the performance of the content based filtering at all. Instead of writing WJ for a user J and XI for a movie I, I'm instead going to just replace this notation with VJ U. This V here stands for a vector. It'll be a list of numbers computed for user J and the U subscript here stands for user. And instead of XI, I'm going to compute a separate vector, subscript M, this stands for movie and for movie I is what the superscript stands for. So VJ U is a vector, is a list of numbers computed from the features of user J. And VIM is a list of numbers computed from the features like the ones you saw in the previous slide of user I. And if we're able to come up with an appropriate choice of these vectors, VJ U and VIM, then hopefully the dot product between these two vectors will be a good prediction of the rating that user J gives movie I. Just to illustrate what a learning algorithm could come up with, if VU that is a user vector turns out to capture the user's preferences, say is 4.9, 0.1, and so on, list of numbers like that. And the first number captures how much do they like romance movies? And then the second number captures how much do they like action movies? And so on. And if VM, the movie vector is 4.5, 0.2, and so on and so forth. With these numbers capturing how much is this a romance movie, how much this is an action movie, and so on. Then the dot product which multiplies these list of numbers element-wise and then takes a sum, hopefully will give a sense of how much this particular user will like this particular movie. So the challenge is given features of a user, say XJ U, how can we compute this vector VJ U that represents succinctly or compactly the user's preferences? And similarly given features of a movie, how can we compute VIM? Notice that whereas XU and XM could be different in size, one could be a very long list of numbers, one could be much shorter list, V here have to be the same size. Because if you want to take a dot product between VU and VM, then both of them have to have the same dimension, such as maybe both of these are, say, 32 numbers. So to summarize, in collaborative filtering, we had number of users give ratings of different items. In contrast, in content-based filtering, we have features of users and features of items, and we want to find a way to find good matches between the users and the items. And the way we're going to do so is to compute these vectors, VU for the users and VM for the items of the movies, and then take dot products between them to try to find good matches. How do we compute VU and VM? Let's take a look at that in the next video.
[{"start": 0.0, "end": 8.0, "text": " In this video, we'll start to develop a second type of recommender system called a content-based"}, {"start": 8.0, "end": 9.8, "text": " filtering algorithm."}, {"start": 9.8, "end": 13.8, "text": " To get started, let's compare and contrast the collaborative filtering approach that"}, {"start": 13.8, "end": 17.48, "text": " we've been looking at so far with this new content-based filtering approach."}, {"start": 17.48, "end": 19.240000000000002, "text": " Let's take a look."}, {"start": 19.240000000000002, "end": 25.16, "text": " With collaborative filtering, the general approach is that we would recommend items"}, {"start": 25.16, "end": 31.14, "text": " to you based on ratings of users who gave similar ratings as you."}, {"start": 31.14, "end": 36.44, "text": " So we have some number of users give some ratings for some items, and the algorithm"}, {"start": 36.44, "end": 40.96, "text": " figures out how to use that to recommend new items to you."}, {"start": 40.96, "end": 48.04, "text": " In contrast, content-based filtering takes a different approach to deciding what to recommend"}, {"start": 48.04, "end": 49.04, "text": " to you."}, {"start": 49.04, "end": 55.04, "text": " A content-based filtering algorithm will recommend items to you based on the features of users"}, {"start": 55.04, "end": 58.68, "text": " and features of the items to find a good match."}, {"start": 58.68, "end": 65.44, "text": " In other words, it requires having some features of each user as well as some features of each"}, {"start": 65.44, "end": 72.08, "text": " item, and it uses those features to try to decide which items and users might be a good"}, {"start": 72.08, "end": 73.9, "text": " match for each other."}, {"start": 73.9, "end": 79.36, "text": " With a content-based filtering algorithm, you still have data where users have rated"}, {"start": 79.36, "end": 80.6, "text": " some items."}, {"start": 80.6, "end": 88.28, "text": " So with content-based filtering, we'll continue to use our ij to denote whether or not user"}, {"start": 88.28, "end": 97.0, "text": " j has rated item i, and we'll continue to use yij to denote the rating that user j has"}, {"start": 97.0, "end": 99.8, "text": " given item i, if it's defined."}, {"start": 99.8, "end": 106.39999999999999, "text": " But the key to content-based filtering is that we'll be able to make good use of features"}, {"start": 106.4, "end": 113.72, "text": " of the user and of the items to find better matches than potentially a pure collaborative"}, {"start": 113.72, "end": 116.16000000000001, "text": " filtering approach might be able to."}, {"start": 116.16000000000001, "end": 117.96000000000001, "text": " Let's take a look at how this works."}, {"start": 117.96000000000001, "end": 122.12, "text": " In the case of movie recommendations, here are some examples of features."}, {"start": 122.12, "end": 128.6, "text": " You may know the age of the user, or you may have the gender of the user."}, {"start": 128.6, "end": 134.52, "text": " So this could be a one-hot feature, similar to what you saw when we were talking about"}, {"start": 134.52, "end": 140.28, "text": " decision trees, where you could have a one-hot feature with three values based on whether"}, {"start": 140.28, "end": 146.20000000000002, "text": " the user's self-identified gender is male or female or unknown."}, {"start": 146.20000000000002, "end": 149.48000000000002, "text": " And you may know the country of the user."}, {"start": 149.48000000000002, "end": 155.76000000000002, "text": " So if there are about 200 countries in the world, then does it be a one-hot feature with"}, {"start": 155.76000000000002, "end": 158.16000000000003, "text": " about 200 possible values?"}, {"start": 158.16000000000003, "end": 163.48000000000002, "text": " You can also look at past behaviors of the user to construct this feature vector."}, {"start": 163.48, "end": 168.79999999999998, "text": " For example, if you look at the top thousand movies in your catalog, you might construct"}, {"start": 168.79999999999998, "end": 174.28, "text": " a thousand features that tells you of the thousand most popular movies in the world,"}, {"start": 174.28, "end": 177.2, "text": " which of these has the user watched."}, {"start": 177.2, "end": 182.83999999999997, "text": " And in fact, you can also take ratings the user might have already given in order to"}, {"start": 182.83999999999997, "end": 184.92, "text": " construct new features."}, {"start": 184.92, "end": 190.79999999999998, "text": " So it turns out that if you have a set of movies and if you know what genre each movie"}, {"start": 190.8, "end": 196.48000000000002, "text": " is in, then the average rating per genre that the user has given."}, {"start": 196.48000000000002, "end": 202.84, "text": " So of all the romance movies that the user has rated, what was the average rating?"}, {"start": 202.84, "end": 207.58, "text": " Of all the action movies that the user has rated, what was the average rating?"}, {"start": 207.58, "end": 214.4, "text": " And so on for all the other genres, this too can be a powerful feature to describe the"}, {"start": 214.4, "end": 215.60000000000002, "text": " user."}, {"start": 215.6, "end": 221.44, "text": " One interesting thing about this feature is that it actually depends on the ratings that"}, {"start": 221.44, "end": 224.92, "text": " the user had given, but there's nothing wrong with that."}, {"start": 224.92, "end": 229.88, "text": " Constructing a feature vector that depends on the user's ratings is a completely fine"}, {"start": 229.88, "end": 233.79999999999998, "text": " way to develop a feature vector to describe that user."}, {"start": 233.79999999999998, "end": 240.68, "text": " So with such features like these, you can then come up with a feature vector X subscript"}, {"start": 240.68, "end": 244.56, "text": " U, U stands for user, superscript J for user J."}, {"start": 244.56, "end": 250.28, "text": " Similarly, you can also come up with a set of features for each movie or for each item,"}, {"start": 250.28, "end": 253.12, "text": " such as what was the year of the movie?"}, {"start": 253.12, "end": 256.7, "text": " What's the genre or genres of the movie of known?"}, {"start": 256.7, "end": 262.72, "text": " If there are critic reviews of the movie, you can construct one or multiple features"}, {"start": 262.72, "end": 267.04, "text": " to capture something about what the critics are saying about the movie."}, {"start": 267.04, "end": 272.44, "text": " Or once again, you can actually take user ratings of the movie to construct a feature"}, {"start": 272.44, "end": 276.02, "text": " of say the average rating of this movie."}, {"start": 276.02, "end": 283.12, "text": " This feature again depends on the ratings that users had given, but again, there's nothing"}, {"start": 283.12, "end": 284.12, "text": " wrong with that."}, {"start": 284.12, "end": 289.32, "text": " You can construct a feature for a given movie that depends on the ratings the movie had"}, {"start": 289.32, "end": 292.24, "text": " received, such as the average rating of the movie."}, {"start": 292.24, "end": 298.8, "text": " Or if you wish, you can also have average rating per country or average rating per user"}, {"start": 298.8, "end": 303.28000000000003, "text": " demographic and so on to construct other types of features of the movies as well."}, {"start": 303.28000000000003, "end": 308.32, "text": " And so with this for each movie, you can then construct a feature vector, which I'm going"}, {"start": 308.32, "end": 315.08000000000004, "text": " to denote X subscript M, M stands for movie and superscript I for movie I."}, {"start": 315.08000000000004, "end": 323.6, "text": " Given features like this, the task is to try to figure out whether a given movie I is going"}, {"start": 323.6, "end": 327.16, "text": " to be a good match for user J."}, {"start": 327.16, "end": 333.92, "text": " Notice that the user features and movie features can be very different in size."}, {"start": 333.92, "end": 341.48, "text": " For example, maybe the user features could be 1500 numbers and the movie features could"}, {"start": 341.48, "end": 343.64000000000004, "text": " be just 50 numbers."}, {"start": 343.64000000000004, "end": 344.88, "text": " And that's okay too."}, {"start": 344.88, "end": 349.12, "text": " In content based filtering, we're going to develop an algorithm that learns to match"}, {"start": 349.12, "end": 351.56, "text": " users and movies."}, {"start": 351.56, "end": 359.92, "text": " Previously, we were predicting the rating of user J on movie I as WJ dot product of"}, {"start": 359.92, "end": 363.0, "text": " XI plus BJ."}, {"start": 363.0, "end": 369.2, "text": " In order to develop content based filtering, I'm going to get rid of BJ."}, {"start": 369.2, "end": 372.92, "text": " It turns out this won't hurt the performance of the content based filtering at all."}, {"start": 372.92, "end": 382.28000000000003, "text": " Instead of writing WJ for a user J and XI for a movie I, I'm instead going to just replace"}, {"start": 382.28000000000003, "end": 386.64000000000004, "text": " this notation with VJ U."}, {"start": 386.64000000000004, "end": 388.56, "text": " This V here stands for a vector."}, {"start": 388.56, "end": 397.38, "text": " It'll be a list of numbers computed for user J and the U subscript here stands for user."}, {"start": 397.38, "end": 403.04, "text": " And instead of XI, I'm going to compute a separate vector, subscript M, this stands"}, {"start": 403.04, "end": 408.36, "text": " for movie and for movie I is what the superscript stands for."}, {"start": 408.36, "end": 418.84, "text": " So VJ U is a vector, is a list of numbers computed from the features of user J. And"}, {"start": 418.84, "end": 425.96, "text": " VIM is a list of numbers computed from the features like the ones you saw in the previous"}, {"start": 425.96, "end": 428.88, "text": " slide of user I."}, {"start": 428.88, "end": 437.35999999999996, "text": " And if we're able to come up with an appropriate choice of these vectors, VJ U and VIM, then"}, {"start": 437.35999999999996, "end": 443.24, "text": " hopefully the dot product between these two vectors will be a good prediction of the rating"}, {"start": 443.24, "end": 445.84, "text": " that user J gives movie I."}, {"start": 445.84, "end": 454.7, "text": " Just to illustrate what a learning algorithm could come up with, if VU that is a user vector"}, {"start": 454.7, "end": 463.24, "text": " turns out to capture the user's preferences, say is 4.9, 0.1, and so on, list of numbers"}, {"start": 463.24, "end": 464.24, "text": " like that."}, {"start": 464.24, "end": 469.4, "text": " And the first number captures how much do they like romance movies?"}, {"start": 469.4, "end": 473.88, "text": " And then the second number captures how much do they like action movies?"}, {"start": 473.88, "end": 474.88, "text": " And so on."}, {"start": 474.88, "end": 483.91999999999996, "text": " And if VM, the movie vector is 4.5, 0.2, and so on and so forth."}, {"start": 483.92, "end": 488.8, "text": " With these numbers capturing how much is this a romance movie, how much this is an action"}, {"start": 488.8, "end": 490.72, "text": " movie, and so on."}, {"start": 490.72, "end": 496.72, "text": " Then the dot product which multiplies these list of numbers element-wise and then takes"}, {"start": 496.72, "end": 502.72, "text": " a sum, hopefully will give a sense of how much this particular user will like this particular"}, {"start": 502.72, "end": 503.72, "text": " movie."}, {"start": 503.72, "end": 511.68, "text": " So the challenge is given features of a user, say XJ U, how can we compute this vector VJ"}, {"start": 511.68, "end": 517.48, "text": " U that represents succinctly or compactly the user's preferences?"}, {"start": 517.48, "end": 523.4, "text": " And similarly given features of a movie, how can we compute VIM?"}, {"start": 523.4, "end": 530.48, "text": " Notice that whereas XU and XM could be different in size, one could be a very long list of"}, {"start": 530.48, "end": 537.12, "text": " numbers, one could be much shorter list, V here have to be the same size."}, {"start": 537.12, "end": 542.24, "text": " Because if you want to take a dot product between VU and VM, then both of them have"}, {"start": 542.24, "end": 548.96, "text": " to have the same dimension, such as maybe both of these are, say, 32 numbers."}, {"start": 548.96, "end": 555.92, "text": " So to summarize, in collaborative filtering, we had number of users give ratings of different"}, {"start": 555.92, "end": 557.2, "text": " items."}, {"start": 557.2, "end": 563.16, "text": " In contrast, in content-based filtering, we have features of users and features of items,"}, {"start": 563.16, "end": 568.64, "text": " and we want to find a way to find good matches between the users and the items."}, {"start": 568.64, "end": 575.0799999999999, "text": " And the way we're going to do so is to compute these vectors, VU for the users and VM for"}, {"start": 575.0799999999999, "end": 579.92, "text": " the items of the movies, and then take dot products between them to try to find good"}, {"start": 579.92, "end": 580.92, "text": " matches."}, {"start": 580.92, "end": 583.36, "text": " How do we compute VU and VM?"}, {"start": 583.36, "end": 594.04, "text": " Let's take a look at that in the next video."}]