All right.
And that's it. Right.
This is the code to split the data set into the training set in a dataset.
Let me zoom out a bit so that you can see it.
All right. So that's the full code.
This will return indeed these four new sets
composed of the training set in X and Y train.
And the test set in X and y tests.
Let me show you this right away.
So we're going to add four new code cells here.
Right.
And we're going to print each of these created sets.
So first we're going to print X train.
Let me copy this.
Then we're going to print X
test.
Then we're going to print Y train.
And finally we're going to print Y test.
Perfect.
All right. So now let's execute everything.
Starting with this cell here splitting the dataset into training and test it.
Done. Perfect. Run successfully.
Now let's run the cell to print X train.
And as you can see, indeed we have now eight observations in this training set.
Right 12345678
which correspond to eight customers taken randomly from this data set.
And we clearly recognize the features here with first the three columns being that
one hot encoded variables that encode the country categorical variable.
We also call that dummy variables.
Then we clearly have here the age as the second
variable as a second feature, you know, and then the salary.
So we clearly have a great matrix of features for the training set.
All right. Perfect.
Now let's print X test.
So we'll get here two observations containing the same features
here as here right.
This is the matrix of features still.
So we have the dummy variables here in the first three columns.
Then the age and the two salaries of our two customers
taken randomly from the data set into this test set.
Then Y train.
So here we'll get eight purchased decisions right with the zeros
and ones here that were encoded before with label encoder.
And of course make sure to understand this.
These eight purchase decisions correspond of course to the eight
same customers of this matrix of features X train of the training set right.
These features correspond to these purchase decisions.
These are the same customers here.
And finally Y test which will output two results
meaning two purchase decisions right zero and one corresponding
of course to the same customers as in this matrix of features of the test set.
All right. So there you go. Congratulations.
Now you have a new tool in your data preprocessing
toolkit splitting the data set into the training set and data set.
Not only you have this tool,
but also you have the final answer to the ultimate question.
Do we have to apply feature scaling before or after the split?
And it's clearly after the split to avoid indeed information leakage
because simply the test set is supposed to be something
you write something on which we evaluate our model on you.
Observations. All right. Great.
So I'm glad that you are really making progress here with new tools
and new knowledge that actually reduce any kind of confusion.
So now we're going to move on to our final tool right,
feature scaling, which now you know, must be applied after the split.
And you will see what
we'll get with some other prints after we deploy this tool on our data set.
So I can't wait to show this to you.
And I can't wait to give you this last final tool in your toolkit,
because then what does it mean?
That means that we will be 100% ready
to start building our future machine learning models.