필터 지우기
필터 지우기

How to find the sensitivity and specificity from the confusion matrix?

조회 수: 1 (최근 30일)
Win Sheng Liew
Win Sheng Liew 2018년 9월 28일
댓글: Win Sheng Liew 2018년 9월 28일
  댓글 수: 2
madhan ravi
madhan ravi 2018년 9월 28일
upload your code , it's hard to debug screenshots
Win Sheng Liew
Win Sheng Liew 2018년 9월 28일
global net imageSize featureLayer classifier
f = waitbar(0,'Please wait...');
rootFolder = fullfile('c:\', 'Users', 'Ws Liew', 'Documents', 'MATLAB', 'Dataset'); categories = {'normal', 'abnormal'}; imds = imageDatastore(fullfile(rootFolder, categories), 'LabelSource','foldernames');
tb1 = countEachLabel(imds)
minSetCount = 0.6;
imds = splitEachLabel(imds, minSetCount, 'randomize');
normal = find(imds.Labels == 'normal', 1); abnormal = find(imds.Labels == 'abnormal', 1);
str = {'Select a CNN Architectures: '}; list = {'GoogLeNet','AlexNet','ResNet','VGG-16','VGG-19'}; [indx,tf] = listdlg('PromptString', str, 'ListSize', [200 130], 'SelectionMode', 'single', 'ListString', list);
waitbar(.25,f,'Loading Pre-trained Network');
if indx == 1 net = googlenet(); featureLayer = 'loss3-classifier';
elseif indx == 2 net = alexnet(); featureLayer = 'fc8';
elseif indx == 3 net = resnet50(); featureLayer = 'fc1000';
elseif indx == 4 net = vgg16(); featureLayer = 'fc8';
else indx == 5 net = vgg19(); featureLayer = 'fc8';
end
net.Layers
net.Layers(1)
net.Layers(end)
numel(net.Layers(end).ClassNames)
waitbar(.4,f,'Training and Testing Image Datasets');
[trainingSet, testSet] = splitEachLabel(imds, 0.3, 'randomize');
imageSize = net.Layers(1).InputSize; augmentedTrainingSet = augmentedImageDatastore(imageSize, trainingSet, 'ColorPreprocessing', 'gray2rgb'); augmentedTestSet = augmentedImageDatastore(imageSize, testSet, 'ColorPreprocessing', 'gray2rgb');
w1 = net.Layers(2).Weights;
w1 = mat2gray(w1); w1 = imresize(w1,5);
trainingFeatures = activations(net, augmentedTrainingSet, featureLayer, 'MiniBatchSize', 32, 'OutputAs', 'columns');
trainingLabels = trainingSet.Labels;
waitbar(.65,f,'SVM Classifier Training');
classifier = fitcecoc(trainingFeatures, trainingLabels, 'Learners', 'Linear', 'Coding', 'onevsall', 'ObservationsIn', 'columns');
testFeatures = activations(net, augmentedTestSet, featureLayer, 'MiniBatchSize', 32, 'OutputAs', 'columns');
predictedLabels = predict(classifier, testFeatures, 'ObservationsIn', 'columns');
testLabels = testSet.Labels;
confMat = confusionmat(testLabels, predictedLabels);
confMat = bsxfun(@rdivide,confMat,sum(confMat,2))

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Classification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by