brain tumor code errors

2 ビュー (過去 30 日間)
Faisal Al-Wazir
Faisal Al-Wazir 2023 年 3 月 31 日
回答済み: Joss Knight 2023 年 4 月 4 日
greetings, my doctor gave me this code and made me have two sets of data
1-roi_imdata_n= data for brains without tumors = 1x67
2-roi_imdata_a= data for brains with tumors =1x100
I keep getting errors and I don't know what are the issues
load ('roi_imdata_n');
load ('roi_imdata_a');
%Normal = 67;
%Normal_learn = 47;
%Abnormal = 100;
%Abnormal_learn = 70;
%Nim = 167;
%train = 117;
%test = 50;
imdsTrain = {roi_imdata_n{1,1:Normal_learn},roi_imdata_a{1,1:Abnormal_learn}}';
Ytrain = [zeros(Normal_learn,1);ones(Abnormal_learn,1)];
Ylabels = {};
for i = 1:train
if Ytrain(i,1) == 0;
Ylabels{i,1} = 'false';
else
Ylabels{i,1} = 'true';
end
end
Yclass = categorical(Ylabels);
dTrain = table(imdsTrain,Yclass);
imdsValidation= {roi_imdata_n{1,(Normal_learn+1):Normal},roi_imdata_a{1,(Abnormal_learn+1):Abnormal}}';
Ytest = [zeros(Normal-Normal_learn,1);ones(Abnormal-Abnormal_learn,1)];
Ylabels = {};
for i = 1:test
if Ytest(i,1) == 0;
Ylabels{i,1} = 'false';
else
Ylabels{i,1} = 'true';
end
end
Yclass = categorical(Ylabels);
dTest = table(imdsValidation,Yclass);
layers = [
imageInputLayer([32 32 1])
convolution2dLayer(32,32, 'Padding' , 'same' )
batchNormalizationLayer
reluLayer
maxPooling2dLayer(5, 'Stride' ,2)
convolution2dLayer(32,32, 'Padding' , 'same' )
batchNormalizationLayer
reluLayer
maxPooling2dLayer(5, 'Stride' ,2)
convolution2dLayer(32,32, 'Padding' , 'same' )
batchNormalizationLayer
reluLayer
maxPooling2dLayer(5, 'Stride' ,2)
convolution2dLayer(32,32, 'Padding' , 'same' )
batchNormalizationLayer
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
% Dt = gpuDeviceTable;
% D = gpuDevice(Dt{1,1});
% reset(D);
options = trainingOptions( 'sgdm' , ...
'Momentum', 0.6, ...
'L2Regularization', 0.1, ...
'InitialLearnRate' ,0.01, ...
'GradientThresholdMethod', 'global-l2norm', ...
'MaxEpochs' ,6, ...
'Shuffle' , 'every-epoch' , ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.2, ...
'LearnRateDropPeriod', 5, ...
'ValidationData' , dTest, ...
'ValidationFrequency' , 24, ...
'ExecutionEnvironment','cpu',...
'Verbose',false, ...
'MiniBatchSize', 3, ...
'BatchNormalizationStatistics', 'moving', ...
'OutputNetwork', 'best-validation-loss', ...
'Plots' , 'Training-Progress' );
net = trainNetwork(dTrain,layers,options);
save('cnn_trained.mat','net','dTrain','dTest','Ytrain','Ytest')
% delete(findall(0));
then he gave us a fill called LAST.m
% delete(findall(0));
clear all; close all; clc;
clear memory;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% Loading Database %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load ('roi_imdata_n');
load ('roi_imdata_a');
Normal = 67 ;
Normal_learn = 47 ;
Abnormal = 100;
Abnormal_learn = 70 ;
Nim = 167;
train = 117;
test = 50;
% Defining Normal learn & test images
for i = 1:Nim;
if i <= Normal;
all_images{1,i}=roi_imdata_n{1,i};
else
all_images{1,i} =roi_imdata_a{1,i-(Normal)};
end
end
%Deep Learning directly on roi
dl_classify;
load("cnn_trained.mat")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% Features Extraction %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
all_feat = [];
for i = 1:(Nim)
ai = all_images{1,i}; % Normilaization steps
t = double(reshape((ai),1,numel(ai)));
c=1;
% FO Statistical Features
all_feat(i,c) = mean(t);
c=c+1;
% all_feat(i,2) = std(t);
% all_feat(i,3) = std(t).^2;
all_feat(i,c) = mode(t);
c=c+1;
all_feat(i,c) = median(t);
c=c+1;
all_feat(i,c) = quantile(t,0.1);
c=c+1;
all_feat(i,c) = quantile(t,0.2);
c=c+1;
all_feat(i,c) = quantile(t,0.3);
c=c+1;
all_feat(i,c) = quantile(t,0.4);
c=c+1;
all_feat(i,c) = quantile(t,0.5);
c=c+1;
all_feat(i,c) = quantile(t,0.6);
c=c+1;
all_feat(i,c) = quantile(t,0.7);
c=c+1;
all_feat(i,c) = quantile(t,0.8);
c=c+1;
all_feat(i,c) = quantile(t,0.9);
% HO Features (Hist & GLCM)
% Histogram Feature
hist_levels= 16;
imhist_1= zeros(Nim, hist_levels);
imhist_1 = imhist(ai,hist_levels);
% Normalization
% imhist_1= imhist_1/sum(sum(imhist_1));
%
% % First Order Uniformity
% all_feat(i,[15:30]) = sum((imhist_1).^2);
%
% % First Order Entropy
% all_feat(i,[31:46]) = sum(imhist_1.*log(imhist_1+0.001));
%
% % GLCM Feature
% GLCM_levels= 16;
% GLCM= zeros(Nim, GLCM_levels, GLCM_levels);
% GLCM = graycomatrix(ai,'NumLevels', GLCM_levels, 'GrayLimits', [], 'Offset', [-2 2]);
%
% % Normalization
% GLCM= GLCM/sum(sum(GLCM));
%
% % First Order Uniformity
% all_feat(i,[47:62]) = sum((GLCM).^2);
%
% % First Order Entropy
% all_feat(i,[63:78]) = sum(GLCM.*log(GLCM+0.001));
end
% Init feature vectors
feat_learn = [all_feat(1:Normal_learn,:);all_feat((Normal+1):(Normal+Abnormal_learn),:)];
feat_test = [all_feat((Normal_learn+1):Normal,:);all_feat((Normal+Abnormal_learn+1):(Nim),:)];
learn_class = [zeros(Normal_learn,1);ones(Abnormal_learn,1)];
test_class = [zeros((Normal - Normal_learn),1);ones((Abnormal - Abnormal_learn),1)];
size1= size(feat_learn);
Nfeat= size1(2);
Pval= zeros(Nfeat,1);
for k1=1:Nfeat
[H,P] = ttest2(feat_learn(1:Normal_learn,k1),feat_learn(((Normal_learn+1):end),k1));
Pval(k1)= P;
end
figure(1)
plot(Pval);
textout= sprintf('T-Test: Number of useful features (P-Value < 0.05) = %d out of %d',sum(Pval<0.05), Nfeat);
disp(textout);
[h,w] = size(all_feat);
Hypothesis = zeros(w,1); P_value = zeros(w,1); Selected_Feature_ttest = zeros(w,2);
for i = 1 : w
[Hypothesis(i), P_value(i)] = ttest2(all_feat(1:Normal,i) , all_feat((Normal)+1:h,i));
Selected_Feature_ttest(i,1) = Hypothesis(i);
Selected_Feature_ttest(i,2) = P_value(i);
end
[P_val_sortT_test, IndxTest]= sort(Selected_Feature_ttest(:,2)); % IndxTest: represents the number of accepted features.
a = sum(P_val_sortT_test < 0.05);
IndxTest = sort(IndxTest(1:a,1));
Finalfeatures_ttest = all_feat(:,IndxTest(1:a));
feat_learn = [Finalfeatures_ttest(1:Normal_learn,:);Finalfeatures_ttest((Normal+1):(Normal+Abnormal_learn),:)];
feat_test= [Finalfeatures_ttest((Normal_learn+1):Normal,:);Finalfeatures_ttest((Normal+Abnormal_learn+1):(Nim),:)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% Training Classifiers %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% First Classifier:
svmstruct_1 = fitcsvm(feat_learn,learn_class,'KernelFunction','rbf');
answer1 = predict(svmstruct_1,feat_learn);
[X,Y,T,AUC1] = perfcurve(learn_class,answer1,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by SVM - rbf Kernel - Training Group');
% Confusion matrix for first classifier:
conMat1 = confusionmat(learn_class,answer1)/train;
TP1= conMat1(1,1);
TN1= conMat1(2,2);
FP1= conMat1(1,2);
FN1= conMat1(2,1);
Sens1= TP1/(TP1+FN1);
Spec1= TN1/(TN1+FP1);
PPV1= TP1/(TP1+FP1);
NPV1= TN1/(TN1+FN1);
Acc1= (TP1+TN1)/(TP1+TN1+FP1+FN1);
error1 = sum(learn_class~= answer1)/train;
AUC1;
check1 = Acc1+error1;
% Second Classifier:
svmstruct_2 = fitcsvm(feat_learn,learn_class,'KernelFunction','polynomial');
answer2 = predict(svmstruct_2,feat_learn);
[X,Y,T,AUC2] = perfcurve(learn_class,answer2,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by SVM - polynomial Kernel - Training Group');
% Confusion matrix for second classifier:
conMat2 = confusionmat(learn_class,answer2)/train;
TP2= conMat2(1,1);
TN2= conMat2(2,2);
FP2= conMat2(1,2);
FN2= conMat2(2,1);
Sens2= TP2/(TP2+FN2);
Spec2= TN2/(TN2+FP2);
PPV2= TP2/(TP2+FP2);
NPV2= TN2/(TN2+FN2);
Acc2= (TP2+TN2)/(TP2+TN2+FP2+FN2);
error2 = sum(learn_class~= answer2)/train;
AUC2;
check2 = Acc2+error2;
%Third Classifier Linear SVM
svmstruct_3 = fitcsvm(feat_learn,learn_class,'KernelFunction','linear');
answer3 = predict(svmstruct_3,feat_learn);
[X,Y,T,AUC3] = perfcurve(learn_class,answer3,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by SVM - linear Kernel - Training Group');
% Confusion matrix for fourth classifier:
conMat3 = confusionmat(learn_class,answer3)/train;
TP3= conMat3(1,1);
TN3= conMat3(2,2);
FP3= conMat3(1,2);
FN3= conMat3(2,1);
Sens3= TP3/(TP3+FN3);
Spec3= TN3/(TN3+FP3);
PPV3= TP3/(TP3+FP3);
NPV3= TN3/(TN3+FN3);
Acc3= (TP3+TN3)/(TP3+TN3+FP3+FN3);
error3 = sum(learn_class~= answer3)/train;
AUC3;
check3 = Acc3+error3;
% Fourth Classifier:
%%%%%%%CNN%%%%%%%%%%%%%%%%%%%%%%
YPred_tr = classify(net,dTrain);
YPred_n = [];
for i =1:train
if YPred_tr(i,1) == 'true';
YPred_n(i,1) = 1;
else
YPred_n(i,1) = 0;
end
end
YPred_tr = YPred_n;
[X,Y,T,AUC4] = perfcurve(Ytrain,YPred_tr,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by CNN - Train Group')
% Confusion matrix for trainng CNN classifier:
conMat4 = confusionmat(Ytrain,YPred_tr)/test;
TP4= conMat4(1,1);
TN4= conMat4(2,2);
FP4= conMat4(1,2);
FN4= conMat4(2,1);
Sens4= TP4/(TP4+FN4);
Spec4= TN4/(TN4+FP4);
PPV4= TP4/(TP4+FP4);
NPV4= TN4/(TN4+FN4);
Acc4= (TP4+TN4)/(TP4+TN4+FP4+FN4);
error4= sum(YPred_tr ~= Ytrain)/numel(Ytrain);
AUC4;
check4 = Acc4+error4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fifth Classifier:
knnstruct_1 = fitcknn(feat_learn,learn_class,'NumNeighbors',1);
answer5 = predict(knnstruct_1,feat_learn);
[X,Y,T,AUC5] = perfcurve(learn_class,answer5,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by KNN - 1 - Training Group');
% Confusion matrix for fifth classifier:
conMat5 = confusionmat(learn_class,answer5)/train;
TP5= conMat5(1,1);
TN5= conMat5(2,2);
FP5= conMat5(1,2);
FN5= conMat5(2,1);
Sens5= TP5/(TP5+FN5);
Spec5= TN5/(TN5+FP5);
PPV5= TP5/(TP5+FP5);
NPV5= TN5/(TN5+FN5);
Acc5= (TP5+TN5)/(TP5+TN5+FP5+FN5);
error5 = sum(learn_class~= answer5)/train;
AUC5;
check5 = Acc5+error5;
% Sixth Classifier:
knnstruct_2 = fitcknn(feat_learn,learn_class,'NumNeighbors',2);
answer6 = predict(knnstruct_2,feat_learn);
[X,Y,T,AUC6] = perfcurve(learn_class,answer6,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by KNN - 2 - Training Group');
% Confusion matrix for sixth classifier:
conMat6 = confusionmat(learn_class,answer6)/train;
TP6= conMat6(1,1);
TN6= conMat6(2,2);
FP6= conMat6(1,2);
FN6= conMat6(2,1);
Sens6= TP6/(TP6+FN6);
Spec6= TN6/(TN6+FP6);
PPV6= TP6/(TP6+FP6);
NPV6= TN6/(TN6+FN6);
Acc6= (TP6+TN6)/(TP6+TN6+FP6+FN6);
error6 = sum(learn_class~= answer6)/train;
AUC6;
check6 = Acc6+error6;
% Seventh Classifier:
knnstruct_3 = fitcknn(feat_learn,learn_class,'NumNeighbors',3);
answer7 = predict(knnstruct_3,feat_learn);
[X,Y,T,AUC7] = perfcurve(learn_class,answer7,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by KNN - 3 - Training Group');
% Confusion matrix for seventh classifier:
conMat7 = confusionmat(learn_class,answer7)/train;
TP7= conMat7(1,1);
TN7= conMat7(2,2);
FP7= conMat7(1,2);
FN7= conMat7(2,1);
Sens7= TP7/(TP7+FN7);
Spec7= TN7/(TN7+FP7);
PPV7= TP7/(TP7+FP7);
NPV7= TN7/(TN7+FN7);
Acc7= (TP7+TN7)/(TP7+TN7+FP7+FN7);
error7 = sum(learn_class~= answer7)/train;
AUC7;
check7 = Acc7+error7;
% Eighth Classifier:
knnstruct_4 = fitcknn(feat_learn,learn_class,'NumNeighbors',4);
answer8 = predict(knnstruct_4,feat_learn);
[X,Y,T,AUC8] = perfcurve(learn_class,answer8,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by KNN - 4 - Training Group');
% Confusion matrix for eighth classifier:
conMat8 = confusionmat(learn_class,answer8)/train;
TP8= conMat8(1,1);
TN8= conMat8(2,2);
FP8= conMat8(1,2);
FN8= conMat8(2,1);
Sens8= TP8/(TP8+FN8);
Spec8= TN8/(TN8+FP8);
PPV8= TP8/(TP8+FP8);
NPV8= TN8/(TN8+FN8);
Acc8= (TP8+TN8)/(TP8+TN8+FP8+FN8);
error8 = sum(learn_class~= answer8)/train;
AUC8;
check8 = Acc8+error8;
% Ninth Classifier:
knnstruct_5 = fitcknn(feat_learn,learn_class,'NumNeighbors',5);
answer9 = predict(knnstruct_5,feat_learn);
[X,Y,T,AUC9] = perfcurve(learn_class,answer9,1);
figure, plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC for classification by KNN - 5 - Training Group');
% Confusion matrix for ninth classifier:
conMat9 = confusionmat(learn_class,answer9)/train;
TP9= conMat9(1,1);
TN9= conMat9(2,2);
FP9= conMat9(1,2);
FN9= conMat9(2,1);
Sens9= TP9/(TP9+FN9);
Spec9= TN9/(TN9+FP9);
PPV9= TP9/(TP9+FP9);
NPV9= TN9/(TN9+FN9);
Acc9= (TP9+TN9)/(TP9+TN9+FP9+FN9);
error9 = sum(learn_class~= answer9)/train;
AUC9;
check9 = Acc9+error9;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% Testing Classifiers %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Testing SVM - rbf Classifier:
answer_1 = predict(svmstruct_1,feat_test);
[X,Y,T,AUC_1] = perfcurve(test_class,answer_1,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by SVM - rbf Kernel - Testing Group')
% Confusion matrix for first testing:
conMat_1 = confusionmat(test_class,answer_1)/test;
TP_1= conMat_1(1,1);
TN_1= conMat_1(2,2);
FP_1= conMat_1(1,2);
FN_1= conMat_1(2,1);
Sens_1= TP_1/(TP_1+FN_1);
Spec_1= TN_1/(TN_1+FP_1);
PPV_1= TP_1/(TP_1+FP_1);
NPV_1= TN_1/(TN_1+FN_1);
Acc_1= (TP_1+TN_1)/(TP_1+TN_1+FP_1+FN_1);
error_1 = sum(test_class~= answer_1)/test;
AUC_1;
check_1 = Acc_1+error_1;
% Testing SVM - polynomial Classifier:
answer_2 = predict(svmstruct_2,feat_test);
[X,Y,T,AUC_2] = perfcurve(test_class,answer_2,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by SVM - polynomial Kernel - Testing Group')
% Confusion matrix for second testing:
conMat_2 = confusionmat(test_class,answer_2)/test;
TP_2= conMat_2(1,1);
TN_2= conMat_2(2,2);
FP_2= conMat_2(1,2);
FN_2= conMat_2(2,1);
Sens_2= TP_2/(TP_2+FN_2);
Spec_2= TN_2/(TN_2+FP_2);
PPV_2= TP_2/(TP_2+FP_2);
NPV_2= TN_2/(TN_2+FN_2);
Acc_2= (TP_2+TN_2)/(TP_2+TN_2+FP_2+FN_2);
error_2 = sum(test_class~= answer_2)/test;
AUC_2;
check_2 = Acc_2+error_2;
% Testing SVM - linear Classifier:
answer_3 = predict(svmstruct_3,feat_test);
[X,Y,T,AUC_3] = perfcurve(test_class,answer_3,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by SVM - linear Kernel - Testing Group')
% Confusion matrix for second testing:
conMat_3 = confusionmat(test_class,answer_3)/test;
TP_3= conMat_3(1,1);
TN_3= conMat_3(2,2);
FP_3= conMat_3(1,2);
FN_3= conMat_3(2,1);
Sens_3= TP_3/(TP_3+FN_3);
Spec_3= TN_3/(TN_3+FP_3);
PPV_3= TP_3/(TP_3+FP_3);
NPV_3= TN_3/(TN_3+FN_3);
Acc_3= (TP_3+TN_3)/(TP_3+TN_3+FP_3+FN_3);
error_3 = sum(test_class~= answer_3)/test;
AUC_3;
check_3 = Acc_3+error_3;
%Testing CNN Classifier:
YPred_ts = classify(net,dTest);
YPred_n = [];
for i =1:test
if YPred_ts(i,1) == 'true';
YPred_n(i,1) = 1;
else
YPred_n(i,1) = 0;
end
end
YPred_ts = YPred_n;
[X,Y,T,AUC_4] = perfcurve(Ytest,YPred_ts,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by CNN - Test Group')
% Confusion matrix for testing CNN classifier:
conMat_4 = confusionmat(Ytest,YPred_ts)/test;
TP_4= conMat_4(1,1);
TN_4= conMat_4(2,2);
FP_4= conMat_4(1,2);
FN_4= conMat_4(2,1);
Sens_4= TP_4/(TP_4+FN_4);
Spec_4= TN_4/(TN_4+FP_4);
PPV_4= TP_4/(TP_4+FP_4);
NPV_4= TN_4/(TN_4+FN_4);
Acc_4= (TP_4+TN_4)/(TP_4+TN_4+FP_4+FN_4);
error_4= sum(YPred_ts ~= Ytest)/numel(Ytest);
AUC_4;
check_4 = Acc_4+error_4;
% Testing KNN-1 Classifier:
answer_5 = predict(knnstruct_1,feat_test);
[X,Y,~,AUC_5] = perfcurve(test_class,answer_5,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by KNN - 1 - Test Group')
% Confusion matrix for testing KNN-1 classifier:
conMat_5 = confusionmat(test_class,answer_5)/test;
TP_5= conMat_5(1,1);
TN_5= conMat_5(2,2);
FP_5= conMat_5(1,2);
FN_5= conMat_5(2,1);
Sens_5= TP_5/(TP_5+FN_5);
Spec_5= TN_5/(TN_5+FP_5);
PPV_5= TP_5/(TP_5+FP_5);
NPV_5= TN_5/(TN_5+FN_5);
Acc_5= (TP_5+TN_5)/(TP_5+TN_5+FP_5+FN_5);
error_5 = sum(test_class~= answer_5)/test;
AUC_5;
check_5 = Acc_5+error_5;
% Testing KNN-2 Classifier:
answer_6 = predict(knnstruct_2,feat_test);
[X,Y,T,AUC_6] = perfcurve(test_class,answer_6,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by KNN - 2 - Test Group')
% Confusion matrix for testing KNN-2 classifier:
conMat_6 = confusionmat(test_class,answer_6)/test;
TP_6= conMat_6(1,1);
TN_6= conMat_6(2,2);
FP_6= conMat_6(1,2);
FN_6= conMat_6(2,1);
Sens_6= TP_6/(TP_6+FN_6);
Spec_6= TN_6/(TN_6+FP_6);
PPV_6= TP_6/(TP_6+FP_6);
NPV_6= TN_6/(TN_6+FN_6);
Acc_6= (TP_6+TN_6)/(TP_6+TN_6+FP_6+FN_6);
error_6 = sum(test_class~= answer_6)/test;
AUC_6;
check_6 = Acc_6+error_6;
% Testing the KNN-3 Classifier:
answer_7 = predict(knnstruct_3,feat_test);
[X,Y,T,AUC_7] = perfcurve(test_class,answer_7,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by KNN - 3 - Test Group')
% Confusion matrix for testing KNN-3 classifier:
conMat_7 = confusionmat(test_class,answer_7)/test;
TP_7= conMat_7(1,1);
TN_7= conMat_7(2,2);
FP_7= conMat_7(1,2);
FN_7= conMat_7(2,1);
Sens_7= TP_7/(TP_7+FN_7);
Spec_7= TN_7/(TN_7+FP_7);
PPV_7= TP_7/(TP_7+FP_7);
NPV_7= TN_7/(TN_7+FN_7);
Acc_7= (TP_7+TN_7)/(TP_7+TN_7+FP_7+FN_7);
error_7 = sum(test_class~= answer_7)/test;
AUC_7;
check_7 = Acc_7+error_7;
% Testing the KNN-4 Classifier:
answer_8 = predict(knnstruct_4,feat_test);
[X,Y,T,AUC_8] = perfcurve(test_class,answer_8,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by KNN - 4 - Test Group')
% Confusion matrix for testing KNN-4 classifier:
conMat_8 = confusionmat(test_class,answer_8)/test;
TP_8= conMat_8(1,1);
TN_8= conMat_8(2,2);
FP_8= conMat_8(1,2);
FN_8= conMat_8(2,1);
Sens_8= TP_8/(TP_8+FN_8);
Spec_8= TN_8/(TN_8+FP_8);
PPV_8= TP_8/(TP_8+FP_8);
NPV_8= TN_8/(TN_8+FN_8);
Acc_8= (TP_8+TN_8)/(TP_8+TN_8+FP_8+FN_8);
error_8= sum(test_class~= answer_8)/test;
AUC_8;
check_8 = Acc_8+error_8;
% Testing the KNN-5 Classifier:
answer_9 = predict(knnstruct_5,feat_test);
[X,Y,T,AUC_9] = perfcurve(test_class,answer_9,1);
figure, plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by KNN - 5 - Test Group')
% Confusion matrix for testing KNN-5 classifier:
conMat_9 = confusionmat(test_class,answer_9)/test;
TP_9= conMat_9(1,1);
TN_9= conMat_9(2,2);
FP_9= conMat_9(1,2);
FN_9= conMat_9(2,1);
Sens_9= TP_9/(TP_9+FN_9);
Spec_9= TN_9/(TN_9+FP_9);
PPV_9= TP_9/(TP_9+FP_9);
NPV_9= TN_9/(TN_9+FN_9);
Acc_9= (TP_9+TN_9)/(TP_9+TN_9+FP_9+FN_9);
error_9 = sum(test_class~= answer_9)/test;
AUC_9;
check_9 = Acc_9+error_9;
% Showing all results for all training classifiers
sens = [Sens1, Sens2, Sens3, Sens4, Sens5, Sens6, Sens7, Sens8, Sens9];
spec = [Spec1, Spec2, Spec3, Spec4, Spec5, Spec6, Spec7, Spec8, Spec9];
PPV = [PPV1, PPV2, PPV3, PPV4, PPV5, PPV6, PPV7, PPV8, PPV9];
NPV = [NPV1, NPV2, NPV3, NPV4, NPV5, NPV6, NPV7, NPV8, NPV9];
Acc = [Acc1, Acc2, Acc3, Acc4, Acc5, Acc6, Acc7, Acc8, Acc9];
error = [error1, error2, error3, error4, error5, error6, error7, error8, error9];
AUC = [AUC1, AUC2, AUC3,AUC4, AUC5, AUC6, AUC7, AUC8, AUC9];
% % Showing all results for all testing classifiers
sens_t = [Sens_1, Sens_2, Sens_3, Sens_4, Sens_5, Sens_6, Sens_7, Sens_8, Sens_9];
spec_t = [Spec_1, Spec_2, Spec_3, Spec_4, Spec_5, Spec_6, Spec_7, Spec_8, Spec_9];
PPV_t = [PPV_1, PPV_2, PPV_3, PPV_4, PPV_5, PPV_6, PPV_7, PPV_8, PPV_9];
NPV_t = [NPV_1, NPV_2, NPV_3, NPV_4, NPV_5, NPV_6, NPV_7, NPV_8, NPV_9];
Acc_t = [Acc_1, Acc_2, Acc_3, Acc_4, Acc_5, Acc_6, Acc_7, Acc_8, Acc_9];
error_t = [error_1, error_2 error_3, error_4, error_5, error_6, error_7, error_8, error_9];
AUC_t = [AUC_1, AUC_2 AUC_3, AUC_4, AUC_5, AUC_6, AUC_7, AUC_8, AUC_9];
[sens;spec;PPV;NPV;Acc;error;AUC]
[sens_t;spec_t;PPV_t;NPV_t;Acc_t;error_t;AUC_t]
% close all;

採用された回答

Joss Knight
Joss Knight 2023 年 4 月 4 日
Looks like your version of MATLAB predates the OutputNetwork training option, which was introduced in R2021b.

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by