如何修复鱼腥交叉分类 [英] How to fix the fisheriris cross classification

查看:109
本文介绍了如何修复鱼腥交叉分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行此在线找到的代码,但是它不起作用.错误是

I tried to run this code found online, but it does not work. The error is

Error using svmclassify (line 53)
The first input should be a `struct` generated by `SVMTRAIN`.

Error in fisheriris_classification (line 27)
pred = svmclassify(svmModel, meas(testIdx,:), 'Showplot',false);

有人可以帮助我解决此问题吗?非常感谢!

Can anyone help me fix this problem? Thank you so much!

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

%# 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.
k=10;

cvFolds = crossvalind('Kfold', groups, k);   %# get indices of 10-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), ...
                 'Autoscale',true, 'Showplot',false, 'Method','QP', ...
                 'BoxConstraint',2e-1, 'Kernel_Function','rbf', 'RBF_Sigma',1);

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

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

%# get accuracy
cp.CorrectRate

%# get confusion matrix
%# columns:actual, rows:predicted, last-row: unclassified instances
cp.CountingMatrix
%with the output:

%ans =
%      0.99333
%ans =
%   100     1
%     0    49
%     0     0

推荐答案

这个问题的原因在我看来似乎是MATLAB在搜索路径中查找函数的方式.我可以肯定地说,它仍在尝试使用LIBSVM函数而不是内置的MATLAB函数.这是有关搜索路径的更多信息:

The reason for the issue seems to me the way MATLAB finds functions on the search path. I am fairly certain that it is still attempting to use the LIBSVM function rather than the built-in MATLAB function. Here is more information about the search path:

http://www. mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html

要验证是否是问题所在,请在命令窗口中尝试以下命令:

To verify whether this is the issue, please try the following command in the command window:

>> which -all svmtrain

您应该发现LIBSVM函数正在掩盖内置函数.您可以使用工具条中的设置路径"工具从MATLAB搜索路径中删除LIBSVM,也可以从不包含LIBSVM文件的其他目录中运行代码.我建议第一个选择.要了解有关内置MATLAB函数的更多信息,请查看以下链接:

You should find that the built-in function is being shadowed by the LIBSVM function. You can either remove LIBSVM from the MATLAB search path using the "Set Path" tool in the Toolstrip, or run your code from a different directory that does not contain the LIBSVM files. I would recommend the first option. To read more about the built-in MATLAB functions, check these links:

http://www.mathworks.com/help/stats/svmtrain.html

http://www.mathworks.com/help/stats/svmclassify.html

如果您想继续使用LIBSVM,建议您访问以下站点.

If you would like to continue use LIBSVM, I would recommend checking the following site out.

https://www.csie.ntu.edu.tw/~ cjlin/index.html 希望这会有所帮助.

https://www.csie.ntu.edu.tw/~cjlin/index.html Hope this helps.

这篇关于如何修复鱼腥交叉分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆