## StepNormalize


Center and scale numeric columns to zero mean and unit variance.


Usage

``` python
StepNormalize(
    columns,
    *,
    id=None,
)
```


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](StepRange.md#mlfeatures.StepRange); to reshape a skewed distribution, see [StepOrderNorm](StepOrderNorm.md#mlfeatures.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](Step.transform.md#mlfeatures.Step.transform) untouched. You can get rid of these warnings by adding a [StepDropZeroVariance](StepDropZeroVariance.md#mlfeatures.StepDropZeroVariance) before this step.

See [Normalization](https://feaz-book.com/numeric-normalization) in *Feature Engineering A to Z* for background on this technique.

See [Arguments shared across steps](../user-guide/common-step-arguments.md) for the arguments this step shares with the others.


## Parameters


`columns: Selector`  
Columns to normalize. Accepts a single column name, a list of names, a mlfeatures selector such as [Selectors.numeric_features()](Selectors.md#mlfeatures.Selectors.numeric_features) (see [Selectors](Selectors.md#mlfeatures.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`  
Stable step identifier. Defaults to `"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.


## Examples

Each selected column is replaced in place by its centered, unit-variance values:


``` python
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 |


Specifying the step touches no data:


``` python
recipe = Recipe().add(StepNormalize(s.numeric_features()))
recipe
```


    Recipe (untrained)
      Inputs: no roles assigned
      Steps:
        step_normalize(select(role='feature', type=NumericType))  [untrained]


[fit()](Step.fit.md#mlfeatures.Step.fit) learns each column's mean and standard deviation:


``` python
fitted = recipe.fit(df)
fitted
```


    Recipe (trained)
      Inputs: 1 columns (1 feature)
      Steps:
        step_normalize(x)  [trained]


[transform()](Step.transform.md#mlfeatures.Step.transform) applies them in place:


``` python
fitted.transform(df)
```


|     | x         |
|-----|-----------|
| 0   | -1.161895 |
| 1   | -0.387298 |
| 2   | 0.387298  |
| 3   | 1.161895  |
