Hello and welcome to this
almost final tutorial of the part one Data Pre-processing.
I look forward to being well-prepared with our data to start making our machine
learning models. It's going to be very fun.
We just have to hold on for two more tutorials and then we're good to go.
Okay, so today we're going to talk about feature scaling which is very important
in machine learning.
I'm going to explain you why right now.
So I'm going to go to Google Sheets to find our data set.
And here it is.
Let's explain what is feature scaling and why we need to do it.
Okay.
So as you can see we
have these two columns age and salary that contains numerical numbers.
Let's just focus on the age and the salary.
You notice that the variables are not on the same scale, because the age
are going from 27 to 50,
and the salary is going from 40 K to like 90 K.
So because this age variable and the salary variable don't have the same scale,
this will cause some issues in your machine learning models.
And why is that.
It's because you're machine learning models.
A lot of machine learning
models are based on what is called the Euclidean distance.
If you remember that back
from high school, the Euclidean distance between two data points between two points
is the square root of the sum of the squared coordinates.
Well, actually here it's the same.
We have two variables age and salary.
So you can picture age as the x coordinate and the salary as the y coordinate.
And in the machine learning models equations
sum Euclidean distances between observation points.
For example, this one and this one are computed based on these two coordinates.
And actually, since the salary has a much wider range
of values, it's because it's going from 0 to 100 k.
The Euclidean distance will be dominated by the salary.
Because, for example, if we take two observations, for example,
the this one, the ninth one and the third one, well the Euclidean
distance will compute the difference between this salary and this salary.
So let's compute it. That's about
okay.
So this is
this one.
As you can see this is 31,000.
If you put that in square
okay.
Let's see up square that gives this.
And now let's take for the same two observations the edges.
So let's compute equals 48 minus.
It was this one right 27.
Okay. That's the difference.
And now let's take the square equals
this square 441.
So you can see very clearly how this squared
difference dominates this squared difference.
And that's because these two variables are not on the same scale.
So you know in the machine learning equations it will be like
this doesn't exist because it will be dominated by this.
So that's why we absolutely need to put the variables on the same scale.
That is that we are going to transform these two variables,
and they're going to have values in the same range.
For example they're going to have values from minus one to plus one here
and same here minus one to plus one.
So that we don't get this sort of problem with a huge number here
dominating a smaller number here,
so that eventually the smaller number doesn't exist.
There are several ways of scaling your data.
A very common one is the standardization, which means that for each observation
and each feature, you withdraw the mean value of all the values
of the feature, and you divide it by the standard deviation.
So that's the first type of feature scaling.
And another type is normalization which means that you subtract
your observation feature x by the minimum value of all the feature values.
And you divide it by the difference between the maximum of your feature values
and the minimum of your feature values.
Don't worry if you're not very comfortable
with the mathematics here, but what you need to understand is that we are
putting all variables in the same range, in the same scale,
so that no variable is dominated by the other.
Okay, so let's do it right now. Anyway.
You're going to see how the variables are going to be transformed.
You're going to see how they go from having large
and very different values to small and same values.
So let's move on to our.