Filter löschen
Filter löschen

sir, following is the error in my code while calculating ROC curve

5 Ansichten (letzte 30 Tage)
Balaji M. Sontakke
Balaji M. Sontakke am 2 Apr. 2018
Kommentiert: naved alam am 12 Apr. 2023
Error using main_new (line 131)
You must pass scores as a vector of floating-point values.
%%Dorsal hand vein recognition using SVM
clc
clear all;
c=[];
addpath train;
addpath test;
mapping=getmapping(8,'u2'); %LBP
W=[0,0,0,0,0,0,0; ...
0,1,1,1,1,1,0; ...
0,1,2,4,2,1,0; ...
0,1,4,4,4,1,0; ...
0,1,2,4,2,1,0; ...
0,1,1,1,1,1,0; ...
0,0,0,0,0,0,0];
%%Training images
for folder_idx = 1 : 20 % no of classes
for i = 1 : 9 % no of images per class
thisfile = fullfile('train', num2str(folder_idx), [num2str(i) '.bmp ']);
B = imread(thisfile );
X = double(B);
X = imresize(X,[60 60],'bilinear');
H2=DSLBP(X,mapping,W);
Gray=X;
Gray=(Gray-mean(Gray(:)))/std(Gray(:))*20+60;
lpqhist=lpq(Gray,3,1,1,'nh');
% imshow(lpqhist);
a=[H2,lpqhist];
c=[c;a];
disp(sprintf('Done',i));
end
end
%%Testing images
d=[];
for folder_idx = 1 : 20 %no of classes
for i = 1 : 3 % no of images per class
thisfile = fullfile('test', num2str(folder_idx), [num2str(i) '.bmp ']);
B = imread(thisfile );
X = double(B);
X = imresize(X,[60 60],'bilinear');
H2=DSLBP(X,mapping,W);
Gray=X;
Gray=(Gray-mean(Gray(:)))/std(Gray(:))*20+60;
lpqhist=lpq(Gray,3,1,1,'nh');
a=[H2,lpqhist];
d=[d;a];
disp(sprintf('Done',i));
end
end
P_train=c;
P_test=d;
% %%PCA low dimension reduction
%
P_train = P_train';
% if classes are 20 then eiganvectors not exceed then 179
model = perform_pca(P_train,179); %rank(P_train)-1
test_features= linear_subspace_projection(P_test, model, 1);
P_train=model.train';
P_test=test_features';
%%Normalisation
P_train=P_train/256;
P_test=P_test/256;
% %%%%%%%%load label %%%%%%%%%%%%
train_label=load('train_label.txt');
test_label=load('test_label.txt');
% P_train = P_train';
% P_test = P_test';
%%classification K Nearest Neighour
% fit a kNN classification model
mdl = fitcknn(P_train,train_label,'Distance','euclidean','NumNeighbors',1); %euclidean
% model=svmtrain(train_label,P_train);
% [predicted_label, accuracy, decision_values]=predict(test_label,P_test,model);
% apply the model to test data and compute test error
[predictlabel,score,cost] = predict(mdl,P_test);
%[predictlabel, score] = resubPredict(mdl,P_test);
% testError1 = sum(test_label ~= predict_label)/numel(test_label);
% Fit probabilities for scores
%groundTruthNumericalLable = [ones(20,1); zeros(20,1); -1.*ones(20,1)];
%[FPR, TPR, Thr, AUC, OPTROCPT] = perfcurve(predictlabel(:,1), score(:,1),'Good');
% [~, Accuracy, Thr] = perfcurve(predictlabel(:,1), score(:,1), 1,'yCrit','accu');
% figure,
% plot(Thr,Accuracy,'r-');
% hold on;
% plot(Thr,Accuracy,'bo');
% xlabel('Threshold for ''good'' Returns');
% ylabel('Classification Accuracy');
% grid on;
%
% disp('Recognition rate');
% [maxInd] = max(Accuracy) %display max index
% disp('threshold value');
% Thr(maxInd) %displays threshold value
score = double(score);
[tpr, fpr, thresh] = roc(predictlabel,score); % The ROC function
[fpr2, tpr2] = perfcurve(predictlabel,score,1); % The perfcurve funtion
plotroc(predictlabel,score); % calculating and plotting altogether
figure(); plot(fpr, tpr); title('ROC'); xlabel('False Positive Rate'); ylabel('True Positive Rate'); % Plotting the ROC results
figure(); plot(fpr2, tpr2); title('perfcurve'); xlabel('False Positive Rate'); ylabel('True Positive Rate'); % Plotting the perfcurve results

Antworten (1)

Walter Roberson
Walter Roberson am 2 Apr. 2018
score returned by predict is an samples x classes array giving probabilities for each class. https://www.mathworks.com/help/stats/classificationknn.predict.html
perfcurve requires a vector of values for the scores https://www.mathworks.com/help/stats/perfcurve.html#bunsogv-scores .
  6 Kommentare
Walter Roberson
Walter Roberson am 12 Apr. 2019
Unfortunately, Balaji's code is poorly formated in a way that makes it ambiguous about whether some parts of it are commented out or not.
naved alam
naved alam am 12 Apr. 2023
[predictlabel,score,cost] = predict(mdl,P_test);

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by