What is the conceptual difference between applying sample weights to a loss versus applying class weights?

Quick Overview

Asks how weighting a training loss per class differs from weighting it per example. Tests understanding of how each kind of weight changes what the model optimizes, its effect on predicted probabilities, common reasons for per-example weights, and how libraries combine the two.

What is the conceptual difference between applying sample weights to a loss versus applying class weights?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Many training APIs let you weight the loss either per class or per example. What is the conceptual difference between applying sample weights to a loss versus applying class weights? ```hint Look at what the weight depends on Ask what information each kind of weight is allowed to depend on, and whether one kind can express the other. ``` ```hint Think about the outputs Consider what scaling up the loss of a whole class does to the probabilities the model predicts. ``` ### What a Strong Answer Covers - What each kind of weight is a function of, and how the two relate - The effect of class weights on the class balance the model sees and on calibration - Typical reasons to give individual examples different weights - How the two kinds of weights combine in common libraries ### Follow-up Questions - How would you correct the predicted probabilities of a model trained with class weights? - When is class weighting equivalent to resampling, and when do the two behave differently in practice? - How would you estimate importance weights for covariate-shift correction? - How do sample weights interact with the regularization strength in scikit-learn's `LogisticRegression`?

Overview: Asks how weighting a training loss per class differs from weighting it per example. Tests understanding of how each kind of weight changes what the model optimizes, its effect on predicted probabilities, common reasons for per-example weights, and how libraries combine the two.

PracHub logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

Many training APIs let you weight the loss either per class or per example. What is the conceptual difference between applying sample weights to a loss versus applying class weights?

What a Strong Answer Covers Guidance

  • What each kind of weight is a function of, and how the two relate
  • The effect of class weights on the class balance the model sees and on calibration
  • Typical reasons to give individual examples different weights
  • How the two kinds of weights combine in common libraries

Follow-up Questions Guidance

  • How would you correct the predicted probabilities of a model trained with class weights?
  • When is class weighting equivalent to resampling, and when do the two behave differently in practice?
  • How would you estimate importance weights for covariate-shift correction?
  • How do sample weights interact with the regularization strength in scikit-learn's LogisticRegression ?