Home > database >  Does "tf.keras.losses.SparseCategoricalCrossentropy()" work for all classification problem
Does "tf.keras.losses.SparseCategoricalCrossentropy()" work for all classification problem

Time:10-08

For tf.keras.losses.SparseCategoricalCrossentropy(), the documentation of TensorFlow says

"Use this crossentropy loss function when there are two or more label classes."

Since it covers two or more labels, including binary classification, then does it mean I can use this loss function for any classification problem? When do I have to use those binary loss such as tf.keras.losses.BinaryCrossentropy and similar ones?

I am using TensorFlow 2.3.1

CodePudding user response:

BinaryCrossentropy ie like a special case of CategoricalCrossetropy with 2 classes, but BinaryCrossentropy is more efficient than CategoricalCrossentropy in calculation. With CategoricalCrossentropy loss you should take the outputs as 2 dimension, while with BinaryCrossentropy 1 dimension is enough. It means you can reduce the weights by a half at the last layer with BinaryCrossentropy loss.

  • Related