E.g. for use with loss_categorical_crossentropy().
Arguments
- x
Array-like with class values to be converted into a matrix (integers from 0 to
num_classes - 1). R factors are coerced to integer and offset to be 0-based, i.e.,as.integer(x) - 1L.- num_classes
Total number of classes. If
NULL, this would be inferred asmax(x) + 1. Defaults toNULL.
Examples
a <- to_categorical(c(0, 1, 2, 3), num_classes=4)
print(a)b <- array(c(.9, .04, .03, .03,
.3, .45, .15, .13,
.04, .01, .94, .05,
.12, .21, .5, .17),
dim = c(4, 4))
loss <- op_categorical_crossentropy(a, b)
lossloss <- op_categorical_crossentropy(a, a)
lossSee also
op_one_hot(), which does the same operation asto_categorical(), but operating on tensors.loss_sparse_categorical_crossentropy(), which can accept labels (y_true) as an integer vector, instead of as a dense one-hot matrix.https://keras.io/api/utils/python_utils#tocategorical-function
Other numerical utils: normalize()
Other utils: audio_dataset_from_directory() clear_session() config_disable_interactive_logging() config_disable_traceback_filtering() config_enable_interactive_logging() config_enable_traceback_filtering() config_is_interactive_logging_enabled() config_is_traceback_filtering_enabled() get_file() get_source_inputs() image_array_save() image_dataset_from_directory() image_from_array() image_load() image_smart_resize() image_to_array() layer_feature_space() normalize() pad_sequences() set_random_seed() split_dataset() text_dataset_from_directory() timeseries_dataset_from_array() zip_lists()