Context. Suppose a classifier is trained when 0.1% of cases are positive and deployed when 5% are; every borderline case is then scored against an obsolete prior. One would like to detect the change, estimate the new base rates and correct the model from unlabeled target data, which needs an assumption on how the joint law changes. Under label shift, changes while does not, which fits problems where the label causes the features. Earlier estimators (EM, kernel mean matching) had to model or match distributions of , which scales badly with dimension. This paper uses any trained classifier as a dimension reduction; the estimator has antecedents in epidemiology and quantification, and what is new is the finite-sample analysis, the test, and the use with high-dimensional . Under label shift any fixed function of has the same conditional law given under both distributions, so the target's distribution of predictions is a known linear mixture of the source's class-conditional prediction distributions, and the weights solve a linear system. The classifier need not be accurate or calibrated; it only has to make its confusion matrix invertible, and its quality enters the error only through that matrix's smallest singular value.
Setting. Labels take values in ; labeled source data come from and unlabeled target data from . Assume (A1) label shift, ; (A2) , so is finite; and (A3) a fixed classifier whose joint confusion matrix is invertible. Write , , , , with plug-in estimates (from labeled source data not used to train ), and . Black box shift estimation (BBSE) is Soft predictions work too, and their confusion matrix can be invertible when the hard one is not, for example when a rare class is never the argmax.
Proposition (consistency). Under A1-A3, and almost surely as . Theorem (error bound). Let be the smallest singular value of (the statement says eigenvalue, but is not symmetric and the proof uses the singular value, which is the quantity to check). There is a constant such that, if , then with probability at least , The dimension of does not appear. Proposition (detection). Under A1-A3, if and only if ; for any measurable and with no assumptions, implies .
Predictions inherit the invariance, and that gives a linear system. Because depends on only through , A1 gives , and total probability under reads The left side is estimated from unlabeled target data, from labeled source data, and A3 makes the system solvable. It is a method of moments in a -dimensional space chosen by the classifier. A biased or miscalibrated does no harm, because its bias is measured on the source and enters and in the same way. In the binary case this is the old adjusted count, ; the conditional confusion matrix has determinant , so an estimate built on a weakly discriminating score is unstable however well that score is calibrated. For a fraud or credit model, this is the base-rate estimate read off the scores of an unlabeled recent month.
Consistency is eventual invertibility plus the strong law. Let . is invertible once , which Hoeffding and a union bound make fail with probability exponentially small in , so by Borel-Cantelli is singular only finitely often. The strong law for , and , with continuity of matrix inversion at an invertible matrix, gives the almost-sure limits.
The error bound is a perturbation bound for a linear solve. Write and . Since , once (Weyl). is an average of independent centered rank-one matrices of bounded norm, so matrix Bernstein gives , which is where the sample-size condition comes from; Hoeffding on the coordinates gives . Read the bound term by term: the rates are parametric in the label dimension; grows with the size of the shift and is large when a class rare in the source becomes common; and measures the classifier, with for a perfect classifier and for one that cannot tell two classes apart. For , the term costs even if were known.
Testing for label shift reduces to a two-sample test on predictions. From Step 1, with invertible, so the prediction distributions agree exactly when the label distributions do. To test , compare on held-out source data with on target data by any two-sample test (Kolmogorov-Smirnov in the experiments). Validity needs nothing beyond A1, since under and the two samples come from one law; power comes from , and the low-dimensional test avoids a kernel test in dimension . Since implies for any , a rejection also flags covariate or concept shift and can be read as label shift only under A1, and some shifts leave unchanged.
Correction is importance-weighted ERM with the estimated weights. Under label shift , so minimizing over source data targets the risk under . The algorithm trains on one half of the source data and estimates on the other, falls back to when , and otherwise retrains with weights ; negative weights, possible for classes rare in the target, are clipped because they would make the objective unbounded below. There is no guarantee for the corrected classifier beyond consistency of its weights, and the paper suggests correcting only when the test of Step 4 rejects, since reweighting when nothing has shifted only adds variance.
In experiments the test on predictions has high power, and much of the accuracy gain comes from the prior. On resampled MNIST and CIFAR-10 with a two-layer MLP as , the Kolmogorov-Smirnov test on 's outputs has uniform p-values under no shift, power far above a kernel B-test on raw images and close to an infeasible oracle test on the labels, and more power for a better-trained , matching its larger . Kernel mean matching has lower weight error at the smallest , but BBSE's error falls faster and is lower by about ; hard and soft BBSE are close. Reweighting raises MNIST accuracy under the largest Dirichlet shift, and the gain fades as the shift shrinks. On CIFAR-10 the unweighted MLP sits near 43% under every shift while BBSE climbs toward 100% as the target concentrates on one class, and that gain comes mostly from the prior: under tweak-one shift, always predicting the tweaked class scores , and for BBSE scores about . Splitting the data to train makes BBSE worse than the baseline at very small , a cost a classifier already in deployment avoids.
Consequences and limits. Under label shift, one fixed classifier and two frequency tables are enough to detect the shift, estimate the new class proportions at a parametric rate independent of the dimension of , and reweight training. The classifier's quality enters only through , which can be checked on source data and used to choose among classifiers; the size of the shift enters through , which argues for balanced training classes when one can choose them. Everything rests on A1. When the class-conditional law of the features moves too, as when fraudsters adapt or a credit cycle changes who defaults within a class, fails: the detection test can still fire, but the estimated weights are wrong, and nothing in the method can tell that from the unlabeled data alone. The analysis treats as fixed and independent of the data used for . Later work regularizes the linear solve (Azizzadenesheli et al., 2019) and finds maximum likelihood (EM) on a calibrated classifier usually more accurate (Alexandari et al., 2020; Garg et al., 2020); the weights are also what weighted conformal prediction needs under label shift (Podkopaev and Ramdas, 2021).
Terms
- Label shift (A1)
- : class proportions change, class-conditional features do not; natural when causes .
- Importance weight on labels; under A1 it equals .
- Joint confusion matrix of the black box on source data; it must be invertible (A3).
- Moment identity
- : target prediction frequencies are a known linear mixture of source class-conditionals.
- BBSE
- , ; a solve, no model of .
- Smallest singular value; the classifier's quality in the bound, for a perfect classifier and 0 for one that cannot tell two classes apart.
- Error bound
- , with no dependence on the dimension of .
- Adjusted count
- Binary case: .
- BBSD
- Two-sample test of against ; under A1-A3 it tests exactly.
- BBSC
- Importance-weighted ERM with clipped weights , falling back to if is small.
Quiz
- Which property of the classifier controls the estimation error in the theorem?The error is a perturbation of the solve , and amplifies the sampling errors. A classifier that cannot separate two classes makes singular and the weights unidentifiable.
- In the binary case BBSE is the adjusted count . When is this estimate unstable?Dividing by inflates the sampling error of the numerator, and that difference is the determinant of . Calibration plays no role, and a large target sample only helps.
- A fraud model's score distribution on recent transactions moves, and BBSE reports a higher fraud rate. Which situation breaks the estimate even though the test correctly reports a change?BBSE needs A1. If moves, fails and the solve returns wrong weights, though still flags a change. Calibration does not matter, and a large only increases variance.
Sources
- Zachary C. Lipton, Yu-Xiang Wang, and Alex Smola. Detecting and Correcting for Label Shift with Black Box Predictors. ICML, 2018.
- Kamyar Azizzadenesheli, Anqi Liu, Fanny Yang, and Animashree Anandkumar. Regularized Learning for Domain Adaptation under Label Shifts. ICLR, 2019.
- Amr Alexandari, Anshul Kundaje, and Avanti Shrikumar. Maximum Likelihood with Bias-Corrected Calibration is Hard-To-Beat at Label Shift Adaptation. ICML, 2020.
- Saurabh Garg, Yifan Wu, Sivaraman Balakrishnan, and Zachary C. Lipton. A Unified View of Label Shift Estimation. NeurIPS, 2020.
- Aleksandr Podkopaev and Aaditya Ramdas. Distribution-free uncertainty quantification for classification under label shift. UAI, 2021.