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

1 vue (au cours des 30 derniers jours)
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);

Réponses (1)

Manlin Wang
Manlin Wang le 21 Avr 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

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by