In this lecture we are going to answer a very common question I get which is how do I use the train
model to make predictions before we start this lecture.
I want to say that this should be completely possible using only what you've learned so far.
You should be able to apply what you've learned to do this since no new code is necessary.
You have all the tools you need so if you would like to stop this video and try on your own I would
strongly recommend doing so.
To start first recognize that we are in a separate VIP notebook which you can find in the VIP notebooks
document.
Once you've reached the notebook we are going to scroll all the way down to where we plot the last per
iteration.
Since this is where our new work begins
the first step here is to think about which movies do I actually want to make predictions for to make
this simple.
Let's suppose we want to make predictions for the user with user I.D. one.
Well we of course only want to recommend movies that user one has not watched and in order to do that
we first have to figure out what movies User 1 has watched in order to calculate this.
We first need to select all the rows in the data frame where new user I.D. is one.
Next we grab the new movie I.T. column and then call dot values to get this as a num pi array in the
next block.
I've printed out all the movies that user 1 has rated so you can have a look
in the next block.
We need to find the movies that user one has not rated which I'll call potential movie ideas in order
to find these.
We need to make use of the IS in function and panders by using the tilde in front of the IS in function
call.
We are basically saying find all the rows where the new movie idea is not in the array watched movie
ideas.
After selecting these rows we do dark new movie idea to get the movie ideas column and then we call
the unique function since obviously there will be multiple users who have watched the same movies.
Next we check how many movies there are.
That user 1 has not rated and it's about twenty six thousand.
Of course we expect this number to be close to the total number of movies for all users unless of course
there's someone out there who does nothing but watch and rate movies all day.
This is going to be the case by the way this array of potential movie ideas forms one of the inputs
into our model.
As you know the other input is just the user I.D. which should be one for every movie
so in order to get an array like that we want to use the ones like function to create an array of ones
with the same shape as the movie at.
As an exercise you might want to think about how you would do this if you wanted to make predictions
for a different user I.D. say user right.
10 obviously there's no such function as towns like
the next step is to convert our data into torch tenses and move them to the GP you which I'm sure you
know how to do by now.
The next step is to pass these inputs into our model and assign this to a variable called predictions
in the next block.
We convert our predictions into a numb pie array and we also flatten them since we want to 1 the array
and not a 2D array.
The next step is to sort our predictions in descending order since we actually want the sort index.
We can use the ARG sort function.
We also have to make sure that we negate the predictions since the Argonaut function sorts ascending.
Next I print the predictions and the sword index just for your information and because it's a nice sanity
check.
Finally let's suppose I want the top 10 predictions for this user.
All I need to do is take the first 10 elements of the sort index which tells me where those movie ideas
are located in my input array.
I can also index the predictions array to get the corresponding scores.
Next I use a for loop to loop through the top 10 movies and their scores and I prints out the result
inside the loop as you can see we do in fact get a list of movies with scores sorted in descending order.