フィルターのクリア

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

2 ビュー (過去 30 日間)
Akshay Sharma A S
Akshay Sharma A S 2022 年 2 月 24 日
コメント済み: Victor Silva 2023 年 1 月 4 日
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
Victor Silva 2023 年 1 月 4 日
sum_of_rows=sum(cmt,1);
precision=diagonal./sum_of_columns; is this code ok?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics 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