matlab - 如何使用 Matlab SVM 分类器中 crossval() 函数的输出创建混淆矩阵?

标签 matlab svm cross-validation confusion-matrix

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

SVMModel = fitcsvm(X,Y,'Standardize',true,'KernelFunction','RBF',...
    'KernelScale','auto');
CVSVMModel = crossval(SVMModel);
FirstModel = CVSVMModel.Trained{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.`

关于matlab - 如何使用 Matlab SVM 分类器中 crossval() 函数的输出创建混淆矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34396160/

相关文章:

matlab - "shadows it in the MATLAB path"是什么意思?如何在文件中做到这一点?

matlab - Matlab中的"the variable in a parfor cannot be classified."错误

matlab - 如何在 Matlab 中计算线性拟合数据百分比的斜率

image - "Can' t 打开文件"C:"进行读取;您可能没有读取权限。“MATLAB 中的错误

matlab - 如何在神经网络中实现与假阳性与假阴性平衡相关的事实?

用于测试非线性 SVM 的数据集

python - 惩罚一类svm sklearn的错误?

machine-learning - sklearn中的交叉验证+决策树

r - 从 cva.glmnet 对象中提取最佳参数

python - SMOTE 函数在 make_pipeline 中不起作用