0
$\begingroup$

TLDR: Will under/oversampling during the training phase teach the model the wrong distribution and adversely affect accuracy?

Let us assume you want to train a classifier to differentiate between class A and class B. Unfortunately, the population distribution of A and B is unbalanced at a ratio of [1:100]. As such, you utilize under-sampling or over-sampling such that the training and validation sets effectively achieve a [1:1] ratio between A and B. You do nothing to the test set. The distributions of the sets and and the training results are in the below table:

           Train  Val    Test
A Dist.    0.5    0.5    0.99
B Dist.    0.5    0.5    0.01
Accuracy   1.0    0.999  0.85

You have now trained a model which performs worse on the population than a "classify all as A" approach. Does over-sampling or under-sampling teach a model the wrong distribution - causing it to over-confidently predict minority classes? If not - what could be happening in this example?

$\endgroup$
0
$\begingroup$

Yes, teaching the model to expect a balanced distribution definitely will impact the results on the test set. Oversampling the minority class to balance the distribution will make the classifier more likely to predict that a given example is the minority class. Each iteration of gradient descent will push the model to a location where approximately half of the loss was contributed by examples from a minority class, which is not the situation when you're testing the model. There are a few things that I've seen that try to overcome this issue; focal loss is one example, where easily classified examples (predictions that the model has a lot of confidence in) contribute less to the loss than examples that are difficult to classify. Another approach that I've seen used is training a model on an artificially balanced training set, and then freezing all of the weights except the last layer (or last few layers), and finetuning the model on the true distribution. This usually increases the precision of the model.

Accuracy is a misleading metric in this situation. As you noted, the model trained with a balanced training set performs worse when compared to a model that predicts everything as class A. Despite the fact that the accuracy of the second model is higher, the predictions don't make sense, and don't reflect the nature of the data. I would encourage you to examine the precision and recall of the two models to get an idea of where the model is doing poorly.

Also, I think your validation split should have the same statistics as the test set. When the validation data doesn't reflect the test data, you're essentially optimizing your model to hit a different target than you actually want.

| improve this answer | |
$\endgroup$

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.