What is class-weighted cross-entropy loss?

Quick Overview

Asks what class-weighted cross-entropy is, how the loss is written for multiclass and binary classification, and how the class weights are chosen. Tests understanding of class imbalance, the effect of weights on gradients and recall, and why weighting breaks probability calibration.

What is class-weighted cross-entropy loss?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

What is class-weighted cross-entropy loss? Give the formula, explain how the class weights are usually chosen, and describe what the weighting does to the trained model. ```hint Where the weight goes Start from ordinary cross-entropy for one example. Ask where a per-class multiplier would sit and what it does to that example's gradient. ``` ### What a Strong Answer Covers - The weighted loss for the multiclass and binary cases, including how the weighted average is normalized - Common ways to choose the class weights - How the weighting changes gradients, the decision boundary and minority-class recall - The effect on predicted probabilities and calibration - Alternatives for handling class imbalance ### Follow-up Questions - If you train a binary classifier with a positive-class weight $w$, how can you recover calibrated probabilities afterwards? - When would you train unweighted and tune the decision threshold instead of weighting the loss? - How does focal loss differ from class weighting in which examples it emphasizes? - Why can very large weights on a very rare class make mini-batch training unstable?

Overview: Asks what class-weighted cross-entropy is, how the loss is written for multiclass and binary classification, and how the class weights are chosen. Tests understanding of class imbalance, the effect of weights on gradients and recall, and why weighting breaks probability calibration.

General logo
General
Nov 24, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

What is class-weighted cross-entropy loss?

Give the formula, explain how the class weights are usually chosen, and describe what the weighting does to the trained model.

What a Strong Answer Covers Guidance

  • The weighted loss for the multiclass and binary cases, including how the weighted average is normalized
  • Common ways to choose the class weights
  • How the weighting changes gradients, the decision boundary and minority-class recall
  • The effect on predicted probabilities and calibration
  • Alternatives for handling class imbalance

Follow-up Questions Guidance

  • If you train a binary classifier with a positive-class weight ww , how can you recover calibrated probabilities afterwards?
  • When would you train unweighted and tune the decision threshold instead of weighting the loss?
  • How does focal loss differ from class weighting in which examples it emphasizes?
  • Why can very large weights on a very rare class make mini-batch training unstable?