df = pd.DataFrame({"x": [1.0, 2.0, 3.0, 4.0]})
df| x | |
|---|---|
| 0 | 1.0 |
| 1 | 2.0 |
| 2 | 3.0 |
| 3 | 4.0 |
Center and scale numeric columns to zero mean and unit variance.
Usage
Each selected numeric column x is replaced in place by (x - mean) / std, using the column’s mean and standard deviation. To scale onto a fixed interval instead, see StepRange; to reshape a skewed distribution, see StepOrderNorm.
Constant (zero-variance) columns among the selection cannot be scaled to unit variance; they are dropped from the normalization (with a warning) and pass through transform untouched. You can get rid of these warnings by adding a StepDropZeroVariance before this step.
See Normalization in Feature Engineering A to Z for background on this technique.
See Arguments shared across steps for the arguments this step shares with the others.
columns: SelectorColumns to normalize. Accepts a single column name, a list of names, a mlfeatures selector such as Selectors.numeric_features() (see Selectors for the full set), or a narwhals or polars selector (narwhals.selectors.numeric(), polars.selectors.numeric()). Selectors are resolved against the data frame’s schema when the recipe is fitted, so the same selector works on any backend. Only numeric columns are meaningful here.
id: str | None = None"normalize"; a second step of this type in the same recipe becomes "normalize_2", and passing an id already used in the recipe is an error.
Each selected column is replaced in place by its centered, unit-variance values:
Specifying the step touches no data:
Recipe (untrained)
Inputs: no roles assigned
Steps:
step_normalize(select(role='feature', type=NumericType)) [untrained]
fit() learns each column’s mean and standard deviation:
Recipe (trained)
Inputs: 1 columns (1 feature)
Steps:
step_normalize(x) [trained]
transform() applies them in place: