# Should we balance the data set if the data is intrinsically unbalanced? [duplicate]

Say I want to predict the cancer rate(regression)/predict the whether a person has cancer or not(classification). The data intrinsically has few cancer patients/low cancer rate, say 1/200. And the data set is good and large enough, say more than 100,000.

Now the question is: should I use certain sampling strategy to balance the data before I apply any regression/classification algorithm?

From my perspective, the reason we need to balance the data is because the data we get doesn't follow the natural distribution, it's bad, like a 10/90 male/female. But right now, we have a good data which follows the natural distribution, should we balance the data?

I'm also wondering if things are different for classification versus regression. Though low cancer rate, is it still okay to do the regression without sampling?

Any high-level/detailed ideas are appreciated:)

Does an unbalanced sample matter when doing logistic regression?

Also, your setting is a classic setting where you would have high cost if you say someone does not have cancer, but in they fact they do.

• Thanks Tom! Adjusting the penalty is definitely a good advice! But I think it doesn't conflict with the sampling part, right? Aug 28, 2018 at 17:20

You should always use a sampling approach in logistic regression. When facing an unbalanced dataset, which means there is a huge size difference between the event (response, positive..) vs non-event (no response, negative...) data. When the target event is rare, a representative sample is unlikely to have enough target events to build a good predictive model. Fortunately, the amount of information in a data set with a categorical outcome (such as a response to a marketing campaign) is determined not by the total number of cases in the data set, but by the number of cases in the rarest outcome category.

1. Oversampling

One approach is to oversampling. While oversampling reduces analysis time, it also introduces some biases. You need to correct these biases so that the results are applicable to the population.

For example, you might choose a sampling of data that contains all of the events and only a subset of the nonevents, which will make event and non-event data sizes similar. Again, this kind of analysis introduces biases that you need to correct so that the results are applicable to the population.

1. Splitting the data for training, validation, and test. (You probably know this.)
2. Bias correction. The effect of oversampling is the response ($$logit(\hat{p})$$) surface for a logistic regression model is shifted linearly, and oversampling does not affect the slopes, but it does make the intercepts too high or too low.

To correct the bias, or offset follow the equation $$Offset = \ln \frac{(\pi_0 \rho_1)}{(\pi_1 \rho_0)}$$

$$\pi_0$$=proportion of non-events in the population; $$\pi_1$$=proportion of events in the population.

$$\rho_0$$=proportion of non-events in the sample; $$\rho_1$$=proportion of events in the sample.

The output results should be ($$logit(\hat{p})-$$offset)