So here we are in.
And now that you understand feature scaling
let's apply it to the training set.
And the test set here we will just write two lines of code which are.
So the first line is training sets.
So two training sets already exists right.
It's this one. The training set.
As you can see it's not scaled.
These are
it contains the raw values.
So training set equals and simply.
Now we're going to write scale.
And then training set.
That's all that scales.
Your training set is in a grid.
And same for the test set.
We will copy this line.
Paste it here.
And we will change training into test.
And here as well.
Okay so here I just wrote this.
There is something important to understand.
This will be the feature
scaling block of code that we will be using in our template.
However let's see what happens when I select this code and execute it.
So let's select this execute
okay.
As you can see here I obtained two errors Eren.
Code means x must be numeric for the training set, and the test set.
Can you guess what the problem is?
The problem is that.
Okay, well, it tells us what the problem is.
It tells us that X must be numeric.
But what does that mean?
Well, first what is this x?
X is for this line of code, the training set.
And for this line of code the test set.
So let's forget the test set for a second.
And let's focus on the training set.
So x is the training set.
And it says that the training set must be numeric.
So let's look at our training set okay.
Well the training set looks numeric.
Right here we have numeric values numeric values numeric values numeric values.
But no actually there are two columns that don't have numeric values.
It's this one the country and this one purchased.
And you remember why?
Well, it's because before we had the country written in text
and the purchase column written in text with yes or no,
and we changed that by putting the categories as factors.
That's what we did here.
As you remember, data set country equals factor
of the different levels and labels and a factor.
And R is not a numeric number.
And when you apply the scale here x must be numeric.
That means that all the columns in x that is the training set must be numeric.
So this time we are going to
exclude the categories from the feature scaling.
We're not going to apply feature scaling on those columns.
So that's very simple.
All we need to do is to take the columns we're interested in
which are well the indexes of the column we want to scale which are indexes.
So indexes in R start at one.
So that's 123.
So that's the second and third index
we want to take to scale the age and the salary columns.
So two and three let's input it.
We need to specify here two column three.
And that gets what we want.
So now I'm going to copy this copy
paste it here.
Here.
And here.
All right. And now it's ready.
Let's have a look at the training set and the test sets.
Not scaled not scaled.
Let's go back to our code.
Let's select this.
And now we shouldn't get an error.
Come in a control percentage to execute.
Here we go.
It executed properly.
And now let's look at the training set.
All scaled properly. Perfect.
And the test set
all scaled properly perfect.
And now our data is ready to offer a good precision
and good accuracy and a fast work of the machine learning models.
And by that I mean that the machine learning models will converge rapidly.
Okay, so that's it for feature scaling.
Now you know how to apply features.
Getting to your data in Python in R congratulations.
And mostly congratulations because we did
all the required steps to preprocess our data.
Feature scaling was the last one
because the next tutorial will be about this data pre-processing template,
and I will just explain how we are going to use it in our machine learning models.
It's going to be very fast and practical, so we are done with the data
pre-processing.
Congratulations, you did the most difficult part
and now it's time to have fun.
It's time to start making the models and I can't wait to start them with you.
So thank you for watching this tutorial.
I look forward to seeing you on the next one.
And until then, enjoy machine learning.