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

6 Ansichten (letzte 30 Tage)
  2 Kommentare
madhan ravi
madhan ravi am 28 Sep. 2018
upload your code , it's hard to debug screenshots
Win Sheng Liew
Win Sheng Liew am 28 Sep. 2018
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))

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by