gpt4 book ai didi

matlab - 如何使用 MATLAB 获取 SVM 中的预测值?

转载 作者:行者123 更新时间:2023-11-30 09:57:37 24 4
gpt4 key购买 nike

我正在尝试在 MATLAB 中获取预测列矩阵,但我不太知道如何对其进行编码。我当前的代码是 -

load DataWorkspace.mat
groups = ismember(Num,'Yes');
k=10;

%# number of cross-validation folds:
%# If you have 50 samples, divide them into 10 groups of 5 samples each,
%# then train with 9 groups (45 samples) and test with 1 group (5 samples).
%# This is repeated ten times, with each group used exactly once as a test set.
%# Finally the 10 results from the folds are averaged to produce a single
%# performance estimation.

cvFolds = crossvalind('Kfold', groups, k);
cp = classperf(groups);
for i = 1:k
testIdx = (cvFolds == i);
trainIdx = ~testIdx;
svmModel = svmtrain(Data(trainIdx,:), groups(trainIdx), ...
'Autoscale',true, 'Showplot',false, 'Method','SMO', ...
'Kernel_Function','rbf');

pred = svmclassify(svmModel, Data(testIdx,:), 'Showplot',false);

%# evaluate and update performance object
cp = classperf(cp, pred, testIdx);
end
cp.CorrectRate
cp.CountingMatrix

问题在于,它实际上总共计算了 11 次准确率 - 每次折叠 10 次,最后一次作为平均值。但是,如果我对每次折叠进行单独预测并为每个循环打印 pred,则可理解的准确性会大大降低。

但是,我需要每行数据的预测值的列矩阵。关于如何修改代码有什么想法吗?

最佳答案

交叉验证的整个想法是对分类器的性能进行无偏估计。

完成后,您通常只需在整个数据上训练模型即可。该模型将用于预测 future 的实例。

所以就这样做:

svmModel = svmtrain(Data, groups, ...);
pred = svmclassify(svmModel, otherData, ...);

关于matlab - 如何使用 MATLAB 获取 SVM 中的预测值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16406444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com