필터 지우기
필터 지우기

ROC curve with Matlab using svmtrain

조회 수: 4 (최근 30일)
Mohamad
Mohamad 2014년 11월 20일
댓글: Thi Huong Hoa Trinh 2020년 5월 7일
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

채택된 답변

Ilya
Ilya 2014년 11월 21일
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
Mohamad
Mohamad 2014년 11월 22일
Dear llya Thank you very much. You have been too helpful. best
Thi Huong Hoa Trinh
Thi Huong Hoa Trinh 2020년 5월 7일
Thanks so much. You have help me a lot. I also have the same error

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Detection에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by