【问题标题】:How to create a confusion matrix using the output of crossval() function in Matlab SVM classifier?如何使用 Matlab SVM 分类器中的 crossval() 函数的输出创建混淆矩阵?
【发布时间】:2016-03-27 13:20:24
【问题描述】:

我必须在 Matlab 中测量 SVM 分类器的性能。必须使用混淆矩阵作为性能度量。但是,在 Matlab 中的示例中,只能计算损失值。我找不到有关如何根据 crossval() 函数的结果创建混淆矩阵的信息。

SVMModel = fitcsvm(X,Y,'Standardize',true,'KernelFunction','RBF',...
    'KernelScale','auto');
CVSVMModel = crossval(SVMModel);
FirstModel = CVSVMModel.Trained{1};

【问题讨论】:

  • 如果没有其他办法,至少可以手动计算矩阵。使用 SVM 分类器对测试数据进行分类。然后,查看哪些测试数据项映射到哪些分类器输出,并与真实类进行比较。
  • 是的,事实上我正在这样做。但是,我正在寻找一种更实用的方法。

标签: matlab svm cross-validation confusion-matrix


【解决方案1】:

执行此操作的示例 Matlab 代码。

% Example 3
% Compute the confusion matrix using stratified 10-fold cross validation:
% https://www.mathworks.com/help/stats/crossval.html

load('fisheriris');
% Class label
y = species;
% Measurments to classify with
X = meas;

% Class order
order = unique(y); % Order of the group labels

cp = cvpartition(y,'k',10); % Stratified cross-validation

f = @(xtr,ytr,xte,yte)confusionmat(yte,classify(xte,xtr,ytr),'order',order);

cfMat = crossval(f,X,y,'partition',cp);

cfMat = reshape(sum(cfMat),3,3)
% cfMat =
%     50     0     0
%      0    48     2
%      0     1    49
% cfMat is the summation of 10 confusion matrices from 10 test sets.`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-05
    • 2018-02-20
    • 2015-05-19
    • 2012-01-20
    • 2021-03-02
    • 2016-05-06
    • 2018-04-27
    • 2021-10-30
    相关资源
    最近更新 更多