Why the final Validation accuracy appears on the plot different than the accuracy that is calculated by the law of accuracy ?
2 views (last 30 days)
Show older comments
I create and train a simple convolutional neural network for deep learning classification on Matlab, when training finishes, the final validation accuracy that appears on the right side of the plot is different than the accuracy I have gotten from the following law for the validation set
accuracy = sum(predictedLabels == valLabels)/numel(valLabels);
1 Comment
Answers (1)
Manlin Wang
on 21 Apr 2019
I have the same problem. The validation accuracy showed in the training process plot is different from the law of accuracy.The codes are posted as follows:
indices=crossvalind('Kfold',length(XTrain),5);
validate_data_in = (indices == 1);
train = ~validate_data_in;
Xvalidate_data=XTrain(validate_data_in,:);%测试集为20%数据
Yvalidate_label=YTrain(validate_data_in,:);%测试指标
Xtrain_data=XTrain(train,:);
YTrain_label=YTrain(train,:);
indices1=crossvalind('Kfold',length(Xtrain_data),10);
acc=zeros(2,1);
for k=1:2
test = (indices1 == k);
train = ~test;
X_train=Xtrain_data(train,:);
Y_Trainlabel=YTrain_label(train,:);
test_data=Xtrain_data(test,:);
test_target=YTrain_label(test,:);
inputSize = 31;
numHiddenUnits = 120;
numClasses = 2;
layers = [ ...
sequenceInputLayer(inputSize)
bilstmLayer(numHiddenUnits,'OutputMode','sequence')
dropoutLayer(0.2)
bilstmLayer(100,'OutputMode','sequence')
dropoutLayer(0.2)
bilstmLayer(50,'OutputMode','last')
dropoutLayer(0.2)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
%
maxEpochs = 100;
miniBatchSize = 100;
% lgraph = layerGraph(layers);
% lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');
options = trainingOptions('sgdm', ...
'ExecutionEnvironment','cpu', ...
'GradientThreshold',1, ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'InitialLearnRate',1e-3, ...
'SequenceLength','longest', ...
'ValidationData',{test_data,test_target}, ...
'Shuffle','every-epoch', ...
'Verbose',false, ...
'Plots','training-progress');
%train LSTM network
net = trainNetwork(X_train,Y_Trainlabel,layers,options);
%Test LSTM Network
YPred = classify(net,test_data);
acc(k) = sum(YPred == test_target)./numel(test_target)
end
2 Comments
Xinlong Liu
on 30 Jul 2019
Hi Maria,
I have the same problem. I am using MATLAB R2017b. Are there any solutions?
See Also
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!