ROC curve with Matlab using svmtrain
Show older comments
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
More Answers (0)
Categories
Find more on Detection in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!