# imbalanced dataset - class weight vs weighted loss function

I'm working on a classification problem with a very imbalanced dataset. Many papers mention a "weighted cross-entropy loss function" or "focal loss with balancing weights". I can't find any of those in tensorflow (tf.keras to be precise) but there is a class_weight parameter in model.fit(). Is there a difference between those two things or is this just the way tensorflow implements weighted loss functions?

The weighted cross-entropy and focal loss are not the same. By setting the class_weight parameter, misclassification errors w.r.t. the less frequent classes can be up-weighted in the cross-entropy loss. The focal loss is a different loss function, its implementation is available in tensorflow-addons.
• Yes that's correct, in Keras you use the class_weight parameter, which under the hood gets converted to per-sample weights, depending on class_weight, which are used to compute a weighted loss across all samples.