【问题标题】:Attempt to reference field of non-structure array - train svm model尝试引用非结构数组的字段 - 训练 svm 模型
【发布时间】:2013-06-26 13:35:13
【问题描述】:

你好 stackoverflow 世界,

所以我试图通过 svm 训练模型运行一些数据,我遇到了以下错误:

Undefined function or variable 'bestc'.
Error in train_svm_model_sh (line 28)
cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];

我原来的脚本在哪里:

bestcv = 0; 
for log2c = -10:10, 
  for log2g = -10:10, 
    cmd = ['-s 0 -t 0 -v 20 -c', num2str(2^log2c), '-g', num2str(2^log2g) '-q']; 
    cv = svmtrain(labels, data, cmd); 
    if (cv > bestcv),
        bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
        fprintf('%g %g %g (best c = %g, g = %g, rate = %g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
    end
  end
end 
cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];

运行有问题的行是:

cmd = ['-s 0 -t 0 -c', num2str(bestc), '-g', num2str(bestg)];

这是因为我只在 if 循环中定义了变量 bestcbestg 吗?我该如何解决这个问题?

【问题讨论】:

    标签: matlab libsvm undefined-function


    【解决方案1】:

    我猜cv 永远不会大于bestcv。为了帮助调试它,您可以这样做:

    bestc = []; bestg = [];
    

    然后检查他们是否是isempty

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-18
      • 2017-11-29
      • 1970-01-01
      • 2016-05-31
      • 2023-03-14
      • 2016-10-25
      • 2020-12-18
      • 2015-12-24
      相关资源
      最近更新 更多