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.
Usage Example:
y = [0, 1, 2, 3]
tf.keras.utils.to_categorical(y, num_classes=4)
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]], dtype=float32)
Arguments |
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' .
|
Returns |
A binary matrix representation of the input. The classes axis is placed
last.
|