What Missing Handling Is and Is Not
Separate what train-fitted imputation and missingness indicators guarantee—finite inputs and honest held-out scoring—from what they cannot do: recover unobserved measurements or survive a change in why values go missing.
The problem
Across the preceding five pages, we isolated -1 sentinels, computed training means and training modes, assembled filled feature columns, and appended binary missingness indicators. A tempting misconception is that imputation reconstructs the missing measurement itself.
It does not. Consider six rows [role, x_raw, y]: four training rows ([1, 2, 5], [1, 4, 9], [1, 6, 13], [1, -1, 21]) and two held-out rows ([0, 5, 11], [0, -1, 19]). On observed rows, y = 2 * x + 1; here the slope 2 and intercept 1 are taken as known so this page can isolate the missingness offset on its own.
When the sensor clips above range, x_raw records -1 while y sits near 19 or 21. Missing handling provides a consistent feature map—not the true unseen x (9 on r5, 10 on r3).
Work through the numbers
Observed training inputs on r0, r1, and r2 are 2, 4, and 6, giving x_mean = 12 / 3 = 4. Filling -1 yields x_fill = [2, 4, 6, 4, 5, 4], so the baseline formula base = 2 * x_fill + 1 predicts [5, 9, 13, 9, 11, 9]. Notice that x_fill = 4 on r5 is nowhere near the true underlying 9 that generated y = 19; using base alone leaves residuals 12 on r3 and 10 on held-out r5.
Adding the indicator column miss = [0, 0, 0, 1, 0, 1] lets training row r3 fit a missingness offset shift = 21 - 9 = 12. Freezing pred = base + miss * 12 produces [5, 9, 13, 21, 11, 21] with absolute errors [0, 0, 0, 0, 0, 2], cutting held-out error on r5 from 10 down to 2 without ever knowing r5's true x.
The live model
The table displays raw x, target y, frozen prediction Pred, and |y - Pred|. At default r5_y = 19, sensor dropout at test time follows the same high-load pattern seen in training, so Pred = 21 misses by 2. Drag r5_y right to 23 and Pred stays 21 with residual 2. Now drag r5_y left to 7—simulating a loose cable during low load—and watch Pred remain frozen at 21 while |y - Pred| jumps to 14.

let r5_y = scene.parameter("r5_y", 19.0, 7.0, 23.0, 4.0);
let table = input.clone();
table.set(17, r5_y);
let role = table.select(1, 0);
let x_raw = table.select(1, 1);
let y = table.select(1, 2);
let miss = x_raw.lt(0.0).to(DType.F64);
let tr_obs = role * x_raw.ge(0.0).to(DType.F64);
let x_mean = (x_raw * tr_obs).sum().div(tr_obs.sum());
let x_fill = torch.where(x_raw.lt(0.0), x_raw * 0.0 + x_mean, x_raw);
let base = x_fill * 2.0 + 1.0;
let tr_miss = role * miss;
let shift = ((y - base) * tr_miss).sum().div(tr_miss.sum());
let pred = base + miss * shift;
let err = (y - pred).abs();
let answer = torch.stack(torch.list().add(pred).add(err), 1);
out.set("x_mean", x_mean).set("shift", shift).set("pred_err", answer);
{
"x_mean": 4,
"shift": 12,
"pred_err": [
[
5,
0
],
[
9,
0
],
[
13,
0
],
[
21,
0
],
[
11,
0
],
[
21,
2
]
]
}Your turn
Although the starter computes the training offset shift = 12, its predictions on offline rows 3 and 5 stay stuck at 9, leaving errors of 12 and 10. Apply that learned offset on unrecorded rows so answer pairs each row's full prediction with its absolute error.

let table = input;
let role = table.select(1, 0);
let x_raw = table.select(1, 1);
let y = table.select(1, 2);
let miss = x_raw.lt(0.0).to(DType.F64);
let tr_obs = role * x_raw.ge(0.0).to(DType.F64);
let x_mean = (x_raw * tr_obs).sum().div(tr_obs.sum());
let x_fill = torch.where(x_raw.lt(0.0), x_raw * 0.0 + x_mean, x_raw);
let base = x_fill * 2.0 + 1.0;
let tr_miss = role * miss;
let shift = ((y - base) * tr_miss).sum().div(tr_miss.sum());
let pred = base;
let err = (y - pred).abs();
let answer = torch.stack(torch.list().add(pred).add(err), 1);
out.set("x_mean", x_mean).set("shift", shift).set("pred_err", answer);
{
"x_mean": 4,
"shift": 12,
"pred_err": [
[
5,
0
],
[
9,
0
],
[
13,
0
],
[
9,
12
],
[
11,
0
],
[
9,
10
]
]
}Combine the mean-imputed baseline prediction with the training missingness offset on unrecorded rows so answer stacks each row's prediction beside its absolute error.
Including the missingness offset lifts predictions on r3 and r5 from 9 to 21, cutting their residuals from 12 and 10 down to 0 and 2.
Read the result carefully
Separate the engineering guarantee from the statistical assumption. Deterministically, train-only imputation plus indicators guarantees finite matrices with zero held-out leakage so downstream linear or tree models can score any row containing -1.
Statistically, every imputed constant shrinks feature variance toward x_mean, and every indicator weight assumes test-time missingness shares the training mechanism. High-range clipping makes absence depend on the unseen value itself (missing not at random), whereas a broken wire that drops readings regardless of any variable is missing completely at random; when the field cause switches from one to the other, frozen rules extrapolate the old offset blindly.
Recap
- Imputation substitutes a frozen training summary (
x_mean = 4) so matrix arithmetic runs cleanly; it never recovers an individual row's true unobserved value. - Pairing filled values with
misscaptures informative dropout (shift = 12) only when training and deployment share the same missingness mechanism. - Missing-value preprocessing prevents crashes and leakage, whereas domain shifts in how gaps arise still degrade held-out accuracy.