SVM C Hyperparameter: Penalty or Budget
The letter C in a support vector machine is not one thing: in some libraries it is a penalty on margin violations, and in some books it is a budget for them, and the two point in opposite directions. When you read advice about C, check which convention it uses.
The penalty convention. The scikit-learn user guide says SVC solves the primal problem min ½ wᵀw + C Σ ζᵢ, subject to yᵢ(wᵀφ(xᵢ) + b) ≥ 1 − ζᵢ and ζᵢ ≥ 0. It explains that the penalty term C "controls the strength of this penalty, and as a result, acts as an inverse regularization parameter." The SVC documentation says the same in other words: "The strength of the regularization is inversely proportional to C." A larger C makes each unit of slack more expensive, so the fit generally favors fewer violations and a narrower margin. That is a tendency, not a guarantee: the fitted margin can stay the same over a range of C, and fewer classification mistakes are not promised.
The budget convention. In James, Witten, Hastie, and Tibshirani's Equations 9.12 to 9.15, the slack variables must satisfy Σ εᵢ ≤ C, with C a nonnegative tuning parameter. They write that C "bounds the sum of the εᵢ's, and so it determines the number and severity of the violations to the margin (and to the hyperplane) that we will tolerate," and call it "a budget for the amount that the margin can be violated." Then: "As the budget C increases, we become more tolerant of violations to the margin, and so the margin will widen." With C = 0 there is no budget and you get the maximal margin hyperplane, which exists only if the classes are separable. They add that C is generally chosen by cross-validation and controls the bias-variance trade-off: small C gives narrow margins that fit the data closely, with low bias and high variance.
Try it by hand. Five points on a line with labels: x = −3 and −1 are negative, x = 1 and 3 are positive, and x = −2 is also positive, so no single threshold separates them. Compare two candidate rules f(x) = w·x in the penalty convention, ignoring the intercept. Candidate A has w = 1, a narrow margin. Its slacks ζᵢ = max(0, 1 − yᵢ f(xᵢ)) are 0, 0, 0, 0, and 3 for the point at −2, so Σζ = 3 and the objective is ½ + 3C. Candidate B has w = ¼, a wider margin. Its slacks are 0.25, 0.75, 0.75, 0.25, and 1.5, so Σζ = 3.5 and the objective is 0.03125 + 3.5C. B wins when 0.03125 + 3.5C < 0.5 + 3C, which is C < 15/16 = 0.9375. At C = 0.5 the objectives are 2.0 for A and 1.78 for B. At C = 1 they are 3.5 and 3.53, and A wins. So in the penalty convention, raising C moves the winner from the wide margin to the narrow one. This compares two candidates only. It is not the full optimum, and the points are invented. In the budget convention the arrow flips: raising the budget C widens the margin.
The trap: assuming C has the same meaning, or the same reciprocal relation to a regularization strength like ridge's alpha, in every library and objective. Advice copied from one convention into the other, such as raise C for a wider margin, does the opposite, and a C value from one does not carry over to the other.
Prof Rod's rule: before you tune C, find the objective it sits in and ask whether a bigger C punishes violations or forgives them.