# Which loss function to choose for imbalanced datasets?

For imbalanced datasets (either in the context of computer vision or NLP), from what I learned, it is good to use a weighted log loss. However, in competitions, the people who are in top positions are not using weighted loss functions, but treating the classification problem as a regression problem, and using MSE as the loss function. I want to know which one should I use for imbalanced datasets? Or maybe should I combine both?

the weighted loss I am talking is::
neg_weights=[]
pos_weights=[]
for i in tqdm(range(5)):##range(num_classes)
neg_weights.append(np.sum(y_train[:,i],axis=0)/y_train.shape[0])
pos_weights.append(np.sum(1-y_train[:,i],axis=0)/y_train.shape[0])
def customloss(y_true,y_pred):
y_true=tf.cast(y_true,dtype=y_pred.dtype)
loss=0.0
loss_pos=0.0
loss_neg=0.0
for i in range(5):
loss_pos+=-1*(K.mean(pos_weights[i]*y_true[:,i]*K.log(y_pred[:,i]+1e-8)))
loss_neg+=-1*(K.mean(neg_weights[i]*(1-y_true[:,i])*K.log(1-y_pred[:,i]+1e-8)))
loss=loss_pos+loss_neg
return loss


the competition I was talking about is https://www.kaggle.com/c/aptos2019-blindness-detection/discussion/109594

• Does the loss function help you that much to overcome the class imbalance problem or the algorithm? I think you should ask which algorithm to use in imbalance class or which strategy to use to combat class imbalance? – Swakshar Deb Sep 20 '20 at 16:03