Dear Conor,
would you mind to explain how it works for a Sequence-to-label classification?
I have imbalanced sequence data (98% is false, 2% is true). As a first step, I have to change weights xx1 and xx2 (do you have a recommendation for this?).
classWeight = [xx1 xx2];
layer = myClassificationLayer(classWeights);
Afterwards I did
numClasses = numel(classWeights);
validInputSize = [vv1 vv2 numClasses];
checkLayer(layer,validInputSize,'ObservationDimension',2);
vv1 refers to the number of classes (=2) and vv2 to the number of observations(of one sequence or ALL observations in the dataset, e.g. vv2 = 10000 observations, each with 30 timesteps).
How do I have to modify forwardLoss and backwardLoss function of class ClassificationLayer?
Thank you so much for your help!
classdef myClassificationLayer < nnet.layer.ClassificationLayer
properties
ClassWeights
end
methods
function layer = myClassificationLayer(classWeights, name)
layer.ClassWeights = classWeights;
if nargin == 2
layer.Name = name;
end
layer.Description = 'Weighted cross entropy';
end
function loss = forwardLoss(layer, Y, T)
N = size(Y,4);
Y = squeeze(Y);
T = squeeze(T);
W = layer.ClassWeights;
loss = -sum(W*(T.*log(Y)))/N;
end
function dLdY = backwardLoss(layer, Y, T)
end
end
end