Feature preprocessing
Prepare numeric columns before a neural network consumes them.
TensorFlow · Class
A Keras preprocessing layer that standardizes continuous features using stored mean and variance. Statistics can be supplied at construction or learned with adapt().
Normalization learns or receives feature statistics, then shifts and scales inputs using those values. With the default axis, each feature index gets its own mean and variance; setting invert=True reverses the transformation.
tf.keras.layers.Normalization(axis=-1, mean=None, variance=None, invert=False, **kwargs)| Name | Type | Description |
|---|---|---|
axis | Integer, tuple of integers, or None | Axis or axes receiving separate statistics for each index; None uses scalar statistics across all input elements. |
mean | Optional value or values | Mean value or values used for normalization; they must broadcast to the retained-axis shape. |
variance | Optional value or values | Variance value or values used for normalization; they must broadcast to the retained-axis shape. |
invert | Boolean | If true, applies the inverse transformation and reconstructs the original scale. |
**kwargs | Keyword arguments | Additional layer keyword arguments. |
A Keras preprocessing layer that outputs normalized inputs, or inverse-transformed inputs when invert=True.
import numpy as np
import tensorflow as tf
layer = tf.keras.layers.Normalization(axis=-1)
layer.adapt(np.array([[1., 10.], [3., 14.], [5., 18.]]))
print(layer(np.array([[3., 14.]], dtype=np.float32)))Creates a feature-wise normalizer, learns its statistics from sample data, and transforms one input row.
Prepare numeric columns before a neural network consumes them.
Reuse fixed training statistics when serving or exporting a model.
Undo a previously applied standardization step.
The layer standardizes inputs by subtracting the stored mean and dividing by the square root of the stored variance. It can use statistics supplied in the constructor or statistics learned with adapt().
Follow-up: How would you restore standardized values? Set invert=True so the layer applies the inverse transformation using its stored statistics.
axis determines which dimensions receive separate mean and variance values. The default axis=-1 therefore normalizes feature positions independently, while axis=None uses one scalar pair of statistics.
Follow-up: What shape constraint matters for supplied statistics? Their values must broadcast to the shape of the retained axes, or build() raises an error.
adapt() computes the dataset mean and variance and stores them as the layer's weights. It must be completed before fit(), evaluate(), or predict() uses the layer.
Follow-up: What alternative avoids adapt()? Pass compatible mean and variance values during construction.
tf.keras.layers.UnitNormalizationtf.keras.layers.LayerNormalizationtf.keras.layers.BatchNormalization