In this video, we are going to split our data into test and train.
We do this so that we can see the performance of our model on previously unseen data.
So we will train the model using the train part of the data and we will test its performance on the
best part of the data.
Usually we split the data in the nation of 80 is to guarantee, meaning that we will use 80 percent
of the data to train the model.
And that is 20 percent of the data will be used to test its performance.
To do this train split an hour.
This is the code that you need to run.
First, we need a package called C Études if it is installed in R.
You do not need to run this command.
If it is not, you have to run in Stalder packages and within inverted commas, you have the right tools.
The D of tools is capital.
Once this package will be installed, you need to run library, see your tools.
What does basically buzzer's if you go to the packages part?
It is showing all the packages that are installed, but this check box is on right now.
That is, you cannot use your tools.
As of now, if you want to use your tools in this cord, you have to take it or run library, çehre
tools command.
So either they get hit or run this command.
Once the Seer Tools package is ready for use.
We will ride these four lines.
The first line is set seed setting seed is done so that we have reproducibility of the data.
That is, if I said, see that zero and you also said seed at zero.
When we are randomly selecting 80 percent of the data to be trained, data that randomly selected 80
percent of data will be same for me and same for you.
So if we do not certain seed, you get a separate set of observations in 80 percent of my data.
Which I will use to train the model and thus I will get a different model than the model that you will
get with your 80 percent of the data.
So setting seed ensures that both of us get the same split.
So we'll run the court this line.
Posters and installer packages, although, see it all was already installed in my system.
It will again go and reinstall it.
Then library doors see it also then.
And we have taken on this check box.
Then a wohlstetter deal.
Next is to create a new variable.
Goit split.
This very well will be created on the movie, does it, meaning that it will have the same number of
observations as the movie did, does it?
And we have a split ratio of point eight, which means that 80 percent of the data in this played variable
will have value.
True.
And remaining 20 percent will have value falls.
So if we run this line of code.
A new variable split is created.
It has values, falls through, falls through.
And so on.
And we have 506 such observations.
Not very ever split values, true, which is for nearly 80 percent of the time.
Wherever this value is true, we will put that observation into the train set and wherever this is false
will put that observation in the desert.
So when I on this call, I'll get a new dataset called Dream.
And it has 393 observations, which is nearly 80 percent, not exactly 80 percent.
But nearly percent.
And then we have this set which will have the remaining 20 percent of the observations.
So now this train very well, this train dataset, which has 393 observations.
This will be used to bring the model.
That is to make that decision tree.
Once that decision tree is created, we will check its performance on the test set.
That is, we will predict the value of collection variable for the test.
And we will compared the actual value with the predicted value of this variable.
This is all we split the data into test and bring in our.