2
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ If you take a randam sample, then the 3:7 ratio will approximately be kept, so in my opinion you do not have to correct, So I would take a random sample. $\endgroup$ – user83346 Sep 18 '15 at 17:41
1
$\begingroup$

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.

$\endgroup$
  • $\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. Rubin Sep 18 '15 at 13:40
0
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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 ?

$\endgroup$
  • $\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. Rubin Sep 26 '15 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$ – Yohan Obadia Sep 27 '15 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.