How does training with a class-weighted loss affect the calibration of the model's predicted probabilities?

Quick Overview

Asks how weighting classes in the cross-entropy loss changes the probabilities a classifier outputs. Tests deriving the weighted optimum, the link to prior shift and resampling, which metrics are unaffected, and how to correct the bias with prior correction or post-hoc calibration.

How does training with a class-weighted loss affect the calibration of the model's predicted probabilities?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How does training with a class-weighted loss affect the calibration of the model's predicted probabilities? Assume a classifier trained with cross-entropy where each class $k$ gets a weight $w_k$, for example to counter class imbalance. ```hint Find the minimizer For a single input $x$, write the expected weighted cross-entropy as a function of the predicted distribution and find the distribution that minimizes it. ``` ```hint Separate order from value Ask which uses of the model depend only on the order of its scores and which depend on the probability values themselves. ``` ### What a Strong Answer Covers - The minimizer of weighted cross-entropy compared with the unweighted case, and the direction of the bias - The link to training on resampled data with a different class prior - Which uses of the model are affected: ranking, thresholded decisions, and expected-cost decisions or risk scores - How to correct or avoid the distortion, and the limits of each fix - How to measure calibration, and on which data ### Follow-up Questions - A binary model was trained with weight 9 on the positive class and 1 on the negative class. It outputs 0.5 for an example. What probability should you report? - Why can temperature scaling alone fail to fix a class-weighted model, while Platt scaling works? - Does random undersampling of the majority class cause the same distortion? How would you correct it?

Overview: Asks how weighting classes in the cross-entropy loss changes the probabilities a classifier outputs. Tests deriving the weighted optimum, the link to prior shift and resampling, which metrics are unaffected, and how to correct the bias with prior correction or post-hoc calibration.

General logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How does training with a class-weighted loss affect the calibration of the model's predicted probabilities?

Assume a classifier trained with cross-entropy where each class kk gets a weight wkw_k, for example to counter class imbalance.

What a Strong Answer Covers Guidance

  • The minimizer of weighted cross-entropy compared with the unweighted case, and the direction of the bias
  • The link to training on resampled data with a different class prior
  • Which uses of the model are affected: ranking, thresholded decisions, and expected-cost decisions or risk scores
  • How to correct or avoid the distortion, and the limits of each fix
  • How to measure calibration, and on which data

Follow-up Questions Guidance

  • A binary model was trained with weight 9 on the positive class and 1 on the negative class. It outputs 0.5 for an example. What probability should you report?
  • Why can temperature scaling alone fail to fix a class-weighted model, while Platt scaling works?
  • Does random undersampling of the majority class cause the same distortion? How would you correct it?