All right, here we go for that final step.
Predicting the salary of the position level 6.5
with both linear regression and polynomial regression.
So we're going to start with
linear regression first therefore creating a new code cell here.
Let's do a step by step.
Of course the first step you had to do here was to take your linear
regressor object, you know, from the simple linear regression model.
And this object was named Lin Regge.
This one.
And then very simply from this object
you're going to call the predict method
to predict the salary of the position level 6.5.
All right.
So what exactly do you need
to input here in this brick method to get such a predicted salary?
Well I'm sure some of you try to directly input 6.5,
but unfortunately this is not that simple because indeed
you always have to input your observations in an array, right?
That's what is specified here in the parameters.
The input of the brick method should be an array like or a sparse matrix.
So an array like this for example a numpy array or a simple array
with double pair of square brackets.
Well you know I said it.
That's exactly how you need to input an array.
Because generally in Python an array is built with pairs of square brackets.
If you add just a single pair
of square brackets here, well that actually creates a list.
Or you can also see it as a vector.
But in order to create an array, well, you know, an array contains
several dimensions like two dimensions in our case here.
And therefore you need to add a double pair of square brackets.
What does this double pair of square brackets mean?
Well, the first pair of square brackets here corresponds to the first dimension,
and the second pair of square brackets here corresponds to the second dimension.
So the first dimension is actually corresponding to the rows in your array,
and the second dimension is corresponding to your column.
So for example, if I add just to show you, if I add for example five here,
that would create actually an array of one row and two columns.
And if I add here a comma and then another pair of square brackets,
and then for example two and three, well this would
create indeed an array of two rows and two columns.
In the first row you would have 6.5 and five.
And in second row you would have two and three.
So you see the first square bracket here corresponds
to the rows and the second one corresponds to the columns.
All right.
So let's go back to where we were exactly this.
So this indeed is exactly the format expected by this break
method an array of two dimensions.
Even if this only contains one cell, you know one value.
Well, it has to be in this format.
And now while you're ready to get that prediction.
So before we execute this, let's remember that
this person asked for a 160 K salary.
And this is justified by the fact that this person earned a 160
K salary in the previous company, which is what we have to check right now.
And we're going to check that first with the linear regression model,
which returns indeed a salary of $330,000 per year.
So if we actually use this model to negotiate with that person,
we would actually find it super weird, right?
Because this predicted salary is way over
the real salary that this person had in its previous company.
So clearly the prediction here is wrong.
And, you know, that's what we can clearly see on the graph.
You know, the graph above showing the results of the linear
regression model 6.5 is somewhere around here.
And indeed, if we want to get the prediction,
we have to project it to that blue regression line and then projected
again to the vertical axis, which is around here.
And indeed that's what we get.
You know, this is multiplied by ten to the power of six.
So indeed we get something around 330.