MATLAB Answers

## Why the final Validation accuracy appears on the plot different than the accuracy that is calculated by the law of accuracy ?

Nusaiba Mnayyis

### Nusaiba Mnayyis (view profile)

さんによって質問されました 2018 年 3 月 19 日

### Xinlong Liu (view profile)

さんによって コメントされました 2019 年 7 月 30 日 17:34
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 件のコメント

Maria Duarte Rosa

### Maria Duarte Rosa (view profile)

2019 年 2 月 19 日
Hi Nusaiba,
Which MATLAB version are you using?

サインイン to comment.

## 1 件の回答

### Manlin Wang (view profile)

2019 年 4 月 21 日

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 件のコメント

Maria Duarte Rosa

### Maria Duarte Rosa (view profile)

2019 年 4 月 24 日
Which MATLAB version are you using?
Xinlong Liu

### Xinlong Liu (view profile)

2019 年 7 月 30 日 17:34
Hi Maria,
I have the same problem. I am using MATLAB R2017b. Are there any solutions?

サインイン to comment.

Translated by