Feature Engineering: Keep the Coordinates Stable

  • A fitted transform includes parameters and column order.
  • Split first; fit on training rows; reuse on held-out rows.
  • Repeat fitting within each cross-validation training fold.
1 / 8

Min-max worked example

Train: [[2,10,7],[4,20,7],[6,30,7]]

  • Save mins=[2,10,7], maxs=[6,30,7].
  • Training outputs: [[0,0,0],[0.5,0.5,0],[1,1,0]].
  • Course zero-span policy: output zero.
2 / 8

Held-out values can leave the range

New row [8,15,9] transforms to [1.5,0.25,0].

  • Reuse training minima/maxima; do not refit.
  • No clipping is required.
  • Zero-span columns always return zero in this exercise.
3 / 8

Standardization stores an effective scale

Train: [[1,7],[3,7]]

  • Means [2,7]; population variances [1,0] using /n.
  • Saved stds=[1,1]; constant columns use scale one.
  • Training outputs [[-1,0],[1,0]]; held-out [5,9] -> [3,2].
  • Standardization does not make a distribution normal.
4 / 8

One-hot positions carry meaning

Saved categories: ["bird","cat","dog"]

  • cat -> [0,1,0]
  • bird -> [1,0,0]
  • dog -> [0,0,1]
  • Reuse this order even if a prediction batch omits a category.
5 / 8

Unknown categories

  • fox -> [0,0,0] under the exercise policy.
  • decode([0,0,0],categories) -> None.
  • Width stays fixed; unknown identity is lost.
  • Exactly one 1 applies only to known values.
6 / 8

Scaling is a modeling choice

  • It changes distance contributions and coefficient penalties.
  • Outliers influence ranges, means, and variances.
  • A count, flag, and ordinal feature may need different treatment.
  • Validate the representation using held-out performance.
7 / 8

Extend with the same fit boundary

  • Imputation statistics and selected features come from training data.
  • Interactions can expose nonlinear structure.
  • Target encoding needs out-of-fold training features.
  • Save preprocessing state with the trained model.
8 / 8
←/→ or click edges to navigate · ? help · N notes · F fullscreen