/ THE IDEA
Each example first receives its ordinary loss, a number measuring the model's error. The class weight then multiplies that loss before the examples are combined. A weight of three makes that example contribute three times as much as an otherwise identical example with weight one. The model is trained against the resulting weighted objective. One automatic policy gives weights inversely related to class counts. In a two-class dataset, this can make each class contribute equally if their average unweighted losses are equal. That is a design choice about the objective. It is not a claim that the two classes occur equally often outside the training collection.
THE FORMAL IDEA
L_weighted = Σ(w_class × L_example) / N
| L_example is one example's ordinary loss; w_class is the multiplier for its category; N is the number of examples. | | Σ means add across examples. This expression uses division by N; some implementations instead divide by the sum of weights, changing the overall scale. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
There are 8 ordinary and 2 damaged parcels, each with dimensionless loss 1. With both weights 1: contributions are 8×1 = 8 and 2×1 = 2; mean loss = (8+2)/10 = 1. Change damaged weight to 4: contributions become 8 and 2×4 = 8. The weighted mean becomes (8+8)/10 = 1.6, although no prediction changed.
|
At the current model settings, the reported objective increased because the scoring policy changed. During subsequent training, improving a damaged-parcel prediction becomes more valuable relative to an ordinary-parcel improvement. The new objective can favour a different model, but this arithmetic does not guarantee how many future mistakes it will make.
/ SO WHAT?
Weighting and changing a decision threshold are related but different interventions. Weighting can alter the fitted model itself; a threshold changes how an already fitted score becomes an action. Keep those choices separate when explaining a result. Otherwise an apparent model improvement might simply reflect adopting different priorities about which errors are acceptable.
ONE CAVEAT |
| Class counts alone do not determine real-world error costs. Weighting can worsen performance for another class and can change the interpretation of probability estimates. Evaluate the resulting model and operating policy on representative data. |
KEEP THIS
Class weights change which errors training is paid to reduce, so they encode priorities rather than creating extra evidence about rare examples.
|
NEXT: Why does measuring a voltage change it?
|