A soft-margin SVM uses a different penalty for each class: with the usual constraints. What changes in the dual and in the KKT conditions? In what direction does the boundary move if , and how would you choose 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: . The rest of the dual, and , stays the same.
Steps
- In the Lagrangian, the term is . The stationarity condition becomes , so .
- The dual is with for positives, for negatives, and .
- KKT: means the point is exactly on its margin. means it is inside the margin or misclassified.
- Effect of : 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.
- Choosing: a common rule is (inverse class frequency). So the total penalty from each class is balanced. Better still, tune the ratio together with by cross-validation on a metric such as F1, recall at fixed precision, or PR-AUC.
- This is exactly the `class_weight` option in common SVM libraries.
Common mistakes
- Thinking the boundary moves toward the class with the larger . It moves away from it.
- Changing to account for the weights. That constraint does not change.
- Tuning with accuracy on imbalanced data.
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 and with label , and and with label , are not linearly separable. Solving the hard-margin SVM dual with the kernel , what are the , 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?