In a classification task, when the sample counts of different classes differ greatly, the model tends to be biased toward the majority class. Rescaling corrects this bias by adjusting the weight of each class, so that the classifier pays more attention to the minority class when it makes decisions.
N = total samples | m⁺ = positive examples | m⁻ = negative examples
w⁺ = positive-class weight | w⁻ = negative-class weight
P(+|x) = raw positive-class probability | P'(+|x) = adjusted probability
m⁺ — number of positive-class samples
m⁻ — number of negative-class samples
N = m⁺ + m⁻ — total number of samples
w⁺ — positive-class rescaling weight
w⁻ — negative-class rescaling weight
P(+|x) — raw predicted probability of the model
P'(+|x) — probability after rescaling
Adjust the parameters on the left and watch the rescaling weights and the adjusted probability change in real time. The preset scenarios switch quickly between data distributions with different degrees of imbalance.
Rescaling is one of the fundamental strategies for dealing with class imbalance in machine learning. Its core idea is to assign a different weight coefficient to the samples of each class, thereby adjusting the bias of the classifier during decision making.
In a binary classification problem, let the number of positive examples be m⁺, the number of negative examples be m⁻, and the total number of samples be N = m⁺ + m⁻. The rescaling weights are defined as:
w⁺ = N / (2 × m⁺) and w⁻ = N / (2 × m⁻)
The adjusted probability is obtained by weighted normalization: P'(+|x) = P(+|x)·w⁺ / (P(+|x)·w⁺ + P(-|x)·w⁻). When a class has fewer samples, its weight coefficient is larger, so it receives more attention in the decision. For a K-class problem, the general form is w_c = N / (K × N_c).
Imagine a class with only 5 boys and 95 girls. If the teacher picks class representatives in proportion to headcount, the boys would have almost no chance of being chosen. Rescaling is like giving the boys extra weighted votes — each boy’s opinion is amplified several times, so that in the final decision the boys’ voices are not completely drowned out by the girls’ numerical advantage.
In machine learning, when the numbers of positive and negative samples differ greatly, the model tends to favour the majority class. Rescaling gives the minority class a higher weight, so the model pays more attention to minority samples during training and prediction, thereby correcting that bias.
Class imbalance is a common and thorny problem in machine learning. When the sample counts of the classes in the training data differ greatly, standard classifiers tend to favour the majority class, leaving recognition accuracy for the minority class extremely low. Concretely:
- The model may predict every sample as the majority class: overall accuracy looks high, yet it has no ability to recognise the minority class
- The feature patterns of the minority class are "drowned out" by the majority class, making it hard for the model to learn an effective decision boundary
- On the test set, recall and F1 score for the minority class are often extremely low
Rescaling adjusts the weights so that, without changing the original data distribution, the classifier gives different classes different levels of attention, thereby improving its ability to recognise the minority class. It is a lightweight, easy-to-implement solution.
In many real-world applications, the minority class is exactly what we care about most. For example:
- Fraud detection: fraudulent transactions are far fewer than normal ones, but missing even one is extremely costly
- Medical diagnosis: positive samples are far fewer than healthy ones, but a missed diagnosis can be fatal
- Fault prediction: equipment failures are rare, but a single failure can cause huge losses
- Intrusion detection: network attacks account for a tiny fraction of traffic, yet the security threat cannot be ignored
If class imbalance is not handled properly, the model’s "high accuracy" is only an illusion. Rescaling offers a simple and effective way to raise the model’s sensitivity to the minority class, so that the model actually delivers in critical scenarios.
- Financial risk control: credit card fraud detection, money laundering identification
- Healthcare: rare disease screening, benign vs. malignant tumor diagnosis
- Industrial manufacturing: equipment fault prediction, product defect detection
- Network security: intrusion detection, malicious traffic identification, spam filtering
- Customer management: customer churn prediction, high-value customer identification
- Text classification: extreme sentiment detection, niche categories in topic classification
- Image recognition: lesion detection in medical imaging, abnormal behaviour detection in surveillance
- Weight choice depends on prior knowledge: if the class priors are estimated inaccurately, the weights may be set improperly, which hurts model performance.
- Risk of over-correction: when the minority class has very few samples, its weight can become extremely large, causing the model to over-favour the minority class and introducing a new bias.
- Limited effect under extreme imbalance: for extreme imbalance (e.g. 1:10000), rescaling alone may not be enough; it has to be combined with oversampling, undersampling or ensemble methods.
- The meaning of the probability changes: the adjusted probability no longer carries its original calibration meaning and cannot be read directly as a true class probability.
- Extra complexity for multi-class problems: with more than two classes, choosing the weights and handling the interactions between classes becomes more complicated.
- Does not change the nature of the data: rescaling only adjusts the weights; it adds no information about the minority class, whose feature coverage stays limited.