Okay, so now we imported the K-12 library.
That is going to make a good split
of the data set into the training set and the test set.
So now let's make the split.
So remember in Python, for those of you who followed the Python tutorial
we used random state equals zero so that we get the same results.
Well here it's going to be the same.
We're going to set a seed to have the same results.
Only we're going to do it now. We're not going to wait
to be in the function in the library that makes this split.
So to do it we have to set the same seed.
And so we can type set dot seed.
And in parenthesis we can choose any number we want.
It can be this number.
You know that's the seed.
If we both choose this number will have the same results.
But let's choose a more simple number.
Let's just for example one two, three.
And now let's make this split.
It's not as simple as in Python where we make it in one line.
Here we're going to have to prepare the method that we are going to call split.
That is the method that is going to make
the split of your data set into the training set, and the test set equals
and then sample
dot split
okay.
Now if you want we can press F1 to see what we have to input.
Okay.
So it's simply split split data into test and train set.
Let's see the arguments.
The first argument is why.
So that's not the same argument that we had to put for Python.
In Python
we had to put both the matrix of features x and the dependent variable vector y.
Here we only have to put y only we're going to take y the following way.
We're going to type data set dollar sign purchased.
Because your dependent variable is purchase okay.
So that's okay for the first parameter.
And then what is the second parameter.
It's split ratio okay.
So split ratio let's write split ratio here.
And so split ratio is just a percentage
of the observations that you want to put in your training set.
So let's be careful.
In Python we put the percentage for the test set.
And here we have to put it for the training set.
So remember in Python we chose 20% for the test set.
So here logically for the training set we will choose 0.8 okay.
So what we'll do split return.
So it will return true or false for each of your observations.
That means that each observation will have either true or false.
And this is going to be true
if this observation was chosen to go to the training set,
and false if the observation was chosen to go to the test set.
So let's have a look. Let's select this
command or Control plus enter to execute.
And here it is. We have the split here.
So now let's go to the console and write split.
All right. Enter.
All right.
You see that you have ten values.
And so true means that the observation goes to the training set.
And false means that the observation goes to the test set okay.
So now what we have to do is to create the training set
and the test set separately.
So we're going to do this.
We'll type training set which is going to be the name of our training set.
Actually let's make it simple.
So training set equals subset parenthesis.
And here is the first argument we put data set
because it's the training set is a subset of the data set.
And here we will specify
that we want the split equals equals true.
And that's it okay.
So that's it for the training set.
Now let's copy this line.
Paste it here.
And here we're going to change training set to test set.
And of course we're going to change split equals equals true
to false.
Because the test set are the observations for which the split equals false.
And now we're ready.
We are ready to make the splits
of the data set into the training set and the test set.
So let's execute these lines command and control.
Plus enter to execute.
And here we go.
Test set and training sets are created.
Let's look at them.
So let's click on the training set here.
And the test set.
Let's move that here and that here okay.
Let's look at the training set first okay.
We see that we have eight observations okay good.
And now let's look at the test set.
Now we can clearly see that we have two observations with six and nine perfect
okay.
So that's it for this tutorial.
You now know how to split your data set into a training set and a test set.
This is a must do in any machine learning model.
You have to test
the performance of your machine learning model into a separate test set.
So congratulations!
Now you are almost ready
to begin the journey of making exciting machine learning models.
We just have one thing to do left feature scaling.
You'll understand in the next tutorial why it's so important to do this.
So I look forward to seeing you there.
And until then, enjoy machine learning.