Member-only story
Neural Network Model Balanced Weight For Imbalanced Classification In Keras
Adjusting the balanced weight for the cost function to give more attention to the minority class in a neural network model
When using a neural network model to classify imbalanced data, we can adjust the balanced weight for the cost function to give more attention to the minority class. Python’s Keras library has a built-in option called class_weight
to help us achieve this quickly.
One benefit of using the balanced weight adjustment is that we can use the imbalanced data to build the model directly without oversampling or under-sampling before training the model. To learn about oversampling and under-sampling techniques, please check my previous posts here and here.
In this tutorial, we will go over the following topics:
- Baseline neural network model for imbalanced classification
- Calculate class weight using sklearn
- Apply class weight on a neural network model
- Apply manual class weight on a neural network model
Resources for this post: