Calculate TP,TN,FN,FP F1 score for above code

2 次查看(过去 30 天)
Hello Everyone, the below is code snipped, however my f1 scores exceed 1, please help me
clc;
warning off
imds=imageDatastore('Train',...
'IncludeSubFolders',true,'LabelSource','foldername');
[imdsTrain,imdsValidation]=splitEachLabel(imds,0.8,'randomized');
g=alexnet;
labels='foldername';
layers=g.Layers;
inputSize = g.Layers(1).InputSize;
layers(23)=fullyConnectedLayer(4);
layers(25)=classificationLayer;
layer='fc8';
allImages=imageDatastore('Train','IncludeSubfolders',true, 'LabelSource','foldernames');
I=read(allImages);
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain);
augimdsTest = augmentedImageDatastore(inputSize(1:2),imdsValidation);
opts=trainingOptions('sgdm','InitialLearnRate',0.001,'MaxEpochs',12,'MiniBatchSize',64,'Plots','training-progress','ValidationData',augimdsTest);
myNet1=trainNetwork(allImages,layers,opts);
featuresTrain=activations(g,imdsTrain,layer,'OutputAs','rows');
featuresTest=activations(g,imdsValidation,layer,'OutputAs','rows');
svmtrain=fitcecoc(featuresTrain,imdsTrain.Labels);
YPred=predict(svmtrain,featuresTest);
plotconfusion(imdsValidation.Labels,YPred);
[cm,order] = confusionmat(imdsValidation.Labels,YPred);
YAct=imdsValidation.Labels;
cmt=cm';
diagonal=diag(cmt);
sum_of_rows=sum(cmt,1);
precision=diagonal./sum_of_columns;
overall_precision=mean(precision);
sum_of_columns=sum(cmt,2);
recall=diagonal./sum_of_rows;
overall_recall=mean(recall);
f1_score=2*((overall_precision*overall_recall)/(overall_precision+overall_recall));
save myNet1;

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by