Skip to content
BIASED

Linear classifiers and surrogate losses

Labels ±1, the hyperplane and the distance to it, the margin, why the error rate gives no useful gradient, convex surrogate losses and what each estimates, the perceptron as SGD, linear separability.

Classes as numbers

A number is not yet a decision

In Regularization we controlled the size of regression weights. Now the target is a class. Encode labels as y∈{−1,+1}y\in\{-1,+1\} and use a linear score f(x)=wTx+bf(x)=w^Tx+b. Predict +1+1 when f(x)≥0f(x)\ge0 and −1-1 otherwise. We explicitly give a zero score to the positive class.

Why not regress on these numerical labels? In a newly specified one-dimensional example, negative points are −4,−2-4,-2 and positive points are 1,31,3. Least squares with an intercept gives f(x)=(10x+5)/29f(x)=(10x+5)/29. The boundary is −1/2-1/2 and every sign is correct. Add a positive point at 4040: the fit becomes

f(x)=106x−1353353.f(x)=\frac{106x-135}{3353}.

Now the boundary has moved past the positive point at 11, although x+1/2x+1/2 still separates the data. Squared error charges a correctly classified point even when its score is much greater than 11. Fitting numerical labels and choosing correct signs are different objectives. This is an exact, fictional calculation, not a benchmark result or a claim that least-squares classification always fails.

The hyperplane and the distance to it

The score has a scale

For w≠0w\ne0, the boundary wTx+b=0w^Tx+b=0 is a hyperplane normal to ww. Its signed distance from a point and that point's perpendicular projection are

r=f(x)∥w∥,x⊥=x−f(x)∥w∥2w.r=\frac{f(x)}{\lVert w\rVert},\qquad x_\perp=x-\frac{f(x)}{\lVert w\rVert^2}w.

For w=(2,−1)w=(2,-1), b=−1b=-1 and x=(3,1)x=(3,1), the score is 44 and the projection is (1.4,1.8)(1.4,1.8). Substitution into the boundary equation gives zero.

Multiplying both ww and bb by the same positive number multiplies scores but preserves all predictions and signed distances. A negative multiplier reverses the nonzero predictions. Changing only the bias moves the boundary. If w=0w=0, the score is constant and the distance formulas do not apply. A large score alone is therefore not an invariant confidence measure.

The margin and the error count

Add the label to the score

The functional margin is M=yf(x)M=yf(x). Positive margins lie on the label's side; negative margins are mistakes. Dividing by ∥w∥\lVert w\rVert gives a geometric margin when w≠0w\ne0.

At M=0M=0 our tie rule matters: a positive label is predicted correctly and a negative label incorrectly. The conservative count

R^≤0=1n∑i[Mi≤0]\widehat R_{\le0}=\frac1n\sum_i[M_i\le0]

counts both as errors. It upper-bounds actual classification error and agrees with it away from the boundary. Squared label error also has a margin form: since y2=1y^2=1, (y−f)2=(1−M)2(y-f)^2=(1-M)^2.

A small change to a boundary usually leaves all signs unchanged. The empirical error is flat between crossings and jumps at a crossing, so ordinary gradient descent receives no useful direction. This is not an impossibility claim: in one dimension we can test thresholds between sorted points, and a finite strictly separable problem can be expressed by feasible linear inequalities.

Surrogate losses

Give the optimizer a direction

Replace the discontinuous error indicator with a surrogate loss. Four convex choices are

ϕlog⁡(M)=log⁡(1+e−M)/log⁡2,ϕhinge(M)=max⁡(0,1−M),ϕexp⁡(M)=e−M,ϕsqh(M)=max⁡(0,1−M)2.\begin{aligned} \phi_{\log}(M)&=\log(1+e^{-M})/\log2,\\ \phi_{\mathrm{hinge}}(M)&=\max(0,1-M),\\ \phi_{\exp}(M)&=e^{-M},\\ \phi_{\mathrm{sqh}}(M)&=\max(0,1-M)^2. \end{aligned}

Each is nonnegative and at least 11 for M≤0M\le0, so its average bounds the conservative error count. The division by log⁡2\log2 is needed for this particular unit upper bound: natural-log logistic loss is only log⁡2\log2 at zero. Scaling the data loss alone also changes its tradeoff with a fixed regularizer.

Hinge and logistic grow linearly for very negative margins; exponential grows exponentially and squared hinge quadratically. Hinge stops charging once M≥1M\ge1; logistic keeps decreasing towards zero. None is immune to outliers, because a parameter gradient also contains the feature vector.

Convexity rules out nonglobal local minima. It guarantees neither a finite minimizer nor convergence for an arbitrary step schedule. Hinge has a kink; use a subgradient there. Squared hinge has a continuous first derivative, but not a continuous second derivative at M=1M=1.

What each surrogate estimates

What an optimal score can tell us

Fix a feature value and write p=P(y=+1∣x)p=P(y=+1\mid x). The conditional risk is Cp(f)=pϕ(f)+(1−p)ϕ(−f)C_p(f)=p\phi(f)+(1-p)\phi(-f). For 0<p<10<p<1, its pointwise minimizers include

flog⁡∗=log⁡p1−p,fexp⁡∗=12log⁡p1−p.f^*_{\log}=\log\frac{p}{1-p},\qquad f^*_{\exp}=\frac12\log\frac{p}{1-p}.

For hinge and p≠1/2p\ne1/2, the minimizer is the majority sign, +1+1 or −1-1; it does not retain the probability's magnitude. At p=1/2p=1/2, every score in [−1,1][-1,1] minimizes hinge risk. Squared error and squared hinge have optimum 2p−12p-1 for interior probabilities. These are unrestricted pointwise results.

A linear model may be unable to express those scores. Specify equally likely feature values x=−1,0,1x=-1,0,1 with positive probabilities 1/8,7/8,1/81/8,7/8,1/8. They define a fictional distribution, not measured frequencies. Independent logistic scores can be −log⁡7,+log⁡7,−log⁡7-\log7,+\log7,-\log7. Their mean base-two loss is 0.5435640.543564 and decision error 0.1250.125.

The best linear logistic score is instead constant: w=0w=0, b=log⁡(3/5)b=\log(3/5), predicting probability 3/83/8. Its loss is 0.9544340.954434 and error 0.3750.375. The constant prediction is calibrated when grouped by its own predicted probability, yet it loses the feature-dependent probabilities. Adding x2x^2 to the features can express the required shape.

Classification calibration of a loss concerns its pointwise preference for the majority sign. It does not eliminate a restricted model's approximation error, finite-sample estimation error or unfinished optimization. Logistic regression, next, will separate likelihood fitting from probability calibration.

The perceptron as SGD

An update after a nonpositive margin

The perceptron uses max⁡(0,−M)\max(0,-M) and, with step size one, updates when M≤0M\le0:

w←w+yx,b←b+y.w\leftarrow w+yx,\qquad b\leftarrow b+y.

At zero it chooses the nonzero endpoint subgradient. This choice matters: the zero parameter vector has zero perceptron loss, despite having no positive margins. The loss is not a unit upper bound on the conservative error count. Cycling through points gives incremental updates; random sampling gives the stochastic interpretation.

Our optional notebook uses (2,−1)(2,-1) positive, (−1,2)(-1,2) negative, (3,1)(3,1) positive, (0,−3)(0,-3) negative in that order, starting from zero. Compute a score with the current parameters, multiply by the label, then decide whether to update. A complete pass without updates establishes strict separation of these training points.

For the convergence statement, append a constant feature 11 and include the bias in the parameter vector. Suppose all augmented inputs have norm at most RR and a unit separator gives every example margin at least γ>0\gamma>0. After kk updates, progress towards that separator is at least kγk\gamma, while parameter norm is at most kR\sqrt{k}R. Thus

k≤R2/γ2.k\le R^2/\gamma^2.

This bounds updates, not passes or future errors. It requires separation. On inseparable data, repeated cycling needs a stopping rule.

Separability, and what comes next

Representation and a finite solution

The deterministic negative–positive–negative pattern at x=−1,0,1x=-1,0,1 is not separable by one threshold. The score 1−2x21-2x^2 separates it after adding a quadratic feature. More data does not repair a missing feature shape by itself. Conversely, enough features can fit arbitrary labels; successful training alone does not establish generalization.

On separable data, scaling a separator sends logistic and exponential losses towards zero without attaining it at finite weights. Hinge and squared hinge can attain zero with many separators. A positive quadratic penalty on all parameters,

1n∑iϕ(yi(wTxi+b))+λ(∥w∥2+b2),λ>0,\frac1n\sum_i\phi(y_i(w^Tx_i+b))+\lambda(\lVert w\rVert^2+b^2),\qquad\lambda>0,

makes these continuous convex objectives strongly convex and coercive, so the minimum exists and is unique. Penalizing only ww is a different convention: with a single observed class, an unpenalized logistic bias can still diverge. Standard hard-margin SVM leaves the bias out of its norm; its geometry is treated later in Support vector machines.

The optional notebook checks the new label-fit, conditional-risk and perceptron examples with Python's standard library. It is not required for progress. These are controlled calculations, not performance or calibration evidence on real users.

Sources

Adapted with Codex assistance from the reviewed English note and Russian note, revision 82b6cb0. The small fixtures originate in that reviewed first-party renewal; the phone questions and notebook self-checks are newly composed. No third-party dataset or notebook is used.

Scientific references: Bartlett, Jordan and McAuliffe (2006), §2, Theorem 2 for classification calibration; Freund and Schapire (1999), §§2–3.1 for the perceptron update and Block–Novikoff bound. Prior conceptual references, including HSE lectures and The Elements of Statistical Learning, remain credited in the pinned source note; no reuse permission is inferred from their availability.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • Linear scores and lossesoptional

    Trace the exact label-fit and perceptron examples; compare conditional risks and check hinge/logistic bounds. Standard-library notebook with saved outputs.

    ~20 min · easier on a computer · Read the matching topic. Python standard library only; no downloads.

    Self-check in the notebook — not part of mastery or the certificate.

Full notes

Answers are saved on the server and tied to this browser until you sign in.