【问题标题】:ROC curve 3 class classification with MatlabROC曲线3类分类与Matlab
【发布时间】:2021-03-08 18:34:09
【问题描述】:

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

【问题讨论】:

标签: matlab machine-learning plot classification roc


【解决方案1】:

这是一个按照 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

【讨论】:

    猜你喜欢
    • 2014-01-03
    • 2021-07-30
    • 2016-08-06
    • 2018-12-19
    • 2012-09-04
    • 2021-03-03
    • 2017-08-19
    • 2016-08-27
    • 2012-07-10
    相关资源
    最近更新 更多