How to get Precision, Recall,ROC,F_Mesure?

조회 수: 3 (최근 30일)
Arya Faturrahman
Arya Faturrahman 2022년 10월 12일
답변: Deep 2024년 12월 27일
Hello anyone I want to get Precision, Recall, Sensitivity,Sprecificity,ROC. But I don't know how to implements code. i get Error at perfCurve and i don't know to fix it.
This my Train Code
imds = imageDatastore('Dataset', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
tbl = countEachLabel(imds);
minSetCount = min(tbl{:,2});
imds = splitEachLabel(imds, minSetCount, 'randomize');
countEachLabel(imds);
net = resnet50();
lgraph = layerGraph(net);
clear net;
numClasses = 2;
%numel(lgraph.Layers(end).ClassNames);
[trainingSet, testSet] = splitEachLabel(imds, 0.7, 'randomize');
imageSize = [224 224 3];
augmentedTrainingSet = augmentedImageDatastore(imageSize,...
trainingSet, 'ColorPreprocessing', 'gray2rgb');
augmentedTestSet = augmentedImageDatastore(imageSize,...
testSet, 'ColorPreprocessing', 'gray2rgb');
% New Learnable Layer
newLearnableLayer = fullyConnectedLayer(numClasses, ...
'Name','new_fc', ...
'WeightLearnRateFactor',10,...
'BiasLearnRateFactor',10);
% Replacing the last layers with new layers
lgraph = replaceLayer(lgraph,'fc1000',newLearnableLayer);
newsoftmaxLayer = softmaxLayer('Name','new_softmax');
lgraph = replaceLayer(lgraph,'fc1000_softmax',newsoftmaxLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'ClassificationLayer_fc1000',newClassLayer);
options = trainingOptions('adam',...
'MaxEpochs',6,'MiniBatchSize',8,...
'Shuffle','every-epoch', ...
'ValidationData', augmentedTestSet, ...
'ValidationFrequency', 30, ...
'InitialLearnRate',1e-4, ...
'Verbose',false, ...
'Plots','training-progress');
netTransfer = trainNetwork(augmentedTrainingSet,lgraph,options);
And This my Test code for get the precision and any parameters
YPred = predict(netTransfer, augmentedTestSet); %imds_test is the image dastore containing the test images.
[Xpr,Ypr,Tpr,AUCpr] =perfcurve(testSet, newClassLayer, 1, 'xCrit', 'reca', 'yCrit', 'prec');
[c,cm,ind,per] = confusion(targets,outputs); %per represents the Matrix of percentages. Please refer to the doc for more details.
Can you help me to fix and get the data?.

답변 (1개)

Deep
Deep 2024년 12월 27일
The function "perfcurve" accepts 3 arguments: a vector of classifier predictions, given true class labels, and the positive class label. You can read more about its correct usage in detail from the official documentation by using the following command:
doc perfcurve
Additionally, since you are working with a confusion matrix, you might find the following MATLAB Answer by Sam helpful for calculating the desired performance metrics: https://www.mathworks.com/matlabcentral/answers/2053757-how-to-evaluate-the-performance-metrics-accuracy-precision-recall-f1score-on-the-tuned-fis#answer_1365099.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by