Held-Out MAE
Collapse masked held-out absolute errors into a single Mean Absolute Error scalar by dividing the held-out error sum by te_mask.sum().
The problem
Score Held-Out Rows produced a masked vector with positive absolute errors on held-out slots and zeros on training slots. To compare two candidate models at a glance, we summarize those held-out misses into one scalar in the original target units: Held-Out Mean Absolute Error (MAE).
Calling .mean() directly on the masked error vector is a classic bug. Because four of the six slots hold masked training zeros, .mean() divides the two held-out errors by six instead of two, reporting only one-third of the true error.
Work through the numbers
Inspect six [role, y] observations: [1, 10], [1, 14], [0, 7], [1, 18], [0, 31], and [1, 22]. Across the four training rows (10, 14, 18, 22), the sum is 64 and tr_mean = 64 / 4 = 16.
Against 16, held-out row r2 (y = 7) misses by |7 - 16| = 9, and held-out row r4 (y = 31) misses by |31 - 16| = 15. Multiplying (y - 16).abs() by te_mask gives te_err = [0, 0, 9, 0, 15, 0], whose sum is 9 + 15 = 24.
Dividing 24 by te_mask.sum() = 2 yields held_out_mae = 24 / 2 = 12. Calling te_err.mean() instead divides 24 by 6 and falsely claims 4—identical to the in-sample training MAE (6 + 2 + 2 + 6) / 4 = 4.
The live model
Amber bars show the scored held-out residuals (9 on r2 and 15 on r4), grey bars show excluded training residuals (6, 2, 2, 6), and the horizontal amber line marks held_out_mae. At default r4_y = 31, held_out_mae sits halfway between 9 and 15 at 12. Drag r4_y left to 19 (|19 - 16| = 3) to lower held_out_mae to (9 + 3) / 2 = 6, or drag right to 43 (|43 - 16| = 27) to raise held_out_mae to (9 + 27) / 2 = 18.

let r4_y = scene.parameter("r4_y", 31.0, 19.0, 43.0, 6.0);
let table = input.clone();
table.set(9, r4_y);
let role = table.select(1, 0);
let y = table.select(1, 1);
let tr_mask = role.eq(1.0).to(DType.F64);
let te_mask = role.eq(0.0).to(DType.F64);
let tr_mean = (y * tr_mask).sum().div(tr_mask.sum());
let te_err = te_mask * (y - tr_mean).abs();
let te_mae = te_err.sum().div(te_mask.sum());
let answer = te_mae.reshape(1);
out.set("train_mean", tr_mean).set("held_out_mae", answer);
{
"train_mean": 16,
"held_out_mae": [
12
]
}Your turn
The two amber held-out bars have heights 9 and 15, yet the starter's summary line sits way down at 4—below both bars it is supposed to average. Summarize only the held-out misses so answer reports [12], whether a split holds out two rows or three.

let table = input;
let role = table.select(1, 0);
let y = table.select(1, 1);
let tr_mask = role.eq(1.0).to(DType.F64);
let te_mask = role.eq(0.0).to(DType.F64);
let tr_mean = (y * tr_mask).sum().div(tr_mask.sum());
let te_err = te_mask * (y - tr_mean).abs();
let te_mae = te_err.mean();
let answer = te_mae.reshape(1);
out.set("train_mean", tr_mean).set("held_out_mae", answer);
{
"train_mean": 16,
"held_out_mae": [
4
]
}Summarize the masked held-out errors into a 1-element Mean Absolute Error scalar averaged strictly over the held-out rows.
Averaging over the two held-out rows alone lifts held_out_mae from 4 up to 12, halfway between the amber bars 9 and 15.
Read the result carefully
Compare this denominator rule with Train Mean Uses Train Rows: every masked average in tensor code follows (values * mask).sum().div(mask.sum()). Notice also why MAE stays in the original units of y (dollars, degrees, minutes): unlike squared error, doubling both held-out misses doubles MAE linearly without letting a single outlier dominate quadratically.
Recap
- Sum the masked held-out absolute errors
te_err.sum()(9 + 15 = 24). - Divide strictly by
te_mask.sum()(2) to obtainheld_out_mae = 12. - Never call
.mean()on a zero-masked vector: an80/20train-test split would understate held-out MAE by a factor of five.