ROC 曲线 3 class class Matlab 化

ROC curve 3 class classification with Matlab

我必须使用 Matlab 绘制 ROC,但我的数据集包括 3 类,大多数示例都是针对 2 类 的。如何绘制 3 类 的 ROC(例如 fisher iris 数据集)?

这是一个按照 1-against-others 方法绘制 ROC 的示例:

%% loading data
load fisheriris
X = meas(:, 1:1); % more features -> higher AUC
Y = species;

%% dividing data to test and train sets
r = randperm(150); trn = r(1:100); tst = r(101:150);

%% train classifier
model = fitcdiscr(X(trn, :),Y(trn));

%% predict labels
% score store likelihood of each sample 
% being of each class: nSample by nClass
[Y2, scores] = predict(model, X(tst, :));

%% plot ROCs
hold on
for i=1:length(model.ClassNames)
    [xr, yr, ~, auc] = perfcurve(Y(tst),scores(:, i), model.ClassNames(i));
    plot(xr, yr, 'linewidth', 1)
    legends{i} = sprintf('AUC for %s class: %.3f', model.ClassNames{i}, auc);
end

legend(legends, 'location', 'southeast')
line([0 1], [0 1], 'linestyle', ':', 'color', 'k');
xlabel('FPR'), ylabel('TPR')
title('ROC for Iris Classification (1 vs Others)')
axis square