ROC curve with Matlab using svmtrain

1 回表示 (過去 30 日間)
Mohamad
Mohamad 2014 年 11 月 20 日
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 Center および File ExchangeDetection についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by