Surrogate loss calibration and margin bounds
Study classification calibration and the ψ transform linking convex surrogate loss to 0-1 excess risk, then derive norm- and margin-based generalization bounds for SVM and boosting.
After this lesson you can
- Explain why 0-1 ERM on half-spaces is NP-hard in the agnostic case and what surrogate losses address.
- Define classification calibration via conditional risk C_η(α), compute ψ transforms for hinge, logistic and exponential losses, and prove ψ(R(f) - R*) ≤ R_φ(f) - R_φ*.
- Prove the BR/√n Rademacher bound for bounded linear classes on bounded inputs.
- Prove a margin bound using ramp loss and the contraction lemma.
- Apply margin bounds to SVM and boosting and measure them on real data.
Before you start
- 13Talagrand's contraction lemmaRademacher generalization boundStructural properties of Rademacher complexityExcess risk identitiesExcess risk decompositionEfficient PAC learning and improper learning
- 11Margin-based classification lossesMaximum margin classifierSoft-margin SVMAdaBoostGradient boosting machine
- 06Convex functionSubgradient and subdifferential
- 02Cauchy-Schwarz inequality
Changing the loss without losing the objective
In binary classification we want to minimize 0-1 errors, but that loss is discontinuous and nonconvex. In the agnostic case, finding the half-space with the fewest mistakes is NP-hard when dimension is part of the input; Guruswami and Raghavendra prove even approximation hardness for noisy half-spaces. This does not contradict the fact that a separable set can be handled with linear programming. Convex surrogates ease optimization under suitable conditions, but optimizing another function helps only if its risk relates to the risk of interest.
Write , score and margin . A margin loss has form . Conditional risk for and score is
The Bayes rule predicts positive when and negative when . Classification risk may use any tie convention at ; the margin-loss graph counts as error for both labels and thus dominates that risk at a tie. A loss is classification-calibrated if, away from a tie, the infimum of conditional risk over incorrect or zero signs is strictly larger than . A correct-sign minimizer alone is insufficient: there must be a positive separation from the best incorrect-sign risk.
Hinge has minimizer away from a tie. Logistic gives , and exponential gives half that logit. At or their infima may require infinite scores. Squared loss gives ; clipped ramp loss is calibrated but nonconvex. Perceptron loss has a minimum at for every and is not calibrated.
Logistic loss recovers through the sigmoid only at the unrestricted population minimizer with a correctly specified logarithmic loss. A restricted class or misspecified model can produce useful classification scores without well-calibrated probabilities. Classification calibration and probability calibration are not synonyms.
The ψ transform
For calibrated convex losses like those above, define and for . In general use the lower convex envelope of the appropriate pointwise transform. The ψ transform quantifies the price of transferring surrogate excess to 0-1 excess:
The infima on the right are over all measurable scores, not necessarily the restricted class used by an algorithm. To understand the proof, an incorrect-sign decision has conditional 0-1 excess and, by convexity, surrogate excess at least . A correct decision has zero 0-1 excess. Integrate over and apply Jensen to convex . Calibration makes for .
For hinge, logistic with natural logarithm and exponential respectively,
Terms are interpreted by continuity. The latter two are approximately near zero; thus a surrogate excess bound generally induces order for 0-1 excess. The hinge relationship is linear. The inequality compares population risks; lowering empirical loss alone does not guarantee lower population excess.
import numpy as np
from scipy.optimize import minimize_scalar
from sklearn.linear_model import LogisticRegression
from scipy.special import expit
losses={'bisagra':lambda a:np.maximum(0,1-a),'logística':lambda a:np.logaddexp(0,-a),
'exponencial':lambda a:np.exp(-a),'perceptrón':lambda a:np.maximum(0,-a)}
for eta in (.2,.5,.8):
vals=[]
for name,phi in losses.items():
res=minimize_scalar(lambda a:eta*phi(a)+(1-eta)*phi(-a),bounds=(-8,8),method='bounded')
vals.append((name,round(res.x,3)))
print('η',eta,vals)
rng=np.random.default_rng(1309); x=rng.uniform(-2,2,2000); eta=expit(2*x); y=rng.binomial(1,eta)
model=LogisticRegression(C=1e6).fit(x[:,None],y)
grid=np.linspace(-2,2,10001); e=expit(2*grid); f=model.decision_function(grid[:,None])
r01=np.mean(np.where(f>0,1-e,e)); bayes=np.mean(np.minimum(e,1-e));
sur=np.mean(e*np.logaddexp(0,-f)+(1-e)*np.logaddexp(0,f))
opt=np.mean(-e*np.log(e)-(1-e)*np.log(1-e))
theta=r01-bayes; psi=.5*((1+theta)*np.log1p(theta)+(1-theta)*np.log1p(-theta))
print('exceso 0-1:',round(theta,6),'ψ:',round(psi,8),'exceso logístico:',round(sur-opt,8))
assert psi<=sur-opt+1e-12Integration uses a deterministic grid for a distribution with known ; fitting uses another sample. The numerical optimizer is bounded to , so a solution near an edge does not show that the unrestricted minimum is finite.
Linear complexity and margin
For , Cauchy-Schwarz resolves the supremum and Jensen controls the expectation:
if . This is linear Rademacher complexity; cross terms vanish when signs are averaged. The absence of explicit dimension depends on keeping and controlled, which can fail when features are added.
The margin ramp loss dominates 0-1 loss and is -Lipschitz. Contraction and the previous empirical bound imply that, for fixed in advance, with probability and simultaneously for every ,
This margin bound combines empirical cost of small margins with complexity and confidence. If is selected from data, use the grid and allocate : the union gives a simultaneous guarantee over all with the confidence term for each scale. Scaling changes functional margin and by the same factor; geometric margin removes that change. An unbounded intercept must be treated separately or included as a constant coordinate with controlled augmented norm.
In SVM, comes from dual coefficients and the smallest positive geometric margin determines separation in the separable case. Soft-margin models have errors and small margins; the full margin distribution matters. The bound does not say an added dimension is free if norm or radius changes.
Votes and boosting
AdaBoost produces with . Its normalized margin is for base classifiers . It is a convex combination of bases, so the Rademacher complexity of the convex hull equals that of the bases. A ramp loss yields a uniform bound depending on the margin distribution, not directly on round count. Schapire and colleagues studied test improvement after zero training error; this need not happen on every sample.
The fixed stratified Wisconsin split has 284 training and 285 test examples. It uses features 0 and 20, all thresholds between training values and both orientations; the figure computes rounds in the browser. The bound uses at most stump traces on examples, Massart and a union over radii. It can exceed 1. The real trajectory does not reach zero training error in these 50 rounds and test error is not monotone.
The synthetic moons option has 40 training and 1000 test examples. In this run, from round 17 to 20 training error remains zero, test error drops from .095 to .088 and the 10th margin percentile rises from .113 to .116. The seed was selected after inspecting test trajectories to show an example: that selection prevents treating it as an independent evaluation of a general procedure. Other seeds and rounds can behave differently; this does not reproduce published figures.
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.svm import SVC
X,y=load_breast_cancer(return_X_y=True); X=X[:,[0,20]]; y=2*y-1
X,Xt,y,yt=train_test_split(X,y,test_size=.5,stratify=y,random_state=1309)
scaler=StandardScaler().fit(X); X=scaler.transform(X); Xt=scaler.transform(Xt)
stumps=[]
for j in range(X.shape[1]):
v=np.unique(X[:,j]); cuts=np.r_[v[0]-1,(v[:-1]+v[1:])/2,v[-1]+1]
for c in cuts:
for s in (-1,1): stumps.append((j,c,s))
H=np.array([s*np.where(X[:,j]>=c,1,-1) for j,c,s in stumps])
Ht=np.array([s*np.where(Xt[:,j]>=c,1,-1) for j,c,s in stumps])
w=np.ones(len(y))/len(y); score=np.zeros(len(y)); test=np.zeros(len(yt)); total=0
for t in range(50):
errors=(H!=y)@w; k=np.argmin(errors); e=errors[k]
if e>=.5-1e-14: break
a=.5*np.log((1-max(e,1e-12))/max(e,1e-12)); total+=a
score+=a*H[k]; test+=a*Ht[k]; w*=np.exp(-a*y*H[k]); w/=w.sum()
if e<=1e-12: break
margins=y*score/total; rho=.5; delta=.05*6/np.pi**2
ramp=np.clip(1-margins/rho,0,1).mean()
bound=ramp+2*np.sqrt(2*np.log(4*(len(y)+1))/len(y))/rho+3*np.sqrt(np.log(2/delta)/(2*len(y)))
print('AdaBoost propio train/test:',round(np.mean(margins<=0),4),round(np.mean(yt*test<=0),4),'cota:',round(bound,3))
ada=AdaBoostClassifier(estimator=DecisionTreeClassifier(max_depth=1),n_estimators=50,random_state=1309).fit(X,y)
svm=SVC(kernel='linear',C=1).fit(X,y); [email protected]_vectors_
print('sklearn AdaBoost train/test:',round(1-ada.score(X,y),4),round(1-ada.score(Xt,yt),4))
print('SVC train/test:',round(1-svm.score(X,y),4),round(1-svm.score(Xt,yt),4),'norma:',round(np.linalg.norm(dual),4))
assert np.all(np.abs(margins)<=1+1e-12) and np.allclose(dual,svm.coef_)Standardization is fitted on training only. The custom stumps and scikit-learn’s can break ties differently; results are compared without requiring identical classifiers. The bound uses the stump family over both coordinates and is a statistical guarantee under i.i.d. sampling, not a clinical proof or guarantee for another population.
Exercises
Step 1 of 2. What is the supremum over ||w|| ≤ B?
Step 1 of 2. What is a minimizer for η > 1/2?
def adaboost_stumps(X, y, T):
passSummary
Main source: Bartlett, Jordan and McAuliffe.