필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
Balaji M. Sontakke
Balaji M. Sontakke 2018년 4월 2일
댓글: naved alam 2023년 4월 12일
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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 4월 2일
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
Walter Roberson
Walter Roberson 2019년 4월 12일
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 2023년 4월 12일
[predictlabel,score,cost] = predict(mdl,P_test);

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

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by