1
00:00:11,650 --> 00:00:16,870
In this lecture we are going to answer a very common question I get which is how do I use the train

2
00:00:16,870 --> 00:00:20,370
model to make predictions before we start this lecture.

3
00:00:20,380 --> 00:00:25,560
I want to say that this should be completely possible using only what you've learned so far.

4
00:00:25,630 --> 00:00:30,670
You should be able to apply what you've learned to do this since no new code is necessary.

5
00:00:30,670 --> 00:00:35,740
You have all the tools you need so if you would like to stop this video and try on your own I would

6
00:00:35,740 --> 00:00:37,660
strongly recommend doing so.

7
00:00:38,050 --> 00:00:43,690
To start first recognize that we are in a separate VIP notebook which you can find in the VIP notebooks

8
00:00:43,690 --> 00:00:44,920
document.

9
00:00:45,070 --> 00:00:49,450
Once you've reached the notebook we are going to scroll all the way down to where we plot the last per

10
00:00:49,450 --> 00:00:50,280
iteration.

11
00:00:50,380 --> 00:00:52,570
Since this is where our new work begins

12
00:01:01,130 --> 00:01:06,980
the first step here is to think about which movies do I actually want to make predictions for to make

13
00:01:06,980 --> 00:01:07,550
this simple.

14
00:01:07,550 --> 00:01:12,140
Let's suppose we want to make predictions for the user with user I.D. one.

15
00:01:12,650 --> 00:01:18,200
Well we of course only want to recommend movies that user one has not watched and in order to do that

16
00:01:18,530 --> 00:01:24,090
we first have to figure out what movies User 1 has watched in order to calculate this.

17
00:01:24,110 --> 00:01:29,770
We first need to select all the rows in the data frame where new user I.D. is one.

18
00:01:29,780 --> 00:01:37,630
Next we grab the new movie I.T. column and then call dot values to get this as a num pi array in the

19
00:01:37,630 --> 00:01:38,200
next block.

20
00:01:38,200 --> 00:01:42,010
I've printed out all the movies that user 1 has rated so you can have a look

21
00:01:49,140 --> 00:01:49,990
in the next block.

22
00:01:50,010 --> 00:01:56,160
We need to find the movies that user one has not rated which I'll call potential movie ideas in order

23
00:01:56,160 --> 00:01:57,110
to find these.

24
00:01:57,210 --> 00:02:03,480
We need to make use of the IS in function and panders by using the tilde in front of the IS in function

25
00:02:03,480 --> 00:02:04,110
call.

26
00:02:04,140 --> 00:02:10,170
We are basically saying find all the rows where the new movie idea is not in the array watched movie

27
00:02:10,170 --> 00:02:11,160
ideas.

28
00:02:11,520 --> 00:02:17,520
After selecting these rows we do dark new movie idea to get the movie ideas column and then we call

29
00:02:17,520 --> 00:02:24,790
the unique function since obviously there will be multiple users who have watched the same movies.

30
00:02:24,960 --> 00:02:26,820
Next we check how many movies there are.

31
00:02:26,820 --> 00:02:30,710
That user 1 has not rated and it's about twenty six thousand.

32
00:02:30,750 --> 00:02:36,510
Of course we expect this number to be close to the total number of movies for all users unless of course

33
00:02:36,510 --> 00:02:40,020
there's someone out there who does nothing but watch and rate movies all day.

34
00:02:40,020 --> 00:02:45,900
This is going to be the case by the way this array of potential movie ideas forms one of the inputs

35
00:02:45,900 --> 00:02:47,310
into our model.

36
00:02:47,580 --> 00:02:52,080
As you know the other input is just the user I.D. which should be one for every movie

37
00:02:56,180 --> 00:03:01,940
so in order to get an array like that we want to use the ones like function to create an array of ones

38
00:03:01,940 --> 00:03:04,530
with the same shape as the movie at.

39
00:03:04,700 --> 00:03:09,020
As an exercise you might want to think about how you would do this if you wanted to make predictions

40
00:03:09,140 --> 00:03:11,760
for a different user I.D. say user right.

41
00:03:11,770 --> 00:03:15,170
10 obviously there's no such function as towns like

42
00:03:18,910 --> 00:03:24,430
the next step is to convert our data into torch tenses and move them to the GP you which I'm sure you

43
00:03:24,430 --> 00:03:26,390
know how to do by now.

44
00:03:26,470 --> 00:03:31,720
The next step is to pass these inputs into our model and assign this to a variable called predictions

45
00:03:37,790 --> 00:03:38,590
in the next block.

46
00:03:38,600 --> 00:03:44,030
We convert our predictions into a numb pie array and we also flatten them since we want to 1 the array

47
00:03:44,060 --> 00:03:45,980
and not a 2D array.

48
00:03:46,010 --> 00:03:51,900
The next step is to sort our predictions in descending order since we actually want the sort index.

49
00:03:51,980 --> 00:03:54,530
We can use the ARG sort function.

50
00:03:54,530 --> 00:04:05,850
We also have to make sure that we negate the predictions since the Argonaut function sorts ascending.

51
00:04:05,890 --> 00:04:10,870
Next I print the predictions and the sword index just for your information and because it's a nice sanity

52
00:04:10,870 --> 00:04:11,380
check.

53
00:04:17,280 --> 00:04:21,150
Finally let's suppose I want the top 10 predictions for this user.

54
00:04:21,300 --> 00:04:26,580
All I need to do is take the first 10 elements of the sort index which tells me where those movie ideas

55
00:04:26,580 --> 00:04:29,430
are located in my input array.

56
00:04:29,430 --> 00:04:33,740
I can also index the predictions array to get the corresponding scores.

57
00:04:34,050 --> 00:04:39,240
Next I use a for loop to loop through the top 10 movies and their scores and I prints out the result

58
00:04:39,420 --> 00:04:46,170
inside the loop as you can see we do in fact get a list of movies with scores sorted in descending order.
