MLCrack

    ML MATH & LINEAR ALGEBRA · INTERVIEW QUESTION

    Explain the KKT conditions and their role in SVM optimization.

    ⚫ expert · Numerical Methods

    Hint: Think about the Lagrangian, complementary slackness, and the dual problem.

    Answer

    KKT (Karush-Kuhn-Tucker) conditions are necessary at a local optimum for differentiable inequality-constrained problems under a constraint qualification (for example LICQ). For convex problems, feasible KKT points are globally optimal; necessity still needs an appropriate qualification. The inequality-only conditions are:

    1. Stationarity: ∇f+∑λi∇gi=0\nabla f + \sum \lambda_i \nabla g_i = 0
    2. Primal feasibility: gi≤0g_i \leq 0
    3. Dual feasibility: λi≥0\lambda_i \geq 0
    4. Complementary slackness: λi⋅gi=0\lambda_i \cdot g_i = 0

    In hard-margin SVMs, the constraints are yi(w⋅xi+b)≥1y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \geq 1.

    Complementary slackness means αi>0\alpha_i > 0 only when yi(w⋅xi+b)=1y_i(\mathbf{w} \cdot \mathbf{x}_i + b) = 1, i.e., only support vectors have non-zero dual variables.

    The SVM dual problem: max⁡α∑iαi−12∑i,jαiαjyiyjxi⊤xj\max_\alpha \sum_i \alpha_i - \frac{1}{2} \sum_{i,j} \alpha_i \alpha_j y_i y_j \mathbf{x}_i^\top \mathbf{x}_j

    subject to αi≥0\alpha_i \geq 0 and ∑αiyi=0\sum \alpha_i y_i = 0.

    In a soft-margin SVM, slack variables allow violations and the dual adds 0≤αi≤C0 \leq \alpha_i \leq C. Support vectors with αi=C\alpha_i=C can lie inside the margin or be misclassified; only 0<αi<C0<\alpha_i<C implies an exact unit margin. Sparsity can reduce prediction work, but kernel SVM training may still be expensive.