All right, my friends,
I hope you did amazing with that new exercise, which was to predict
the purchase decision of a new customer in the data set that was the first customer
who is actually 30 years old and earns
an estimated salary of $87,000, right.
If we have a look at our test set,
you know, the original test before the scaling, this one,
this is exactly the customer you had to input in your predict method
in order to predict the purchased decision.
All right.
And now in this tutorial we're going to check two things
that first, you've got the right implementation of the predict method
and mostly the right input inside the brick method.
And secondly we will also check if the prediction is correct.
And in order to do this well we're going to have a look at why
test the purchase decision of that first customer is exactly this one.
You know because white test contains
all the real results here or the real purchase decision.
And so we're going to see if indeed our model was able
to make a correct prediction by predicting zero
for this first customer of age 30 and estimated salary 87 K.
All right.
Let's do this.
Let's proceed to the solution.
Here it is predicting a new result.
I will leave the training and there we go.
So let's create a new code sale.
And now what was the first step.
Well of course the first step was to take our classifier
because of course the predict method as any other method
has to be called from the classifier object itself.
So we take our classifier object.
And then from this object we're going to call this predict method.
By the way let me show you this again.
You have all the predict method
which are predict log probability which will return the log.
You know, the logarithmic function of the probability that your prediction is one.
You know that the purchase decision is one.
And you also have to predict proba method, which returns
of course directly the probability that the purchase decision is one.
All right.
So depending on whether you want to have directly the final prediction 0
or 1 or the probability that the dependent variable is equal to one,
well you have the choice between predict and predict proba okay.
So here we're going to take predict because we directly want to get the
prediction whether or not
that first customer of the test set purchased yes or no the SUV.
So here we're going to add some parenthesis.
And now now I'm really interested if you got this right,
what did you put inside the predict method in order
to predict the purchase decision of that customer who is 30 years old
and earns an estimated salary of 87,000?
All right, well, first of all, let's remind the essential
any single observation inside the predict method
has to be input in a double pair of square brackets.
Why is that?
That's because the predict method expects from
its input a two dimensional array.
And how do we create a two dimensional array with only one observation?
You know, meaning only one row?
Because what we're about input is a two dimensional matrix of one
row and two columns, where the row corresponding
to that single customer and columns correspond in fact to the feature
is the h in the first column and salary in the second column.
So there you go.
Now I've told you everything what you have to input here inside
this second pair of square brackets, which corresponds to the columns.
Well, you have to input the two values of these two features,
the age and the salary.
And therefore, since our first customer is 30 years old and earns
an estimated salary of $87,000,
well, the two features here that we had to input in these.
Therefore, two columns here is first 30
and then $87,000.
All right.
So that's the first thing you must absolutely do.
You know that you must absolutely have the right reflex.
Okay.
Input your single observation within a double
pair of square brackets to give the expected
format of the two dimensional array to your prediction method.
All right.
So that was the first thing. But then not enough.
You had to do something else which is
of course to scale that single observation.
Right.
Because 30 years old here and $87,000
as the estimated salary are in the original scale,
you know, before applying feature scaling standardization.
And since our model was actually trained,
as we can see, on X train and Y train, which were just previously
feature scaled, you know, that's the result of feature scaling.
Well, as I told you, the Predict method
can only be applied to observations where the features
have the exact same scale as the one that was used for the training.
And therefore here we need to apply the transform method
in order to give us word break method.
Not only the right format here, but also the right skill
and that's why we have to transform this single observation
input in the right format into that new skill.
And so what we have to do here is take our SC object.
Remember that was the name of the feature scaling object,
which we used to apply feature scaling on both the matrix of features
of the training set extreme and the matrix of features of the test set X test.
So SC and then remember we call
there it is just below the transform method.
The transform method which has to take as input this
whole single prediction input in a 2D array.
All right. In a second one. And perfect.