I have data with binary response (default of a client). I want to split the data into training and testing sets. I have 300 default clients and 700 non default clients. When splitting, should I make sure that the training set keeps the same ratio 3:7 of defaults? Or can I simply take a random sample?
3 Answers
R's createDataPartition function from package caret does that for you. It would not necessarily keep the response in the same ratio, but would split your data with least bias.
-
$\begingroup$ My question was not how to do it (how to keep the ratio) but whether it is a correct way to analyse data. $\endgroup$– T. RubinSep 18, 2015 at 13:40
Yes, you can take a random sample.
As the difference between the two types is significant, a random sample would obey(almost) the same distribution.
You might want to read up on random sampling, for appreciating the concept and executing it with confidence.
If you want to be sure to keep a perfect ratio without introducing a selection bias, you could select respectively all the 1
values, sample it and select the quantity you want and do the same with the 0
values.
The ultimate question would be, what do you plan to do with your data once you've done the split ?
-
$\begingroup$ The reason for splitting is to develop the model (what covariates to use) and fit it on the training subset. Then I want to use the testing subset to check if the model predicts well. Anyway, I've done a random sample and the ration has remained almost the same (29.5 % : 70.5 %). I guess I can work with it. $\endgroup$– T. RubinSep 26, 2015 at 16:09
-
$\begingroup$ Yep, that's the simplest way and as your data set increase, the ratios are gonna be closer to the ideal one due to the Law of Large Numbers. My answer was provided in case that your sample is small to do a perfect ratio selection. $\endgroup$ Sep 27, 2015 at 12:39