CS230 — Original on-site preparation
Independent written study. All essential explanations and optional model reasoning for this chapter are on this page. References are optional further study. No degree, professional approval or observed competence is conferred.
A transformation is fitted state inside an evaluation design
The original training-only imputation investigation remains the starting point. Extend it by writing a feature contract: row identity and customer group, prediction time, outcome horizon, each input's type and units, valid range, availability time and missing-value meaning. A blank can mean collection failure, not applicable or withheld information. Those mechanisms can associate with outcomes and change across sites. An observed association does not establish that replacing the blank recovers the missing value or preserves a causal estimand.
For a numerical column, mean or median imputation learns a replacement from observed training entries. A constant fill is an explicit policy rather than an estimated value. A missingness indicator can preserve the fact that a value was absent, but can also encode an unstable collection practice. An entirely missing training column has no empirical mean; choose and document an explicit fallback or exclusion instead of dividing by zero. More elaborate iterative or nearest-neighbor imputers add model assumptions and hyperparameters. They must be fitted and evaluated within training folds just like a predictor.
Standard scaling learns training mean μ and standard deviation s, then transforms x to (x−μ)/s. For training [2,6], using the population standard deviation convention gives μ=4,s=2 and transformed values [−1,1]. A held-out100 becomes48; refitting the scaler on held-out observations would implement a different procedure. Libraries can use different variance conventions; name the convention before comparing numbers. A zero-variance feature cannot use literal division by zero; handle it under a declared policy. Extreme held-out standardized values can reveal extrapolation or shift, not automatically a coding error.
Min–max scaling learns endpoints and maps x to (x−min)/(max−min). For the same training data,100 maps to24.5, outside[0,1]. This is expected when a new value exceeds the training maximum. Clipping would change the rule and discard that magnitude information. Robust scaling instead uses training quantiles; it may reduce sensitivity to extreme values but does not establish representativeness or eliminate the need to evaluate shift.
Categorical encoders learn a vocabulary and column order. With training categories blue and red, a one-hot representation might assign[1,0] and[0,1]. A new green category requires a documented unknown-category behavior, such as rejection or a separate unknown column. Silently reordering columns or treating green as red violates the model contract. Ordinal integer codes create a numeric order that nominal categories do not possess. When an encoder uses target statistics, additional leakage controls are needed; never encode evaluation labels into their own inputs.
A pipeline packages fitted preprocessing followed by an estimator. A column-wise transformer can apply different numerical and categorical rules and concatenate outputs in a stable order. During fitting, transformations learn from the training subset; prediction applies those saved transformations without relearning from the target batch. In cross-validation, fit the entire pipeline independently on each fold's training data. Feature selection, vocabulary construction and dimensionality reduction also learn from data even when labels are not used. Fitting them globally before folding contaminates the evaluation boundary.
For independent observations a random split can approximate new draws from the same population. Grouped splits address new entities; chronological splits address future periods. The choice follows deployment, not the highest score. A customer-disjoint split alone does not enforce time availability, while a time split alone can include recurring customers. Declare both when the intended use requires both. Reserve an untouched final set after development choices; repeated adaptation to its results turns it into development evidence. Cross-validation variability is not automatically a confidence interval for every future setting.
Distribution shift can concern input frequencies, outcome prevalence or the input–outcome relationship. Changed devices, policies, customers and label collection can all matter. A preprocessing pipeline preserves a specified fitting procedure; it does not certify stability of those relationships. Monitor data contracts and performance with denominators, record delayed labels, and distinguish unlabeled input checks from observed predictive performance. Reproducibility of a seed or fixture cannot establish validity of leaked evaluation.
Optional changed record: trace fitted values through a fold
Training values are[1,missing,5] and held-out values are[9,missing]. Fit a mean imputer, then standard scaling on the imputed training column using population variance. Calculate both transformed partitions. A colleague instead fits the imputer on all observed values and calls the result acceptable because labels were unused.
The training fill is3, so training becomes[1,3,5] and held-out becomes[9,3]. The training mean is3 and population variance is(4+0+4)/3=8/3, giving standard deviation √(8/3). Training outputs are[−√(3/2),0,√(3/2)], while held-out outputs are[3√(3/2),0]. The alternative fill(1+5+9)/3=5 transmits the held-out feature distribution into fitted state. Omitting labels does not restore the declared training-only boundary. In another cross-validation fold, relearn both imputer and scaler using only that fold's training rows.
Optional criteria: distinguish missingness meaning from numerical replacement; reproduce the fitted statistics with their convention; trace the same saved transformations into held-out data; justify entity/time/availability boundaries and remaining shift limits. Award one point per fully explained criterion. The preserved native leakage case and complete application provide further optional implementation practice.
Optional source references
These sources support the explanations; reading them is optional. Original Academy examples are fictional. Historical attributed readings remain preserved.