Raw Table Has Row IDs
Strip database primary keys and arbitrary row identifiers from raw tables before forming numeric feature columns so model inputs stay invariant to renumbering.
The problem
Raw SQL exports and spreadsheets almost never start with predictors. Column 0 is routinely an administrative primary key—invoice_id, patient_chart_no, or listing_id—assigned sequentially or randomly when a record enters storage. Because those keys are stored as numbers (101, 205, 310), a naive table -> tensor pipeline treats them as quantitative measurements alongside room counts or ages.
Leaving row_id inside a feature matrix corrupts geometry and linear weights alike: migrating the database from IDs 100..500 to 500..900 shifts every dot product even though the physical apartments did not change at all.
Work through the numbers
Inspect five apartment records stored as [row_id, rooms, age]: [101, 2, 4], [205, 3, 2], [310, 4, 6], [412, 2, 8], and [518, 5, 1]. Notice how row_id spans 417 units (101 to 518), dwarfing rooms (2 to 5) and age (1 to 8).
Suppose a scorer evaluates 10 * rooms - age on the physical attributes alone, giving [16, 28, 34, 12, 49]. If row_id leaks in with even a tiny weight 0.1, row 0 becomes 0.1 * 101 + 16 = 26.1 while row 4 becomes 0.1 * 518 + 49 = 100.8—and adding 400 to every ID shifts every leaked score upward by +40. Dropping column 0 retains columns 1 and 2 in order: [[2, 4], [3, 2], [4, 6], [2, 8], [5, 1]].
The live model
The left panel displays the three-column raw export with row_id shaded grey; the right panel shows the extracted 5-by-2 [rooms, age] matrix in green. At default id_offset = 0, raw keys run 101..518 and leaked_id_score starts at 26.1. Drag id_offset to 200 (301..718) or 400 (501..918): leaked_id_score climbs by +20 and +40 on every row, whereas clean_features stays fixed at [[2, 4], [3, 2], [4, 6], [2, 8], [5, 1]].
![Five apartment rows stripping primary-key column row_id (101..518) to retain the 5x2 measurement matrix [rooms, age].](../assets/ml/raw-table-has-row-ids--demo.png)
let id_offset = scene.parameter("id_offset", 0.0, 0.0, 400.0, 200.0);
let raw_id = input.select(1, 0) + id_offset;
let rooms = input.select(1, 1);
let age = input.select(1, 2);
let table = torch.stack(torch.list().add(raw_id).add(rooms).add(age), 1);
let answer = torch.stack(torch.list().add(rooms).add(age), 1);
let leaked = raw_id * 0.1 + rooms * 10.0 - age;
out.set("clean_features", answer).set("leaked_id_score", leaked);
{
"clean_features": [
[
2,
4
],
[
3,
2
],
[
4,
6
],
[
2,
8
],
[
5,
1
]
],
"leaked_id_score": [
26.1,
48.5,
65,
53.2,
100.80000000000001
]
}Your turn
In the starter, slot 0 of answer carries the database keys 101..518 (shaded red) while the apartment ages never enter the matrix. Keep only the two physical measurements in table order so renumbering keys leaves answer unchanged. Check tests a four-row export keyed 9001..9004 and a six-row export keyed 17..89.

let table = input;
let col0 = table.select(1, 0);
let rooms = table.select(1, 1);
let age = table.select(1, 2);
let answer = torch.stack(torch.list().add(col0).add(rooms), 1);
out.set("clean_features", answer);
{
"clean_features": [
[
101,
2
],
[
205,
3
],
[
310,
4
],
[
412,
2
],
[
518,
5
]
]
}Form the N-by-2 feature matrix answer from input so only the physical apartment measurements enter, in their table order.
Once only the physical attributes remain, all five rows turn green at [[2, 4], [3, 2], [4, 6], [2, 8], [5, 1]].
Read the result carefully
Watch for a second hazard beyond renumbering sensitivity: index leakage. In historical exports, row_id often correlates accidentally with outcomes—for instance, when positive cases were appended in a separate batch at the end of a file (row_id > 8000).
A model handed row_id can fit that filing artifact on the training file: any outcome that happens to rise or fall with the order in which rows were filed is predicted from the id alone. None of that fit transfers to fresh records, whose ids start from a new range.
Keep row_id in a separate lookup array for joining predictions back to records, never inside X.
Recap
- Audit column
0of every raw export for administrative keys (row_id, timestamps of ingestion, batch numbers) before building tensors. - Exclude
row_idso the feature matrix[[2, 4], [3, 2], [4, 6], [2, 8], [5, 1]]remains invariant when database keys shift. - Store identifiers alongside—never inside—the numeric predictors passed to a model.