Standardize continuous features
Tabular or numerical model inputs
Keras · Class
Keras Normalization standardizes continuous features using stored mean and variance. Statistics may be supplied directly or learned from data with adapt().
Normalization is a preprocessing layer for continuous features. It stores feature statistics supplied at construction or computed with adapt(), then transforms inputs using the stored mean and variance; with the default axis, each feature position has separate statistics.
keras.layers.Normalization(axis=-1, mean=None, variance=None, invert=False, **kwargs)| Name | Type | Description |
|---|---|---|
axis | Integer, tuple of integers, or None | Axes that receive separate mean and variance values; an integer, tuple of integers, or None. |
mean | Array-like | Mean value or values used for normalization. |
variance | Array-like | Variance value or values used for normalization. |
invert | Boolean | Whether to reverse the normalization transformation. |
**kwargs | Keyword arguments | Additional layer keyword arguments. |
A tensor transformed using the stored mean and variance, or the inverse transformation when invert=True.
import keras
import numpy as np
x = np.array([[1., 10.], [3., 20.], [5., 30.]])
layer = keras.layers.Normalization(axis=-1)
layer.adapt(x)
print(layer(x).numpy())Creates one normalization statistic per feature, learns those statistics from the sample data, and applies the resulting transformation.
Tabular or numerical model inputs
Input pipelines with known dataset statistics
Reconstructing values after normalized processing
It computes normalized values as (input - mean) / sqrt(var). The mean and variance are either passed to the constructor or learned and stored through adapt().
Follow-up: What does adapt() do? It calculates the dataset statistics and saves them as the layer's weights for later calls.
The default axis is -1, so the layer keeps separate statistics for each position along the final dimension. Setting axis to None makes it use one scalar mean and variance across all input elements.
Follow-up: Why might axis=None be useful? It applies global normalization when per-feature statistics are not desired.
The layer does not require adapt() if mean and variance are supplied during construction. Otherwise, adapt() must run before fit(), evaluate(), or predict() so the layer has statistics available.
Follow-up: What validation applies to supplied statistics? Their shapes must broadcast to the kept axes, or building the layer raises an error.
keras.layers.BatchNormalizationkeras.layers.LayerNormalizationkeras.layers.RMSNormalizationkeras.layers.UnitNormalization