0
$\begingroup$

Most advice I have found online is that we must not balance the test set. The test set should remain to be unseen.

However, I failed to see how balancing the test set will cause us to leak knowledge about the test set into the training set. Essentially, all I am doing is to check the number of samples in each class, and tossing away of excess samples that causes imbalance.

Can someone explain this to me?

$\endgroup$
3
  • 3
    $\begingroup$ Because any such modifications do not reflect the real situation of the test set, it's made up, so you are evaluating on made-up data, which isn't nice. $\endgroup$ Commented Aug 29, 2023 at 7:35
  • $\begingroup$ @user2974951 Is there a mathematic explaination? $\endgroup$
    – Fraïssé
    Commented Aug 29, 2023 at 8:33
  • 1
    $\begingroup$ Yes, the distribution of the modified test data is not the same as the original test data distribution, how about this? $\endgroup$ Commented Aug 29, 2023 at 8:39

2 Answers 2

4
$\begingroup$

The very reason for creating a test set is to simulate the real-world situation where you have to use your model on unseen data. This unseen data can have properties very different from the data that you trained you model on, including the distribution.

However, I failed to see how balancing the test set will cause us to leak knowledge about the test set into the training set.

It will not lead to data leakage since you are not using the data points in your test set to transform your training set, or to train the model itself. But it will also not lead to generalized performance. Your model would be specific to the evaluation you made on the altered test set.

Essentially, all I am doing is to check the number of samples in each class, and tossing away of excess samples that causes imbalance.

In this case, you are altering the property of the test set. The test set is supposed to act as if it was unseen data. By doing this, even though you might end up getting good test metrics (in theory), it will only give you false assurance that your model is working as it should (in practice).

Example:

You developed a model and evaluated it after discarding the excess samples causing the imbalance. You end up getting a test accuracy of 95%. You deploy the model today.

A month later when you re-evaluate your model performance, you discover that the month-long data actually contained 80% data belonging to one class. And your deployed model was not evaluated for such a scenario.

And unfortunately, the client who relied on the deployed model for leads made wrong decisions based on it and incurred losses. He may have fared better with no certainty than the false certainty the model gave him.

$\endgroup$
0
$\begingroup$

You are not leaking the knowledge in the training, but you are corrupting your final model evaluation when deployed on previously unseen and unaltered (unbalanced) data.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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