All right.
So first let's start by importing the libraries.
That's easy. Done.
Next step we import the data set.
And we can now because we have the data set uploaded in our notebook.
So make sure to have it as well.
Okay. Now the data set is imported.
We have the matrix of features and the dependent variable vector y.
Good.
And now I'm going to do a print to show you the state of x.
You know what is X exactly at this stage.
So I'm going to do print x.
And I'm going to run this cell.
All right. And let's see what we get.
All right.
So indeed we get exactly the same columns as in this data set
with first R&D spend then administration spend and marketing spend and state.
Right.
We can clearly see that we get the same columns here in the same order.
All right. So that's the matrix of features.
All good.
Now I'm now going to show you the dependent viral vector
because that's obvious.
We're going to get the same profit.
But what I want to show you is what becomes x
after we encode the categorical data.
You know, and you can actually guess what it will become.
But you will see that the three columns resulting here from one
hot encoding will actually be placed at the beginning.
All right. So let's check it out.
Let's run the cell to indeed apply encoding categorical data.
And now let's create a new code cell in which we're going to print X again.
And let's run this cell to see what x becomes.
And there you go.
Exactly as I told you we have the same three first columns here.
So that corresponds to R&D spend that corresponds
to the administration spend and that corresponds to marketing spend.
But now instead of having this state column here, we indeed have these
three new columns at the beginning, including that state variable.
And we can actually see
what corresponds to what, you know, if we have a look at our data set.
Well, the first row has New York as a state.
And therefore New York was encoded as zero zero and one.
Then let's see as the second state of the second row,
you know, corresponding to the second store, we have California,
and therefore California was encoded as one zero and zero.
And finally, well, Florida was encoded as zero, one and zero.
All right. So that's the one hot encoding that happens.
And now all good.
We have a fully pre-processed data set.
And as I told you in part one.
But I'm going to say it again here because this is important.
We don't have to apply feature scaling.
Why? Because, you know, in the equation of the multiple linear regression,
you know, you have this coefficient
that is multiplied to each independent variable.
You know each feature.
And therefore it doesn't matter that some features have higher values than others,
because the coefficients will compensate to put everything on the same scale.
And therefore remember this in multiple linear regression,
there is absolutely no need to apply feature scaling.
And one last thing I would like to add as well,
because I know a lot of you ask this question, do
we need to check the assumptions of linear regression?
The answer is absolutely not, because I will explain
at the end of this part, you know, part two regression that whenever you have
a new data set and you want to experiment with some machine
learning models to figure out which one leads to the highest accuracy.
Well, even if your data set doesn't have linear relationships,
you can still try a multiple linear regression on it.
And if you know your data set doesn't have linear relationships, well,
your multiple linear regression model will just perform poorly, and therefore
it will get an accuracy lower than the accuracy of your other models.
So you will just not select the multiple linear regression model.
But you don't have to check the multiple linear regression assumptions.
It will just be a waste of time.
Really, I will show you at the end how you can so fast and so efficiently
try each of the models on your data
set and select very quickly the one that has the highest accuracy.
All right.
So I just wanted to be clear on that point.
Don't worry about the multiple linear regression assumptions.
If your data set has linear relationships then good.
Your multiple linear regression
will check the assumptions indeed, and will bring to you a high accuracy.
And if your data set doesn't have linear relationships, well, fine.
Your multiple linear regression just will perform poorly
and you will just take another model and that's it.
That's as simple as that. All right.
So now good.
We're done with data preprocessing.
We can therefore move on to the next step which is to train
the multiple linear regression model on the training set.
So take a little break here.
And as soon as you're ready to build your next machine learning model,
well join me in the next tutorial to tackle this.
And until then, enjoy machine learning.