Speed

Raw Features Have Different Scales

Measure column-wise min-to-max spans on a raw feature table to see how arbitrary measurement units dominate unscaled geometry.

The problem

Tabular datasets place columns measured in unrelated physical units side by side. Consider four homes recorded with three raw features [rooms, floor_sqft, age_years]: [2, 600, 5], [3, 900, 15], [4, 1500, 20], and [6, 2100, 45]. Every column describes the same four buildings, yet their numeric magnitudes differ by orders of magnitude.

Before rescaling anything, we need an exact column-by-column diagnostic: the range (max⁡−min⁡\max - \min) of each feature across rows. Reducing across the wrong tensor axis mixes rooms with square feet and years, producing numbers with no physical meaning.

Work through the numbers

Scan down axis 00 (across the four rows) for each of the three columns. In column 00 (rooms), values [2, 3, 4, 6] have minimum 22 and maximum 66, giving span 6−2=46 - 2 = 4 rooms.

In column 11 (floor_sqft), values [600, 900, 1500, 2100] have minimum 600600 and maximum 2,1002{,}100, giving span 2,100−600=1,5002{,}100 - 600 = 1{,}500 square feet. In column 22 (age_years), values [5, 15, 20, 45] have minimum 55 and maximum 4545, giving span 45−5=4045 - 5 = 40 years.

Collecting all three column ranges yields [4, 1500, 40]. Floor area spans 1,500/4=3751{,}500 / 4 = 375 times as many raw units as room count and 1,500/40=37.51{,}500 / 40 = 37.5 times as many units as building age, purely because area was recorded in square feet rather than hundreds of square meters.

The live model

Each bar shows one feature column's raw span as unit_scale multiplies column 11 (simulating a unit conversion on floor area). At default unit_scale =1.0= 1.0, the spans are [4, 1500, 40] and column 11 dwarfs the other two bars. Lowering unit_scale to 0.10.1 (tens of square feet) shrinks column 11's span to 150150 ([4, 150, 40]); raising unit_scale to 2.02.0 stretches column 11's span to 3,0003{,}000 ([4, 3000, 40]) without changing a single house.

Horizontal bars comparing raw column spans [4, 1500, 40] where floor_sqft dominates rooms and age_years.
let unit_scale = scene.parameter("unit_scale", 1.0, 0.1, 2.0, 0.1);
let c0 = input.select(1, 0).unsqueeze(1);
let c1 = (input.select(1, 1) * unit_scale).unsqueeze(1);
let c2 = input.select(1, 2).unsqueeze(1);
let tbl = torch.cat(torch.list().add(c0).add(c1).add(c2), 1);
let answer = tbl.amax(0) - tbl.amin(0);
out.set("column_spans", answer);
{
  "column_spans": [
    4,
    1500,
    40
  ]
}
Watch the parameter change

Your turn

The starter program mixes unrelated units within each row, returning the four-element vector [598, 897, 1496, 2094] instead of one range per feature column. Set answer to the 1D vector of per-column spans (hij−loj\mathrm{hi}_j - \mathrm{lo}_j) across rows; Check evaluates both the four-home table ([4, 1500, 40]) and unseen matrices with different row and column counts.

Starter bars reducing along axis 1 across unrelated columns instead of axis 0 column spans.
let row_hi = input.amax(1);
let row_lo = input.amin(1);
let answer = row_hi - row_lo;
out.set("column_spans", answer);
{
  "column_spans": [
    598,
    897,
    1496,
    2094
  ]
}

Return the 1D vector of column spans (column maximum minus column minimum across rows) for the 2D table input.

Read the result carefully

Look at what unit_scale =0.1= 0.1 versus 2.02.0 demonstrates: recording floor area in tens of square feet divides its numeric span by 1010 (1,500→1501{,}500 \to 150), recording it in doubled units doubles the span (1,500→3,0001{,}500 \to 3{,}000), and the underlying homes never change. The ratio between column 11 and column 00 moves from 1,500/4=3751{,}500 / 4 = 375 to 150/4=37.5150 / 4 = 37.5 or 3,000/4=7503{,}000 / 4 = 750.

Any algorithm that treats raw coordinate differences equally — Euclidean nearest neighbors, kk-means clustering, gradient descent with a shared learning rate, or L2L_2 weight penalties — will let the widest-span column dominate.

Measuring column spans max⁡iXi,j−min⁡iXi,j\max_i X_{i,j} - \min_i X_{i,j} is also your safety check against constant columns: a column whose span is 00 carries zero variation across training rows and cannot be divided by max⁡−min⁡\max - \min without special handling.

Recap

  • Raw feature columns reflect arbitrary measurement units, producing spans like [4, 1500, 40] on the same four observations.
  • Column statistics always reduce along axis 00 (across rows), never along axis 11 (across unrelated columns of one row).
  • Distance-based and regularized models require scaling because changing a feature's unit rescales its raw differences proportionally.