PythiloLesson 1 of 8 · progress kept in this browser

Fit preprocessing on training data only

A model evaluation is misleading when preprocessing learns from held-out observations. Compute the mean and population standard deviation on the training values, then reuse those parameters for later values. A constant training feature needs an explicit policy: use a scale of one so it transforms to zero without division by zero.

train = [2.0, 4.0]
mean, scale = 3.0, 1.0
print((10.0 - mean) / scale)
Your task

Write fit_scale(train), returning (mean, population_standard_deviation), with scale 1.0 for a constant feature. Raise ValueError for empty training data. Write transform(values, mean, scale) returning standardized values using the supplied parameters.