【问题标题】:How to get the error vs. epochs (iterations) plot in matlab when using svm classification?使用 svm 分类时,如何在 matlab 中获取误差与历元(迭代)图?
【发布时间】:2014-11-13 13:42:06
【问题描述】:

我使用svmtrain 训练我的数据集并使用svmclassify 预测测试集。我想看看优化过程,误差与时期(迭代)图。我查看了用法和代码,发现没有关于此类问题的信息。我唯一能得到的就是控制最大迭代。

使用 SVM 分类时如何在 matlab 中获取误差与历元(迭代)图?

这是我修改的代码。但不是我想要的,我想要每个时代的错误。以前有人做过这样的分析吗?谢谢你。 最好的问候!

%# load dataset
load fisheriris                                %# load iris dataset
Groups = ismember(species,'setosa');           %# create a two-class problem

MaxIterValue = 210;                            %# maximum iterations
ErrVsIter = zeros(MaxIterValue, 2);            %# store error data

%# Control maximum iterations
for N = 200: MaxIterValue
%   options.MaxIter = N;
    option = statset('MaxIter', N);
    %# 5-fold Cross-validation
    k = 5;
    cvFolds = crossvalind('Kfold', Groups, k);      %# get indices of 5-fold CV
    cp = classperf(Groups);                         %# init performance tracker

    for i = 1:k                                     %# for each fold
      testIdx = (cvFolds == i);                     %# get indices of test instances
      trainIdx = ~testIdx;                          %# get indices training instances

      %# train an SVM model over training instances
      svmModel = svmtrain(meas(trainIdx,:), Groups(trainIdx), ...
                 'options',option, 'Autoscale',true, 'Showplot',false, 'Method','QP', ...
                   'BoxConstraint',2e-1, 'kernel_function','linear');

      %#plotperform(svmModel);

      %# test using test instances
      pred = svmclassify(svmModel, meas(testIdx,:), 'Showplot',false);

      %# evaluate and update performance object
      cp = classperf(cp, pred, testIdx);
      
    end
    %# get error rate
    ErrVsIter(N, 1) = N;
    ErrVsIter(N, 2) = cp.ErrorRate;

end

plot(ErrVsIter(1:MaxIterValue,1),ErrVsIter(1:MaxIterValue,2));

【问题讨论】:

  • 你能提供一些可运行的例子吗?
  • 嗨,本,我添加了一个示例。感谢您的帮助。

标签: matlab svm


【解决方案1】:

你都做对了,问题是 SVM 每次都在寻找解决方案!所以每个 epoch 都有 CorrectRate=1,试着在你的代码中输入 cp.CorrectRate 来查看它。

问题出在下面一行:

 Groups = ismember(species,'setosa');          

SVM 求解数据非常简单。

并像这样绘制它:

plot(ErrVsIter(200:MaxIterValue,1),ErrVsIter(200:MaxIterValue,2));

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 2013-04-30
    • 2019-01-30
    • 2012-02-08
    • 2013-05-20
    • 2016-03-27
    • 2013-11-17
    • 2015-02-08
    • 2013-06-27
    相关资源
    最近更新 更多