tf.keras.utils.to_categorical

View source on GitHub

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

tf.keras.utils.to_categorical(
    y, num_classes=None, dtype='float32'
)

E.g. for use with categorical_crossentropy.

Arguments:

Returns:

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