Class weights are numeric values assigned to target classes during model training to make some classes count more than others. They are used when classes are imbalanced, so the learning process penalises mistakes on underrepresented classes more heavily than mistakes on common ones.
What class weights are for
Class weights are a training-time adjustment, not a data fix. They change how strongly the learning algorithm treats errors on each class, so the model is pushed to pay more attention to minority labels instead of drifting toward the majority class that appears most often.
This matters whenever imbalance would otherwise let a model achieve superficially good accuracy while missing the cases that matter most. In practice, class weights are one of the simplest ways to make the optimisation process reflect business importance, anomaly rarity, or the cost of false negatives without changing the underlying dataset.
How class weights change model behaviour
Weighted training increases the loss contribution of selected classes. That means the optimiser receives a larger penalty when it misclassifies those examples, which can shift decision boundaries and improve recall for underrepresented classes. The trade-off is that precision on common classes may fall, so the effect has to be judged against the real objective rather than a single headline metric.
Class weights are especially useful when the imbalance is structural, such as fraud, abuse detection, rare defect detection, or any domain where positive examples are scarce. They are not a substitute for understanding the class distribution, because extreme weighting can also make training unstable or overcorrect the model toward the minority class.
Where class weights fit in the training pipeline
They belong in the model-training setup alongside the loss function, sampling strategy, and evaluation metric. A weighted loss tells the optimiser what to emphasise, while validation metrics tell you whether that emphasis actually improved the behaviour you care about. If the metric and the weights disagree, the model may be optimising for the wrong outcome.
They also interact with thresholding and calibration. A model trained with class weights may output scores that are useful for ranking but still need a decision threshold tuned to the operating environment. That is why weighted training should be reviewed together with confusion matrices, per-class recall, and the acceptable cost of different error types.
Common misuses and practical limits
Class weights are often used as a quick response to imbalance, but they are not universally the best fix. If the minority class is noisy, poorly labelled, or too small to represent the real pattern, heavier weighting can amplify error instead of improving learning. In that case, better sampling, more data, or a different objective may be more effective.
They are also easy to misuse as a substitute for evaluation discipline. A model can look improved after weighting while still failing on the operational class that matters most. The safer approach is to treat class weights as one control in a broader training and validation design, not as a standalone solution.
Risk and Threat Considerations
Class weights can create model-risk if the chosen weighting scheme does not match the real cost of mistakes. Overweighting a rare class can produce false positives and unstable decision boundaries, while underweighting it can leave a system blind to the very events it was meant to catch. That is especially important in security, fraud, and safety use cases where rare events carry disproportionate impact.
Failure mechanism: The training objective is skewed enough that the model learns an imbalanced or overcorrected boundary, which can either suppress minority-class misses or flood downstream processes with noisy alerts.
Impact: The organisation may see reduced detection quality, higher manual review load, degraded trust in the model, or silent failure on the rare outcome the model was supposed to surface.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST CSF 2.0, NIST AI RMF and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | ID.RA-01 — Asset vulnerabilities are identified and documented | Class imbalance is a documented modeling condition that changes risk assessment. |
| GV.RM-01 — Risk management objectives are established and communicated | Weights encode which errors matter most, which is a risk-priority decision. | |
| Recommendation — Document class imbalance as a model-risk condition and review its effect on detection quality. Define the acceptable error trade-offs before assigning class weights. | ||
| NIST AI RMF | Map — Map the AI context and risks | Weighted training changes how the model treats rare versus common outcomes. |
| Recommendation — Map the target class imbalance and its impact on model outcomes before training. | ||
| OWASP ASVS | V15 — Secure Coding and Architecture | Imbalanced outcomes and loss weighting are design choices that affect model behaviour. |
| Recommendation — Design the training objective so minority-class failures are not hidden by aggregate metrics. | ||
Practitioner Guidance
What to watch for: Compare weighted and unweighted runs on per-class recall, precision, and confusion matrices before deciding that the weighting helped. The useful question is not whether the aggregate score improved, but whether the model behaves better on the specific class that was previously being ignored.
Practitioner note: If the class imbalance reflects a real operational rarity, class weights are a legitimate way to encode that importance into training. If the imbalance is caused by poor data quality or a shifting label distribution, weighting may mask the underlying problem rather than solve it.
Related resources from NHI Mgmt Group
- What breaks when machine identities are not governed like first-class identities?
- What breaks when enterprise agents are not treated as first-class identities?
- Why do runtime data sources matter as much as model weights in AI security?
- Why do storage-class permissions matter so much in Kubernetes security?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 9, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org