【问题标题】:svm accuracy code in matlabmatlab中的svm精度代码
【发布时间】:2014-12-02 07:08:26
【问题描述】:

我正在处理用于用户身份验证的数据集,我想将我的火车数据划分为冒名顶替者和有效用户。它有 31 个功能和 51 个用户。

我有 200 个训练样本和 200 个测试样本。这是我的代码:

ttrain=[train;train2]    
group=[repmat(1,100,1);repmat(2,100,1)]     
model=svmtrain(ttrain,group,'kernel_function','rbf')     
testoutput=svmclassify(model,test,'Showplot','false')  

但是当我想用下面的代码计算准确性时,它会显示错误: "Undefined function 'eq' for input arguments of type 'struct'."

acc = sum(model == testoutput) ./ numel(testoutput)     

我该怎么办?

【问题讨论】:

  • 你能澄清一下吗?上面你说你的火车数据有 31 个特征和 51 个用户。在我看来,您的训练集中有 51 个示例。下面,您声明您的训练数据包含 200 个示例。 “51 个用户”是什么意思?

标签: matlab svm


【解决方案1】:

model 是 SVMStruct,因此无法使用“==”进行比较。您要做的是计算您的 SVM 正确预测的示例数,然后将该数字除以测试的示例总数。

我假设你必须在以下前提条件下做这样的事情:

  • correctLabels 是对您的示例正确的标签 测试 svm:

    acc = sum(correctLabels == testoutput) / numel(correctLabels)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-30
    • 2015-02-12
    • 2019-02-06
    • 2016-07-14
    • 2017-11-22
    • 2017-11-30
    • 1970-01-01
    • 2017-04-21
    相关资源
    最近更新 更多