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;
댓글 수: 1
Victor Silva
2023년 1월 4일
sum_of_rows=sum(cmt,1);
precision=diagonal./sum_of_columns; is this code ok?
답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!