WEBVTT

00:00.480 --> 00:01.650
-: So let's try to address some

00:01.650 --> 00:04.050
of the shortcomings in user based collaborative filtering

00:04.050 --> 00:06.900
with a technique called item based collaborative filtering.

00:06.900 --> 00:09.300
And we'll see how that can be more powerful.

00:09.300 --> 00:10.500
It's actually one of the techniques

00:10.500 --> 00:12.510
that Amazon actually uses under the hood and

00:12.510 --> 00:13.650
they've talked about this publicly

00:13.650 --> 00:15.450
so I can tell you that much.

00:15.450 --> 00:17.500
But let's see why it's such a great idea.

00:19.050 --> 00:21.210
So we talked about user based collaborative filtering

00:21.210 --> 00:24.330
where we recommend items based on what people similar

00:24.330 --> 00:28.186
to you liked that you haven't seen yet or experienced yet.

00:28.186 --> 00:29.910
And we talked about some of the problems

00:29.910 --> 00:31.800
with user based collaborative filtering.

00:31.800 --> 00:33.120
So what if we flip it all in its head

00:33.120 --> 00:35.580
and instead of basing our recommendations on relationships

00:35.580 --> 00:39.270
between people, we base 'em on relationships between items.

00:39.270 --> 00:42.690
And that's what item based collaborative filtering is.

00:42.690 --> 00:45.690
So this draws in a few insights.

00:45.690 --> 00:48.000
For one thing we talked about people being fickle

00:48.000 --> 00:49.710
their tastes can change over time.

00:49.710 --> 00:52.290
So comparing one person to another person based

00:52.290 --> 00:55.050
on their past behavior becomes pretty complicated.

00:55.050 --> 00:56.430
You know, people have different phases where

00:56.430 --> 00:57.420
they have different interests

00:57.420 --> 01:00.150
and you might not be comparing the people that are

01:00.150 --> 01:01.890
in the same phase to each other

01:01.890 --> 01:03.930
but an item will always be whatever it is

01:03.930 --> 01:06.330
a movie will always be a movie, it's never gonna change.

01:06.330 --> 01:08.640
Star Wars will always be Star Wars.

01:08.640 --> 01:10.830
Well, until George Lucas tinkers with it a little bit.

01:10.830 --> 01:12.150
But for the most part

01:12.150 --> 01:14.101
items do not change as much as people do.

01:14.101 --> 01:16.766
So we know that these relationships are more permanent

01:16.766 --> 01:19.170
and there's more of a direct rel- comparison you

01:19.170 --> 01:21.870
can make when computing similarity between items

01:21.870 --> 01:23.720
because they do not change over time.

01:24.600 --> 01:26.400
The other advantage is that there are generally

01:26.400 --> 01:28.290
fewer things that you're trying to recommend

01:28.290 --> 01:29.889
than there are people you're recommending to.

01:29.889 --> 01:32.329
So again, 7 billion people in the world

01:32.329 --> 01:34.830
you're probably not offering 7 billion things

01:34.830 --> 01:36.750
on your website to to recommend to them.

01:36.750 --> 01:40.003
So, you can save a lot of computational resources

01:40.003 --> 01:43.200
by evaluating relationships between items instead

01:43.200 --> 01:45.660
of users because you probably have fewer items

01:45.660 --> 01:48.180
than you have users in your system.

01:48.180 --> 01:49.800
And that means you can run your recommendations

01:49.800 --> 01:51.120
more frequently, make them more current

01:51.120 --> 01:52.410
more up to date, better.

01:52.410 --> 01:54.660
You can use more complicated algorithms

01:54.660 --> 01:56.940
because you have less relationships to compute

01:56.940 --> 01:57.923
and that's a good thing.

01:57.923 --> 01:59.880
It's also harder to game the system.

01:59.880 --> 02:01.321
So we talked about how easy it is to

02:01.321 --> 02:04.650
gain a user-based collaborative filtering approach

02:04.650 --> 02:07.260
by just creating some fake users that like a bunch

02:07.260 --> 02:08.093
of popular stuff.

02:08.093 --> 02:09.750
And then the thing you're trying to promote

02:09.750 --> 02:10.980
with item-based collaborative filtering

02:10.980 --> 02:12.270
that becomes much more difficult.

02:12.270 --> 02:14.130
You have to game the system

02:14.130 --> 02:16.265
into thinking there are relationships between items.

02:16.265 --> 02:18.540
And since you probably don't have the capability to

02:18.540 --> 02:22.200
create fake items with fake ties to other items based

02:22.200 --> 02:25.200
on many, many other users, it's a lot harder to

02:25.200 --> 02:27.210
game an item based collaborative filtering system

02:27.210 --> 02:28.310
which is a good thing.

02:29.160 --> 02:31.230
While I'm on the topic of gaming the system

02:31.230 --> 02:32.940
another important thing is to make sure that people

02:32.940 --> 02:34.170
are voting with their money.

02:34.170 --> 02:37.740
So, a general technique for avoiding shilling attacks

02:37.740 --> 02:39.891
or people trying to game your recommender system.

02:39.891 --> 02:42.180
Make sure that the behavior that you're basing it off

02:42.180 --> 02:44.404
of is based on people actually spending money.

02:44.404 --> 02:47.489
So you're always gonna get better and more reliable results

02:47.489 --> 02:50.321
when you base recommendations on what people actually bought

02:50.321 --> 02:52.740
as opposed to what they viewed or

02:52.740 --> 02:54.543
you know what they clicked on. Okay.

02:56.430 --> 02:57.263
All right.

02:57.263 --> 02:58.096
So let's talk about

02:58.096 --> 02:58.980
how item based collaborative filtering works.

02:58.980 --> 03:01.080
It's very similar to user-based collaborative filtering,

03:01.080 --> 03:03.111
but instead of users we're looking at items.

03:03.111 --> 03:06.546
So let's go back to the example of movie recommendations.

03:06.546 --> 03:10.140
The first thing we would do is find every pair of movies

03:10.140 --> 03:13.680
every movie pairing that is watched by the same person.

03:13.680 --> 03:16.530
So we go through and find every movie that was watched

03:16.530 --> 03:20.340
by identical people, and then we measure the similarity

03:20.340 --> 03:22.689
of all those people who viewed that movie to each other.

03:22.689 --> 03:26.400
So by this means we can compute similarities

03:26.400 --> 03:29.490
between two different movies based on the ratings

03:29.490 --> 03:32.040
of the people who watched both of those movies.

03:32.040 --> 03:33.990
So I have a movie pair, okay

03:33.990 --> 03:36.150
maybe Star Wars and the Empire Strikes Back.

03:36.150 --> 03:39.058
I find a list of everyone who watched both of those movies.

03:39.058 --> 03:41.271
I compare their ratings to each other

03:41.271 --> 03:43.020
and if they're similar

03:43.020 --> 03:44.730
then I can say these two movies are similar

03:44.730 --> 03:46.140
because they were rated similarly

03:46.140 --> 03:48.090
by people who watched both of them.

03:48.090 --> 03:49.680
Okay, that's the general idea here.

03:49.680 --> 03:50.513
That's one way to do it.

03:50.513 --> 03:52.247
There's more than one way to do it.

03:52.247 --> 03:55.680
And then I can just sort everything by the movie and then

03:55.680 --> 03:58.500
by the similarity strength of all the similar movies to it.

03:58.500 --> 04:02.370
And there's my results for people who liked, also liked

04:02.370 --> 04:05.220
or people who rated this highly also rated this highly

04:05.220 --> 04:06.538
and so on and so forth.

04:06.538 --> 04:08.910
And like I said, that's just one way of doing it.

04:08.910 --> 04:09.960
So that's sort of step one

04:09.960 --> 04:11.640
of item based collaborative filtering.

04:11.640 --> 04:14.010
First, I find relationships between movies

04:14.010 --> 04:16.349
based on the relationships of the people who watched

04:16.349 --> 04:19.680
every given pair of movies.

04:19.680 --> 04:22.545
It'll make more sense when we go through the example.

04:22.545 --> 04:24.600
So for example, let's say that

04:24.600 --> 04:26.680
our nice young lady here

04:27.533 --> 04:29.970
watched Star Wars and Empire Strikes back and

04:29.970 --> 04:30.900
like both of them.

04:30.900 --> 04:33.660
So rated in both five stars or something.

04:33.660 --> 04:35.550
Now along comes Mr. Edgy, Mohawk Man,

04:35.550 --> 04:38.580
who also watched Star Wars and the Empire Strikes Back

04:38.580 --> 04:39.771
and also like both of them.

04:39.771 --> 04:42.660
So at this point, we can say there's a relationship

04:42.660 --> 04:44.310
there's a similarity between Star Wars

04:44.310 --> 04:46.320
and the Empire Strikes back based

04:46.320 --> 04:49.020
on these two users who like both movies.

04:49.020 --> 04:51.630
So what we're gonna do is look at each pair of movies.

04:51.630 --> 04:55.094
We have a pair of Star Wars and Empire Strikes Back

04:55.094 --> 04:57.090
and then we look at all the users

04:57.090 --> 04:59.377
that like, that watched both of them

04:59.377 --> 05:00.990
which are these two guys.

05:00.990 --> 05:02.100
And if they both like them

05:02.100 --> 05:04.170
then we can say that they're similar to each other

05:04.170 --> 05:05.430
or if they both dislike them

05:05.430 --> 05:07.216
we can say they're similar to each other, right?

05:07.216 --> 05:10.386
So we're just looking at the similarity score

05:10.386 --> 05:12.690
of these two users' behavior related

05:12.690 --> 05:15.360
to these two movies in this movie pair.

05:15.360 --> 05:19.585
So along comes Mr. Mustache-y, lumberjack hipster man,

05:19.585 --> 05:22.320
and he watches The Empire Strikes Back,

05:22.320 --> 05:24.630
and he lives in some strange world where

05:24.630 --> 05:27.030
he watched the Empire Strikes back, but had no idea

05:27.030 --> 05:29.520
that Star Wars the first movie existed.

05:29.520 --> 05:30.600
Well, that's fine.

05:30.600 --> 05:33.990
We competed a relationship between the Empire Strikes Back

05:33.990 --> 05:36.750
and Star Wars based on the behavior of these two people.

05:36.750 --> 05:39.450
So we know that these two movies are similar to each other.

05:39.450 --> 05:42.900
So given that Mr. Hipster Man, like the Empire strikes Back,

05:42.900 --> 05:44.700
we can say with good confidence that he would also

05:44.700 --> 05:47.692
like Star Wars and we can then recommend that back to him

05:47.692 --> 05:50.681
as his top movie recommendation.

05:50.681 --> 05:53.040
So you can see you end up with very similar results

05:53.040 --> 05:53.940
in the end, but we've kind of

05:53.940 --> 05:55.020
flipped the whole thing on its head.

05:55.020 --> 05:57.270
So instead of focusing the system on

05:57.270 --> 05:59.010
relationships between people

05:59.010 --> 06:01.925
we're focusing them on relationships between items.

06:01.925 --> 06:04.080
And those relationships are still based

06:04.080 --> 06:07.380
on the aggregate behavior of all the people that watch them.

06:07.380 --> 06:09.150
But fundamentally, we're looking at relationships

06:09.150 --> 06:12.522
between items and not relationships between people.

06:12.522 --> 06:14.078
Got it.

06:14.078 --> 06:15.960
All right, so let's do it.

06:15.960 --> 06:19.320
We actually have some Python code that will use Pandas

06:19.320 --> 06:20.790
and all the various other tools

06:20.790 --> 06:23.241
at our disposable to create movie recommendations

06:23.241 --> 06:25.733
with a surprisingly little amount of code.

06:25.733 --> 06:28.230
So the first thing we're gonna do is show you

06:28.230 --> 06:30.030
item based collaborative filtering and practice.

06:30.030 --> 06:33.840
So we'll build up people who watched, also watched basically

06:33.840 --> 06:35.760
You know people who rated things highly.

06:35.760 --> 06:37.050
Also rated this thing highly.

06:37.050 --> 06:39.480
So building up these movie to movie relationships.

06:39.480 --> 06:40.650
And we're gonna base it on

06:40.650 --> 06:43.020
real data that we got from the movie lens project.

06:43.020 --> 06:45.720
So if you go to movielens.org, there's actually

06:45.720 --> 06:47.550
an open movie recommender system there

06:47.550 --> 06:48.720
where people can rate movies

06:48.720 --> 06:50.791
and get recommendations for new movies

06:50.791 --> 06:53.520
and they make all the underlying data publicly available

06:53.520 --> 06:54.780
for researchers like us.

06:54.780 --> 06:57.780
So we're gonna actually use some real movie ratings data.

06:57.780 --> 06:58.710
It is a little bit dated

06:58.710 --> 07:00.660
it's like 10 years old, so keep that in mind.

07:00.660 --> 07:02.490
But it is real behavior data that we're gonna be working

07:02.490 --> 07:03.840
with finally here.

07:03.840 --> 07:06.006
And we will use that to compute similarities between movies

07:06.006 --> 07:08.430
and that data in and of itself is useful.

07:08.430 --> 07:09.510
You know, you can use that to say

07:09.510 --> 07:11.610
people who liked, also liked, right?

07:11.610 --> 07:14.220
So let's say I'm looking at a webpage for a movie.

07:14.220 --> 07:15.510
I can write there and then and there.

07:15.510 --> 07:17.100
Say if you liked this movie,

07:17.100 --> 07:18.360
given that you're looking at it,

07:18.360 --> 07:19.590
you're probably interested in it

07:19.590 --> 07:21.090
you might also like these movies.

07:21.090 --> 07:22.890
And that's a form of a recommender system right there.

07:22.890 --> 07:24.863
Even though we don't even know who you are.

07:25.860 --> 07:27.900
Now it is a real, it is real world data.

07:27.900 --> 07:30.600
So we're gonna encounter some real world problems with it.

07:30.600 --> 07:33.030
Our initial set of results aren't gonna look good

07:33.030 --> 07:33.930
so we're gonna spend a little bit

07:33.930 --> 07:35.940
of extra time trying to figure out why,

07:35.940 --> 07:37.290
which is a lot of what you spend your time doing

07:37.290 --> 07:38.730
as a data scientist.

07:38.730 --> 07:40.110
Correct those problems and go back

07:40.110 --> 07:42.600
and run again until we get results that make sense.

07:42.600 --> 07:44.430
And finally we'll actually

07:44.430 --> 07:47.546
do user item based collaborative filtering in its entirety

07:47.546 --> 07:49.920
where we actually recommend movies

07:49.920 --> 07:52.735
to individuals based on their own behavior.

07:52.735 --> 07:55.170
So let's, let's do this.

07:55.170 --> 07:56.073
Let's get started.

07:57.690 --> 07:59.430
So that's item-based collaborative filtering.

07:59.430 --> 08:02.147
A wonderful idea thought up of people much smarter than me,

08:02.147 --> 08:05.160
um, but you know it did have its origins at Amazon,

08:05.160 --> 08:05.993
which is kind of cool.

08:05.993 --> 08:07.890
As you can see, it addresses a lot of the shortcomings

08:07.890 --> 08:09.840
of user-based collaborative filtering

08:09.840 --> 08:11.070
and it works out really well.

08:11.070 --> 08:12.660
So let's actually put it into practice

08:12.660 --> 08:15.310
and start writing some Python code to make it happen.
