Skip to content

Sampling by weight inside each tree removes the QRF's tail seed lottery on public SCF and CPS tests #1798

Backlog

Description

@juaristi22

Summary

_fit_forest applies donor weights by resampling the donor rows once per forest (_weighted_bootstrap). Every tree then bootstraps uniformly from that one resample. #481 describes what this does to the extreme tail.

scikit-learn 1.9 offers a second way: pass the weights to the forest's fit, and each tree draws its own rows in proportion to weight. We tested it on public SCF and CPS data while working on PolicyEngine/imputation-paper.

  • With the donors fixed and 20,000 receivers, the shipped resample put the imputed 99th percentile of net worth more than 25% from its typical value in 11 of 120 fits. Per-tree sampling did so in 0 of 120.
  • Per-tree sampling improved a test of conditional fit by 0.012 to 0.015 AUC, to the level of an unweighted fit, while the imputed totals stayed weighted.
  • The dollar measures changed little, and not in one direction.

We did not measure any of this on production donors. We recommend measuring it on one production imputation and adopting it if the result holds there. #1691 already needs scikit-learn 1.9 for quantile-forest 1.5.0, so the two changes could share one re-pin.

A separate finding on the sign gate is at the end. We recommend no change for it.

What we ran

  • Package: microcosm-fit at the paper's pin (b538d8a). Main's _fit_forest resamples the same way (read at 5589fae).
  • Versions: scikit-learn 1.8.0 with quantile-forest 1.4.2, which is the paper's environment and main's lockfile; scikit-learn 1.9.1 with quantile-forest 1.4.2; scikit-learn 1.9.1 with quantile-forest 1.5.0.
  • Data: the SCF 2022 and 2025 public extracts (net worth and debt, about 3,500 donor households), CPS ASEC (dividends and interest, 16,000 donors), six OpenML sets, and the paper's SCF-to-CPS experiment (SCF donors, 20,000 CPS receiver households).
  • Arms: the estimator as shipped; per-tree sampling, run natively under scikit-learn 1.9.1 and emulated under 1.8.0 (the two agree bit for bit where both run); one weighted pool of 2, 5 or 10 times the donor rows per forest; the unweighted fit.
  • Seeds: 30. We fixed the rule for what counts as a difference before reading the comparisons: a mean paired difference above twice its standard error, with the same sign in at least 80% of seeds.

What the one-off resample reads

  • It keeps 51% of the distinct donor rows on the SCF and 57% on the CPS. Per-tree sampling reaches 96% on the SCF.
  • The SCF oversamples wealthy households and gives them low weights. Of the donor rows above the weighted 99th percentile of net worth, the one-off resample keeps 7%. Per-tree sampling reaches 74%.
  • The mean of net worth over the rows a forest reads, relative to the weighted mean, has a standard deviation across seeds of 0.20 as shipped and 0.011 with per-tree sampling (SCF 2022).

Stability

A production build fixes the donors, imputes onto many receivers and uses one seed. We reproduced that case: SCF donors fixed, 20,000 CPS receivers, three donor splits per wave, 20 estimator seeds per split.

  • As shipped, the imputed 99th percentile of net worth landed more than 25% from that split's median in 1, 1 and 2 of 20 seeds on SCF 2022, and in 1, 4 and 2 of 20 on SCF 2025. With per-tree sampling it never did, in 120 fits.
  • On SCF 2022, the standard deviation across estimator seeds fell to 0.47 of the shipped value for the 99th percentile, 0.54 for the 90th and 0.67 for the total. On SCF 2025, the standard deviation of the 99th percentile (as a ratio to the donors') fell from 0.41 to 0.030, and the total's from 0.22 to 0.025.
  • As shipped, most of the run-to-run variance came from the fit and not from the draw. The standard deviation of the imputed total was 0.048 across estimator seeds and 0.014 across redraws from one fit (SCF 2022).
  • In the paper's SCF-to-CPS experiment, extended to 30 donor splits, one split gave a 99th percentile 13.4 times the holdout's as shipped and 0.71 times with per-tree sampling.
  • The typical value did not change. The median 99th percentile was 0.59 to 0.67 of the donors' as shipped and 0.61 to 0.69 with per-tree sampling.

Per-tree sampling removes a spread. It does not remove a bias.

Conditional fit

The test trains a classifier to tell true target values from imputed ones, given the same predictors. An AUC of 0.5 means it cannot tell them apart.

  • As shipped: 0.561 (SCF 2022), 0.564 (SCF 2025), 0.534 (CPS). Per-tree: 0.546, 0.552, 0.522. Unweighted fit: 0.546, 0.542, 0.521.
  • By the rule fixed in advance, only the CPS difference counts: it holds in 93% of seeds and is larger than the test's own noise. On the SCF the difference is about three standard errors from zero and holds in 70% to 77% of seeds.
  • Native scikit-learn 1.9.1 gives the same figures with quantile-forest 1.4.2 (30 seeds) and with 1.5.0 (ten seeds).
  • The cost is the same where weights are equal. On the six OpenML sets the shipped resample costs 0.013 AUC against the unweighted fit, and per-tree sampling removes 89% of that.

What did not change

  • No dollar measure moved by an amount that counts under that rule. Imputed net-worth totals were 0.98 and 1.00 of the survey's as shipped, and 1.04 and 0.98 with per-tree sampling. The 99th percentile was 1.08 and 1.02 as shipped, and 1.07 and 1.03 with per-tree sampling.
  • In the SCF-to-CPS experiment the imputed 99th percentile stayed at 0.6 to 0.7 of the holdout's in every arm.
  • A weighted pool of five times the donor rows also removed the tail spread. It recovered less of the conditional fit (75%) and cost more time (1.4 to 1.6 times the shipped fit).

What a change would involve

  • The code. In _fit_forest, pass the weights to fit and drop the call to _weighted_bootstrap. Gates, chaining and the draw stay as they are.
  • A hard floor on scikit-learn 1.9. pyproject.toml declares scikit-learn>=1.5 and uv.lock has 1.8.0. Under 1.8 the same call runs without error and ignores the weights when it samples.
  • max_samples stays None. From 1.9 a float means a share of the weight total, not of the rows.
  • Zero weights. quantile-forest 1.4.2's zero-weight leaf filter indexes the weights by position in the bootstrap sample, not by row, and main's in-place copy of the leaf code carries the same line. In a test with a fifth of the rows at zero weight, it dropped 15% of each tree's valid draws. quantile-forest 1.5.0 keeps them all.
  • One-row forests. quantile-forest 1.4.2 fails on a forest with one training row when weights are passed.
  • Fit time, against the shipped estimator: 1.19 to 1.47 times with quantile-forest 1.4.2, and 1.07 times (SCF) and 1.18 times (CPS) with 1.5.0.
  • Pins. Every draw changes, so the pins that hash qrf.py move and builds need re-certifying, as Move microcosm's QRF to quantile-forest 1.5.0 #1691 notes for its own change.
  • Versions move draws by themselves. 95% to 99% of imputed values were identical between scikit-learn 1.8.0 and 1.9.1, and 71% to 97% between quantile-forest 1.4.2 and 1.5.0.

One caution. We ran a test with a known answer: a low-weight group whose true weighted share is 0.10, and a predictor that carries no information. Every weighted arm drew the low-weight group too often: 0.128 as shipped and 0.111 with per-tree sampling. A tree grown to one row per leaf gives that row the same reach whatever its weight. Per-tree sampling reduces the excess and does not remove it.

Recommendation

  1. Measure first, without a build. Run per-tree sampling offline on one production imputation with its real weights and its donors fixed. One of the stages named in QRF amount forests lose donor design weights after the n-of-n bootstrap: extreme-tail draws are a seed lottery #481 would be a natural choice. Read three things: the spread of an aggregate across estimator seeds, the dollar measures, and the classifier score against the unweighted fit.
  2. Adopt it if it holds. If the spread falls and no aggregate moves by an amount that matters, make the change together with Move microcosm's QRF to quantile-forest 1.5.0 #1691, so that the draws and the pins move once.
  3. Until then, nothing in the package needs to change.

Sign gate: a finding, with no change recommended

  • In one of the paper's experiments, net worth is drawn after financial assets, nonfinancial assets and debt. Net worth is their signed sum, so the gate's inputs determine its sign classes almost exactly.
  • In that case the gate (HistGradientBoostingClassifier at its defaults) does not converge. Its training loss rises on 46 of 60 donor splits. On five of them it gave negative net worth to between 21% and 52% of receivers, where the holdout has about 9%.
  • scikit-learn's only guard on the boosting step is a floor of 0.001 on a leaf's hessian. That number is absolute, in the units of the weights. SCF weights average several thousand, so the floor never binds. Dividing the weights by their mean lowers the count to 35 of 60 splits and is not a fix.
  • Main reproduces the failure with the default gate_calibration="in_sample". With "cross_fitted" the sign shares come out right, but the calibration slope falls to about 0.001 (0.39 to 0.44 for a gate that converges), so the gate no longer says which rows are negative. "cross_fitted_balanced" converges.
  • The gates for the three components converged in all 360 fits.
  • Production. From a reading of main, no US or UK stage draws a signed target after the items that determine its sign. US SCF net_worth is a single-target fit on eight predictors, and the WAS totals are derived after the draw. We ran no production build to confirm this.

We recommend no change, because no production stage is known to be in this configuration. The condition is more general than this experiment: a gate whose inputs nearly determine a small sign class. The code alone cannot rule it out for a chain that passes an earlier total on as a predictor. Where it occurs, it shows as a gate whose training loss is above the loss of its class rates, or as a cross-fitted slope near zero. No receipt records either number today.

Scope

  • Public data only: SCF public extracts, CPS ASEC and OpenML. The donor files have 3,500 to 16,000 rows. Production pools are larger, and calibrated weights have zeros and a wider range.
  • The per-tree arm, the fixed-donor experiment and their per-seed outputs on the three survey tasks are in Measure what the estimator's one-off weighted resample costs imputation-paper#20. The runs under scikit-learn 1.9, the pools and the fit times are from a local diagnosis and can be shared on request.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions