Weighting Classes in a Binary Classification Neural Network
Show older comments
I am building a binary classification neural network. The last 3 layers of my CNN architecture are the following:
fullyConnectedLayer(2, 'Name', 'fc1');
softmaxLayer
classificationLayer
Currently, the classificationLayer uses a crossentropyex loss function, but this loss function weights the binary classes (0, 1) the same. Unfortunately, in my total data is have substantially less information about the 0 class than about the 1 class.
As a result, I want to weight the loss function to penalize misclassifying the 0 class more, with classWeights proportional to 1/(class frequency).
I noted that there is a way to weight classes in the pixelClassificationLayer but not the general classificationLayer, which I would be using as I am working on a classification problem.
How can I add class weights to my loss function for training?
3 Comments
Samreen Aziz
on 23 Mar 2019
Hi Arjun,
Did you end up ever figuring this out?
Facing a similar problem.
Regards,
Samreen
Arjun Desai
on 24 Mar 2019
Eugene Alexander
on 28 May 2019
Please take a look at Define Custom Weighted Classification Layer and the example on Speech Command Recognition using Deep Learning. I am trying it right now on a binary classification problem.
Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!