And now let's implement this new step.
Feature scaling.
But just before
since we're going to apply a lot of transformations on both x and y.
Well we're going to do some print to see the before and after the transformation.
All right.
So let's create two new code cells here.
Let's first do a print of the matrix of features X.
Then a print of the dependent variable vector y.
Now we're going to run this cell to print x.
And x contains of course in a 2D array.
As you can see with a double pair of square brackets all the position level
is going from 1 to 10. So that was all the expected.
Then let's print y which will this time containing a one
dimensional vector all the salaries corresponding to these position levels.
So all good there.
But now we will have to do a first transformation.
And I'm not even talking about feature scaling.
That first transformation will be to reshape
this y into actually an array.
You know, a two dimensional array
where you have same the salaries displayed vertically.
And so now the question is why do we want y to have such a format,
you know, into 2D array.
Well that's because you know, the standard scalar class that will perform
standardization meaning feature scaling expects
one unique format in its input.
You know, when you apply the fit transform method, which is a 2D array,
if you input here a one dimensional vector like what we have here,
this will return an error simply because, well,
this standard scalar class expects a 2D array as its input.
So now we just have to transform this into a 2D array.
And you actually know exactly how to do that because we already did it.
I'll give you a hint.
This was in the multiple linear regression section.
And so now well of course I would like you to press pause on this video
and try to transform Y or, you know, reshape y into this
2D array with the salaries displayed vertically.
All right.
So we're going to create a new code cell to do this.
And so well first we want to update y.
And therefore you know we will start with this y equals.
And then we'll do the necessary transformation to return this new y.
And so how do we do this.
So the first thing to do is to take y again from which
we're going to call that reshape shape function into which we're going to input.
Well you know the new shape that we would like y to have.
And remember how we have to enter this new shape.
Well we have to input here two elements.
The first one being the number of rows of this new y.
You know, this new format of y we want to have.
And then the number of columns.
So that's easy since we want to have the salaries displayed
vertically, you know, in different rows actually.
Well what we want to have for the number of rows is of course Len of y.
You know, the length of y,
meaning the number of elements in y, meaning the number of salaries.
Okay. So that's the number of rows.
And then the second element here is the number of columns.
And of course we want one column
because we want to display the salaries vertically in a 2D array of course.
And therefore here we input one as in one column.
So we're going to have actually since we have ten salaries
we're going to have ten rows and one column.
Okay. So it was good to do it again.
Now you become more familiar with this reshape trick.
Okay.
And now of course
we're going to print this to see and to check that everything's all right.
And mostly that we have the right format expected by this
standard scale class, which we'll use then to apply feature scaling.
So there we go. Print y.
And let's first execute this to reshape y.
And now let's print y to check two things that first we have a 2D array.
We can clearly see that with the double pair of square brackets.
And also the salary is displayed vertically
just like this matrix of features, which is also a 2D array of course.
All right.
So now everything's perfect.
We're ready to apply feature scaling.
And so we're going to do that right away starting by
creating a new code cell here.
All right.
So now how are we going to do this efficiently.
We always want to be efficient when we code.
So of course we're going to grab our tool in our data preprocessing toolkit.
I'm talking of course about the feature scaling tool.
And we'll have to adapt this a bit
because this was applied on the training and test sets.
But no worries, we will adapt it very quickly and efficiently.
So I'm copying this and I'm pasting that right here and now.
Of course I would like you to please press pause again
and try to figure out on your own what we have to modify here
to make this feature scaling work for situation.