⚙️  Reweighting

Reweighting#

Adjusting sample or class weights to correct bias or distribution shift.

Important

✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.

What it is#

Reweighting assigns different weights to samples, features or loss terms so that training or evaluation reflects the true importance, fairness or distribution of the data. It leaves the raw data untouched and instead changes how much influence each part has.

Where it’s used#

Several settings. Class imbalance: upweight rare positives (fraud, disease) so the model can’t ignore them. Covariate shift / domain adaptation: reweight training samples to match the production distribution (an 80%-desktop training set toward 50%-mobile production). Fairness: upweight underrepresented protected groups for equal contribution. Plus loss reweighting (balancing terms in multi-task or adversarial training) and importance sampling (correcting biased draws for unbiased estimates).

The math#

The ordinary average loss

\[L = \frac{1}{N} \sum_{i=1}^{N} \ell(f(x_i), y_i)\]

becomes, with weights,

\[L = \frac{1}{N} \sum_{i=1}^{N} w_i \, \ell(f(x_i), y_i),\]

where \(w_i\) is the weight on sample \(i\) — a larger \(w_i\) gives that example more influence.

Examples and trade-offs#

On a 1%-fraud dataset, an unweighted model predicts “not fraud” always; weighting fraud at 99 against 1 makes those cases count and lifts recall. A loan model that is 80% male can upweight female applicants toward fairness. The benefits — handling imbalance and drift, improving fairness, keeping data intact (no over/undersampling) — come with risks: extreme weights can overfit the minority, and choosing weights well takes validation.


Theme: MLOps, Serving & Monitoring  ·  All terminology



See also

Source article Adapted (context, re-expressed) in our own words from: Reweighting (insightful-data-lab.com).

Tags: purpose: reference topic: terminology level: advanced