Sam Babichenko

Reading notes / Cost-sensitive classification and calibration

Local case-control sampling

Fithian and Hastie, 2014

Context. In rare-positive problems (clicks, fraud, disease) the information sits mostly in the positives while the compute scales with the total. Epidemiology's answer, case-control sampling, keeps all cases and a few controls, fits logistic regression, and subtracts the log sampling ratio from the intercept (Anderson, 1972; Prentice and Pyke, 1979). The intercept fix is exact only for a correct logistic model, since under misspecification the slopes change too, and the scheme ignores conditional imbalance, keeping an obvious control at the same rate as one that looks like a case. Fithian and Hastie keep each point with probability equal to how surprising its label is under a pilot model, ∣y−p~(x)∣|y-\tilde p(x)|. Every kept label is then close to a fair coin given xx, the most informative state of a Bernoulli, and an offset undoes the tilt exactly; it is the logit shift of Elkan and Saerens et al., now depending on xx.

Setting. (xi,yi)(x_i,y_i) are i.i.d., x∈Rpx\in\mathbb R^p includes the intercept, and the logistic model may be misspecified. The target is the population risk minimizer θ∗=arg⁡min⁡θ E[−Yθ′X+log⁡(1+eθ′X)].\theta^*=\arg\min_\theta\ \mathbb E\big[-Y\theta'X+\log(1+e^{\theta'X})\big]. Sampling is accept-reject, zi∼Bernoulli(a(xi,yi))z_i\sim\text{Bernoulli}(a(x_i,y_i)). Case-control (CC): aa depends on yy only; fit to the subsample and subtract b=log⁡(a(1)/a(0))b=\log(a(1)/a(0)) from the intercept. Local case-control (LCC): given a pilot θ~\tilde\theta with p~(x)=σ(θ~′x)\tilde p(x)=\sigma(\tilde\theta'x), accept with a(x,y)=∣y−p~(x)∣a(x,y)=|y-\tilde p(x)|, fit an ordinary logistic regression to the subsample, and set θ^=θ^S+θ~\hat\theta=\hat\theta_S+\tilde\theta. For a larger subsample, accept with probability c a∧1c\,a\wedge1 and weight accepted points by c a∨1c\,a\vee1.

Results. (i) Under misspecification the limit of CC depends on the sampling ratio and generally differs from θ∗\theta^*. (ii) Consistency. If E∥X∥<∞\mathbb E\|X\|\lt\infty, the classes are not separable by a hyperplane, and the pilot λn→θ∗\lambda_n\to\theta^* in probability, possibly depending on the data, then θ^n→θ∗\hat\theta_n\to\theta^* in probability. (iii) Distribution. If E∥X∥2<∞\mathbb E\|X\|^2\lt\infty and the pilot is independent of the data with n(λn−θ∗)⇒N(0,V)\sqrt n(\lambda_n-\theta^*)\Rightarrow N(0,V), then n(θ^n−θ∗)⇒N(0, H−1(CVC′+aˉ−1J)H−1),\sqrt n(\hat\theta_n-\theta^*)\Rightarrow N\big(0,\ H^{-1}(CVC'+\bar a^{-1}J)H^{-1}\big), where HH and JJ are the Hessian and score covariance of the logistic loss under the subsampled law, CC is the cross-derivative of the score under that law in the pilot, and aˉ=E∣Y−p∗(X)∣\bar a=\mathbb E|Y-p^*(X)| is the acceptance rate. (iv) Efficiency. If the model is correct and the pilot consistent and independent, n(θ^n−θ0)⇒N(0, 2Σfull)\sqrt n(\hat\theta_n-\theta_0)\Rightarrow N(0,\,2\Sigma_{\rm full}), with Σfull\Sigma_{\rm full} the full-sample MLE's covariance, from a subsample of expected size naˉn\bar a; with the factor c>1c\gt1, the covariance is at most (1+1/c)Σfull(1+1/c)\Sigma_{\rm full}, for a subsample about (1+c)/2(1+c)/2 times larger under strong imbalance.

Step 1

Label-dependent sampling shifts the log-odds by the log acceptance ratio. Bayes on the accepted points gives logit⁡P(Y=1∣X=x,Z=1)=f(x)+log⁡a(x,1)a(x,0).\operatorname{logit}P(Y=1\mid X=x,Z=1)=f(x)+\log\frac{a(x,1)}{a(x,0)} . For CC the shift is a constant bb, which the intercept correction removes. For LCC it is −θ~′x-\tilde\theta'x, so the subsample's log-odds are close to 0 everywhere when the pilot is good. If the model is correct, both corrections are exact; the methods differ only under misspecification.

Step 2

Under misspecification, shifting the logit changes what the fit matches. The population score E[X(p(X)−pθ(X))]=0\mathbb E[X(p(X)-p_\theta(X))]=0 makes the best linear fit get probabilities right on average, so it fits most closely where pp changes with ff, near p=1/2p=1/2, and nearly ignores regions where p≈0p\approx0. A constant shift bb changes which regions sit near 1/2, so the CC limit moves with bb. In the oatmeal example (family history in 10% of people, oatmeal in 50% independently; true log-odds −5,−10-5,-10 without history and −4,−1-4,-1 with it, for no oatmeal and oatmeal), the population oatmeal coefficient is 1.4, because only the high-risk column has probabilities that matter. Equal case-control sampling raises every cell by the same amount, the no-history column starts to count, and the coefficient becomes −0.83-0.83: the sign flips (we reproduced 1.39 and −0.83-0.83 on the four cells). Weighted CC restores consistency at a cost in variance.

Step 3

With a perfect pilot, the subsample's score is half the population score. Take pilot θ∗\theta^* and subsample parameter 0, where every fitted probability is 1/2. A positive is kept with probability 1−p∗(x)1-p^*(x) and a negative with probability p∗(x)p^*(x), so E[X(Y−12) aθ∗(X,Y)]=12 E[X(p(X)(1−p∗(X))−(1−p(X))p∗(X))]=12 E[X(Y−p∗(X))]=0.\mathbb E\big[X(Y-\tfrac12)\,a_{\theta^*}(X,Y)\big]=\tfrac12\,\mathbb E\big[X\big(p(X)(1-p^*(X))-(1-p(X))p^*(X)\big)\big]=\tfrac12\,\mathbb E\big[X(Y-p^*(X))\big]=0 . Hence θ∗\theta^* is the LCC target whatever the true ff: sampling stands in for the weights the full-sample score would have applied. CC is LCC with an intercept-only pilot, which is not θ∗\theta^* under misspecification, hence its inconsistency.

Step 4

A consistent pilot suffices for consistency, through coupling and convexity. The population version of the LCC risk is minimized at θ∗\theta^* by Step 3, so what remains is convergence when the pilot λn\lambda_n depends on the data. Drive the accept-reject decisions for every pilot by the same uniforms uiu_i: decisions under λn\lambda_n and under its limit differ only when uiu_i falls between two acceptance probabilities at most ∥xi∥ ∥λn−λ∞∥\|x_i\|\,\|\lambda_n-\lambda_\infty\| apart, and Hoeffding conditional on the data and the pilot controls the few flipped points. Bounded gradients and a finite net make the convergence uniform on compacts, strict convexity keeps the minimizer near θ∗\theta^*, and nonseparability makes each sampled risk coercive.

Step 5

With an independent pilot, the covariance is a sandwich formula plus a term for the pilot's error. Two errors add. Given the pilot, θ^\hat\theta is an M-estimator on about naˉn\bar a points, so n(θ^−θˉ(λn))\sqrt n(\hat\theta-\bar\theta(\lambda_n)) is asymptotically N(0,aˉ−1H−1JH−1)N(0,\bar a^{-1}H^{-1}JH^{-1}), where θˉ(λ)\bar\theta(\lambda) is the limit for a fixed pilot. That limit moves with the pilot, and the implicit function theorem on its score equation gives θˉ(λ)=θ∗+H−1C(λ−θ∗)+o(∥λ−θ∗∥).\bar\theta(\lambda)=\theta^*+H^{-1}C(\lambda-\theta^*)+o(\|\lambda-\theta^*\|). An independent pilot makes the two pieces independent, which gives (iii). Under correct specification θˉ(λ)≡θ0\bar\theta(\lambda)\equiv\theta_0 for every pilot, so C=0C=0, and to first order the pilot's error only changes which points are kept. All the experiments use a data-dependent pilot, which is outside this theorem.

Step 6

The factor two follows from counting Fisher information. With a correct model and pilot θ0\theta_0, each kept point is a fair coin with Fisher information 14xx′\tfrac14xx', and a point at xx is kept with probability p(1−p~)+(1−p)p~=2p(1−p)p(1-\tilde p)+(1-p)\tilde p=2p(1-p), so the expected information per original point is 2p(x)(1−p(x))⋅14xx′=12 p(x)(1−p(x)) xx′,2p(x)(1-p(x))\cdot\tfrac14xx'=\tfrac12\,p(x)(1-p(x))\,xx', exactly half the full sample's, from naˉn\bar a points with aˉ=2E[p(1−p)]≤2P(Y=1)\bar a=2\mathbb E[p(1-p)]\le2P(Y=1). For c>1c\gt1 the same count gives H=c2IfullH=\tfrac c2I_{\rm full} and J⪯c(c+1)4IfullJ\preceq\tfrac{c(c+1)}4I_{\rm full}, hence the bound (1+1/c)Σfull(1+1/c)\Sigma_{\rm full}; c=5c=5 costs 20% extra variance for a subsample about three times larger. A small check of ours agrees (P(Y=1)≈2.6%P(Y=1)\approx2.6\%, n=105n=10^5, independent pilot): about 4,350 kept points gave variance ratios to the full MLE of 2.3, 2.2 and 1.9, against 1.5, 3.4 and 3.6 for 1:1 case-control on about 5,170.

Step 7

In the experiments LCC beats both case-control variants. In a misspecified simulation at 1% positives, with 2,000 points per method, LCC had squared bias 0.0049 against 0.023 (weighted CC) and 0.15 (CC), and variance 0.025 against 0.16 and 0.043. In a correctly specified one with strong separation, aˉ≈0.005\bar a\approx0.005 and LCC is roughly 100 times more efficient than uniform subsampling. On web spam (60% spam, so marginally balanced but conditionally imbalanced), the predicted variance ratios to the full-sample fit, about 2 for LCC and 5 for CC, held approximately, slightly optimistic.

Consequences and limits. LCC turns imbalance into compute savings without case-control's misspecification bias, recovering half the full-data information from a sample at most twice the size of the positive class. For payment fraud, the paper's suggestion fits a daily retrain: with yesterday's model as the pilot, keep the frauds it scored as safe and the good transactions it scored as risky, and drop the bulk of obvious good traffic. The usual practice of keeping all fraud and a fraction rr of legitimate traffic is CC, and its correction (add log⁡r\log r to the fitted log-odds, Elkan's Theorem 2) restores calibration only if the model is right. Since a misspecified fit is most accurate near the level curve where the sampled probability is 1/2, the sampling ratio picks which level curve of p(x)p(x) the fit gets right, and the paper raises aiming it at the decline threshold p∗p^* as an open direction. The theory covers unpenalized logistic regression in fixed dimension, needs an independent pilot for the variance result, and gives no finite-sample guidance on pilot quality. A stale pilot after drift always lowers the information per kept point and costs consistency under misspecification, since the limit is then θˉ(λ)≠θ∗\bar\theta(\lambda)\ne\theta^*.

Terms

θ∗\theta^*
population logistic risk minimizer; the target even when the model is misspecified
case-control
accept by label only; correct the intercept by b=log⁡(a(1)/a(0))b=\log(a(1)/a(0))
local case-control
accept with ∣y−p~(x)∣|y-\tilde p(x)|; refit and add the pilot back, θ^=θ^S+θ~\hat\theta=\hat\theta_S+\tilde\theta
log-odds shift
accepted-point logit =f(x)+log⁡(a(x,1)/a(x,0))=f(x)+\log(a(x,1)/a(x,0))
conditional imbalance
yy easy to predict from xx for most xx; CC cannot exploit it, LCC can
aˉ\bar a
acceptance rate E∣Y−p~(X)∣≈2E[p(1−p)]≤2P(Y=1)\mathbb E|Y-\tilde p(X)|\approx2\mathbb E[p(1-p)]\le2P(Y=1)
θˉ(λ)\bar\theta(\lambda)
large-sample limit for a fixed pilot λ\lambda; equals θ∗\theta^* at λ=θ∗\lambda=\theta^*
Corollary 7
Σ=H−1(CVC′+aˉ−1J)H−1\Sigma=H^{-1}(CVC'+\bar a^{-1}J)H^{-1}; pilot error enters through CC
Theorem 8
correct model, consistent independent pilot: covariance 2Σfull2\Sigma_{\rm full}
factor cc
accept ca∧1ca\wedge1, weight ca∨1ca\vee1; covariance at most (1+1/c)Σfull(1+1/c)\Sigma_{\rm full}
weighted CC
inverse-probability weights; consistent but inefficient; used as the pilot

Quiz

  1. The consistency theorem allows a pilot that depends on the data. Which device in the proof makes this possible?
  2. Fraud is 0.5% of 10 million transactions and the pilot is good. About how large is the local case-control subsample?
  3. With acceptance ca∧1ca\wedge1 and weight ca∨1ca\vee1 at c=4c=4, what does the theory give under strong imbalance?

Sources