ROC curve with Matlab using svmtrain

7 views (last 30 days)
Hello I am working with a data set containing x_values which I have called SVMdata(a matrix of 17*41) and target values which are the labels for the classification of these data('a' for the first group and 'b'for the second group). I would like to obtain the ROC curve for my data. I have used the following code:
x=SVMdata';
group=SVMdataS1;
groups = ismember(group,'a');
% divide the original data to training and test data set
Q = size(x,1);
>> Q1 = floor(Q*0.80);
>> Q2 = Q-Q1;
ind = randperm(Q);
ind1 = ind(1:Q1);
ind2 = ind(Q1+(1:Q2));
>> x1 = x(ind1,:);
>> t1 = groups(ind1,:);
>> x2 = x(ind2,:);
>> t2 = groups(ind2,:);
options=optimset('maxiter',1000);
%train with the training set
>> svm = svmtrain(x1, t1, ...
'Autoscale',true, 'Showplot',false, 'Method', 'QP', ...
'Kernel_Function', 'polynomial', 'polyorder',1,'quadprog_opts',options);
shift = svm.ScaleData.shift;
scale = svm.ScaleData.scaleFactor;
x2 = bsxfun(@plus,x2,shift);
x2 = bsxfun(@times,x2,scale);
sv = svm.SupportVectors;
alphaHat = svm.Alpha;
bias = svm.Bias;
kfun = svm.KernelFunction;
kfunargs = svm.KernelFunctionArgs;
f = kfun(sv,x2,kfunargs{:})'*alphaHat(:) + bias;
f = -f;
[X,Y,T,AUC] = perfcurve(t2,f,1);
When I run this program, I get the following error: Error using perfcurve>membership (line 633) Positive class is not found in the input data.
Error in perfcurve (line 387)
[W,subYnames] = membership(labels(sorted),weights(sorted),...
Your help is greatly appreciated. best

Accepted Answer

Ilya
Ilya on 21 Nov 2014
The error says that 1 is not found in t2. Note that your groups variable is logical, and so are t1 and t2, but 1 is double. Try replacing 1 with true or replacing t2 with double(t2).
  2 Comments
Mohamad
Mohamad on 22 Nov 2014
Dear llya Thank you very much. You have been too helpful. best
Thi Huong Hoa Trinh
Thi Huong Hoa Trinh on 7 May 2020
Thanks so much. You have help me a lot. I also have the same error

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!