tf.keras.utils.to_categorical

Converts a class vector (integers) to binary class matrix.

Compat aliases for migration

See Migration guide for more details.

tf.compat.v1.keras.utils.to_categorical, `tf.compat.v2.keras.utils.to_categorical`

E.g. for use with categorical_crossentropy.

y class vector to be converted into a matrix (integers from 0 to num_classes).
num_classes total number of classes.
dtype The data type expected by the input. Default: 'float32'.

A binary matrix representation of the input. The classes axis is placed last.