A soft-margin SVM uses a different penalty for each class: min⁡12∥w∥2+C+∑yi=+1ξi+C−∑yi=−1ξi with the usual constraints. What changes in the dual and in the KKT conditions? In what direction does the boundary move if C+>C−, and how would you choose C± for an imbalanced dataset?

Supervised learning, SVM with asymmetric costs
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you can adapt the soft-margin derivation to class-dependent costs and reason about the effect.

Key idea

The only change is the box constraint: 0≤αi≤Cyi. The rest of the dual, w=∑αiyixi and ∑αiyi=0, stays the same.

Steps

  1. In the Lagrangian, the ξi term is Cyiξi. The stationarity condition becomes Cyi−αi−μi=0, so αi≤Cyi.
  2. The dual is max⁡∑αi−12∑αiαjyiyjk(xi,xj) with 0≤αi≤C+ for positives, 0≤αi≤C− for negatives, and ∑αiyi=0.
  3. KKT: 0<αi<Cyi means the point is exactly on its margin. αi=Cyi means it is inside the margin or misclassified.
  4. Effect of C+>C−: a positive slack is more expensive, so the optimiser tolerates fewer positive violations. The boundary moves away from the positives, toward the negative class, so it makes fewer false negatives and more false positives.
  5. Choosing: a common rule is Ck∝1/nk (inverse class frequency). So the total penalty from each class is balanced. Better still, tune the ratio C+/C− together with C by cross-validation on a metric such as F1, recall at fixed precision, or PR-AUC.
  6. This is exactly the `class_weight` option in common SVM libraries.

Common mistakes

How long your answer should be

Half a page; 5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: The four XOR points (1,1) and (−1,−1) with label +1, and (1,−1) and (−1,1) with label −1, are not linearly separable. Solving the hard-margin SVM dual with the kernel k(x,z)=(1+x⊤z)2, what are the αi, the bias and the decision function?
Next in Supervised learning: Prove that information gain from any split is non-negative, and say when it is exactly zero. Can it be zero for a split that is useful?