Using class weights, you make the classifier aware of how to treat the various classes in the cost function.
In this process, you give higher weights to certain classes & lower weights to other classes.
from sklearn.utils.class_weight import compute_class_weight
class_weights = compute_class_weight('balanced', np.unique(y), y)
In Keras, class_weight parameter in the fit() is commonly used to adjust such setting.
You can also use the following format,
class_weight = {0: 1.,
1: 50.,
2: 2.}
In the above statement, every one instance of class 1 would be equivalent of 50 instances of class 0 & 25 instances of class 2.
Then pass either the sklearn's class_weights or the dictionary method class weights in the fit() function as a parameter for model training.
Comments