Hello and welcome back.
Today we've got an important tutorial.
We're talking about feature scaling.
Now before we dive into the technical aspects of feature scaling,
I would like to present you with an image that hopefully will help
you remember what feature scaling is applied to.
Now, even without
knowing anything about feature scaling, please remember that features killing
is always applied to columns, so feature scaling would be applied to this column.
To this column. To this column.
To this column.
Feature scaling is never applied across columns,
so you wouldn't apply feature scaling to data inside a row.
Just to remember.
Feature scaling is always applied to columns.
Now with that out of the way, let's have a look at what feature scaling
actually is.
So there are multiple types of feature scaling multiple techniques.
We're going to look at the two main ones.
normalization and standardization.
Normalization is the process of taking the minimum inside
a column, subtracting that minimum from every single value inside that column,
and then dividing by
the difference between the maximum and the minimum.
So basically every single value in a column is adjusted this way.
And you will end up with a new column or an adjusted column
with values which are all between 0 and 1.
Standardization, on the other hand, is the process is similar,
but instead of subtracting the minimum, we subtract the average
and we divide by the standard deviation.
As a result, all of the values, or almost all of the values inside
the column will be between -3 and 3.
if you have some extreme values or some outliers,
then they can end up outside of these minus three and three boundaries.
So that is normalization standardization.
In the practical tutorials with understand you'll be looking at standardization.
And for simplicity's sake
in these intuition terms we'll have a look at normalization.
So let's imagine we have a data set where we have two columns,
annual income of a person and their age.
Just two simple days with those two columns.
And again, for simplicity's sake, we're only going to have three rows.
We're going to have a blue person, a purple person and a red person.
Now here, is the data.
We have blue person making $70,000
a year and their age is 45 years.
purple person makes $60,000 a year and their age is 44 years,
and red person makes $52,000 a year, and their age is 40 years.
Now, the task at hand is going to be slightly different
to the regressions and, classifications that we've been discussing.
The task at hand is to,
see which of the two people
the purple person is most similar to, just based on this data.
Would you say that the purple person is more similar to the blue person?
Or would you say that the purple person is more similar to the red person?
this is, a this is more relevant for the,
clustering, tasks or clustering
algorithms that we'll be discussing in, the following section of the course.
But it is just such a simple illustrative example that we're going to use it here.
We're going to talk about it.
We're about here to show the importance of feature scaling.
So once again, if you'd like to pause this video please go ahead and try to see
would you group the purple person with the blue person,
or would you group the purple person with the red person?
And now let's have a look at it together.
So the let's look at the differences.
The difference here in salary is $10,000.
And here it is $8,000.
And in terms of age,
the difference between the purple and the blue person is one year.
And between the purple and the red person is four years.
Now, what can happen with unscaled features?
As we see here?
is that the values, the unit values,
of one column can be so much larger than the other that it might overpower.
So, for example, we can see that the values of 10,008 thousand
are much, much greater than the values of one and four.
So we might make the erroneous conclusion that, okay, we're going to ignore values
one four, because those are such small differences compared to 10,000, 8000.
We're going to focus on these large of magnitude numbers 10,008 thousand.
And out of them we'll say that the purple person
is clearly closer to the red person because,
that value is 8000.
It's $2,000 less or 2000 units less than,
the value, the difference between the purple and the blue person.
And as a result, we would group the purple person with the red person.
Now, we don't want
this or similar things happening in our algorithms.
and that's why we need to normalize variables,
because we can't compare right now when comparing salaries to years.
It's it's like comparing apples and oranges.
These are not non comparable things.
What if years was expressed not in years but in minutes.
Then those values would be much higher or in seconds would be even higher.
And even if you have the same units of measurement
like dollars and dollars into columns, they still might not be comparable
because they're relating to different things.
So it's important to scale your features.
And so let's apply normalization as a quick reminder.
This is what the formula for normalization is like.
So we're going to apply it to the columns one by one.
So we are applying it to the dollar column first after normal
after normalizing our values will look like this.
So let's go back for a second and go here.
So I'll let you pause this video if you'd like to do
the manual calculations.
This is, the result.
And once we apply it to the first column, our values will look like this.
Once again, from here we end up here.
And now we can compare like for like based on this image,
based on this data, which do you think the purple person is closest to?
Well, I think the answer is obvious.
The purple
person is almost right in the middle between the red and the blue people.
They're at 0.444, whereas in the H column
the purple person is closest to the blue person.
It's very clear.
So there we go.
That's a quick illustrative example, very simplistic but yet illustrative
example of feature scaling.
And I hope you enjoy seeing that together for the lunch in the practical tours.
On that note, I look forward to seeing you back here next time.
And until then, enjoy machine learning.