‫In this video we will learn how to split the available data into test and train said then we will train
‫the model on the training set and find the means squared error of the test said
‫to split the data into test and.
‫I prefer to install this package or what other method this package is called C IT tools.
‫You know how to install a package.
‫You can just trade in starter dart packages
‫and within Blackboard and double quotation marks right.
‫See tools and be of tool just capital
‫on this.
‫You can see on the right see tools is now available.
‫We'll just take this checkbox to make this available.
‫Now we are going to set a seed.
‫The concept of setting seed is that when splitting the data into a distant train I'll be doing it randomly
‫but if I set the seed at a particular value and you said the same seed at the same value we both will
‫get the same split.
‫That is the observation in the training set which I will hit you will get the same observation in your
‫training set so we'll set the seed at 0.
‫So relate said Dot seed again and within the bracket we will write 0
‫within Baghdad relay detail will run this so we'll see this attack 0.
‫Now we will split the data we'll write split is equal to sample dot split
‫and within a decade will write B if comma split ratio is equal 2.8 the S and the odds of split ratio
‫are capital X this to a new variable called Split is created and it has true and false value for each
‫of the observation we will assign through to the training set and the values that follows will assign
‫a two day set so training set is equal to
‫and thus will set is equal to subset
‫it's a subset of B if so be it comma split
‫equal to equal to true.
‫So we're checking wherever the split values true we take out that subset of the EV and put it into the
‫training set variable so you can see training set variable is also created it has 378 observations it
‫will not tell exactly 80 percent of the observations but merely whichever one you mentioned in the split
‫ratio you will have nearly those number of observations and what the remaining values will assign them
‫to test it.
‫So test underscore said
‫is equal to subset and within that get the F comma split equal to equal to False
‫on this so best said video is also created.
‫Now let we run a linear model on the training data set.
‫We know how to run a linear model for that will create a variable elem underscored a and this is equal
‫to a limb within bracket will.
‫But I use data dot
‫comma data is equal to training set.
‫We are not running this model on the complete data that we have.
‫We are running it only on the 378 observations in the training set.
‫So let's run this.
‫The model is fit in the 11:00 dress code 8.
‫If you want to look at this somebody you can date somebody and we can record eleven elements for a.
‫But here we are going to find out the mean square error of the training set and it's set.
‫So to find means grid errors we need to first predictive value of trace basis.
‫This fitted model to predictive value.
‫We use a function called predict the predict function takes two parameters.
‫One is the model that we have fitted which is a limited story.
‫And the other is the data which is to be used to predict the values of a So we get the predicted values
‫of the training set into a variable called Train underscored a will rate train underscored a is equal
‫to predict and within bracket the first parameter will be element underscoring the city for that model
‫comma.
‫This is the data.
‫So this the training data will guide training underscored said.
‫So what this will do is it will take all the independent variables from this it put it into this model
‫and predict the value of the independent variable and stored it and to train underscored it.
‫So let's run this.
‫So we have train underscored a as another variable will do this same thing for the test it also just
‫in place of train will test
‫to will get the predicted value of house price for our test data also.
‫Now the means where error is the average of difference all the squares of these predicted values and
‫the actual values so to get that average will right mean
‫and within brackets we have to square the differences of these.
‫So it is a difference of training underscore said dollar price.
‫So these these are the actual values minus the predicted values which are trained underscored a
‫and we want to squared these values.
‫So we'll put another bracket under
‫I will square this difference and run this so twenty point six six is the mean squared error on the
‫printing data.
‫So on an average squared distance of the predicted values and the actual values on the training data
‫is twenty point six six.
‫Let's do this.
‫Body tested also
‫will use the best set dollar price
‫minus test underscored a
‫so.
‫Since this test data is previously unseen most probably our model will not work as well on this data.
‫The main square error is today 3.0 4 which means it is performing worse on the unseen data.
‫This is as discussed in these two electives also.
‫So this is all we split the data into tested and a train set in.
‫Are we then done the model on the training set and using the model created on the training set will
‫predict the values of the test dependent variable.
‫We then find the estimated error on this test data.
‫This estimated error is to be used when we are comparing different models.