对于使用SVM进行二进制分类,我有以下代码,以及10个交叉验证,
更新:找到了解决方案,请参阅下面的注释
k=10;
cp = classperf(lables);
cvFolds = crossvalind('Kfold', lables, k);
for i = 1:k
testIdx = (cvFolds == i); %# get indices of test instances
trainIdx = ~testIdx; %# get indices training instances
svmModel = fitcsvm(data_features(trainIdx,:), lables(trainIdx),
'Standardize',true,'KernelFunction','RBF','KernelScale','auto');
[label,score] = predict(svmModel, data_features(testIdx,:));
cp = classperf(cp, pred, testIdx);
cumulative_score= [cumulative_score; score];
label1 = [label1; label];
end
acc= cp.CorrectRate;
conf= cp.CountingMatrix;
我想在Matlab中使用perfcurve
函数绘制ROC曲线,但是,输入的“得分”会改变每一折,因此不能在k折循环之外使用。
[X,Y] = perfcurve(labels,scores,posclass)
在这种情况下如何绘制ROC的任何建议?
注意:通过在循环内添加cumulative_score= [cumulative_score; score];
来解决上述问题,并将其用作perfcurve
答案 0 :(得分:0)
通过在循环内添加cumulative_score= [cumulative_score; score];
,并将其用作perfcurve
的输入