How to plot ROC curve for SVM classifier results?

74 views (last 30 days)
Hello experts,
I need urgent help please. I have training data en test data for my retinal images. I have my SVM implemented. But when I want to obtain a ROC curve for 10-fold cross validation or make a 80% train and 20% train experiment I can't find the answer to have multiple points to plot. I understand that sensitivity vs 1-specificity is plotted, but after svm obtain predicted values, you have only one sensitivity and one specificity. So I tried rocplot and the perfcurve, but I haven't got the ROC curve as would expected. It is frustrating because, if I give perfcurve the inputs like this X,Y,T,AUC]=perfcurve(testLabel,pred ,1); the testlabel is for one dataset, this only plot one (sensitivity versus 1-specificity) point, where is the round or stair roc curve values generated from. I just want a valid ROC curve code that works??
Here is my work, where I tried 10-fold cross validation:
labels=[1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;... 1;1;1;1;1;0;0;0;1;0;1;0;0;1;0;... 0;0;0;1;0;0;0;0;0;0;1;0;0;... 0;0;0;1;1;1;1;0;0;1;1;0;0;0;0;0;0;... 0;0;0;1;1;0];
My two features I use:
TrainVec=[amountExudates ,GS];
k=10;
cvFolds = crossvalind('Kfold',labels, k);
cp = classperf(labels);
for i = 1:10
testIdx = (cvFolds == i);
trainIdx = ~testIdx;
svm = svmtrain(TrainVec(trainIdx,:),labels(trainIdx),...
'Autoscale',true, 'Showplot',true, 'Method','QP',...
lot',false, 'Method','QP', ...
'BoxConstraint',2e-1, 'kernel_function','rbf','rbf_sigma',0.1);
pred = svmclassify(svm, TrainVec(testIdx,:),'Showplot',true);
cp2 = classperf(cp, pred, testIdx);
testLabel=labels(testIdx);
Then I tried
[tpr,fpr,thresholds] = roc(testLabel,pred);
plotroc(testLabel,pred);
and I tried
% Xnew=TrainVec(trainIdx);
% shift = svm.ScaleData.shift;
% scale = svm.ScaleData.scaleFactor;
% Xnew = bsxfun(@plus,Xnew,shift);
% Xnew = bsxfun(@times,Xnew,scale);
% sv = svm.SupportVectors;
% alphaHat = svm.Alpha;
% bias = svm.Bias;
% kfun = svm.KernelFunction;
% kfunargs = svm.KernelFunctionArgs;
% f = kfun(sv,Xnew,kfunargs{:})'*alphaHat(:) + bias;
% f = -f;
[X,Y,T,AUC]=perfcurve(testLabel,pred ,1);
figure;plot(X,Y)

Answers (1)

Ilya
Ilya on 16 Oct 2013

Community Treasure Hunt

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

Start Hunting!