How to plot ROC curve for SVM classifier results?

조회 수: 8 (최근 30일)
Valeska Pearson
Valeska Pearson 2013년 10월 15일
답변: Ilya 2013년 10월 16일
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)

답변 (1개)

Ilya
Ilya 2013년 10월 16일

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by