【发布时间】:2015-12-28 01:21:54
【问题描述】:
我正在使用 stats 包中包含的 Matlab 2012 svm。我有一个二进制分类问题,我训练一组向量并测试另一组向量,如下 matlab 代码所示:
%set the maximum number of iterations
optSVM = statset('MaxIter', 1000000);
%train the classifier with a set of feature vectors
SVMtrainModel = svmtrain(training_vectors_matrix(:,2:end), training_vectors_matrix(:,1), 'kernel_function' , 'linear', 'options', optSVM, 'tolkkt', 0.01);
%read the test vectors
TestV = csvread(test_file);
%Test the feature vectors in the built classifier
TestAttribBin = svmclassify(SVMtrainModel, TestV(:,2:end))
这是一个非常简单的代码,可以正常运行。训练运行正常,但是当我测试时发生以下错误:
Subscript indices must either be real positive integers or logicals.
Error in svmclassify (line 140)
outclass= glevels(outclass(~unClassified),:);
那么,我的特征向量有什么问题吗?如果我在不同的特征向量(训练和测试向量)中运行相同的代码,代码运行正常。我已经检查了特征向量并且没有 NaN。这个问题应该是什么原因造成的?
【问题讨论】:
-
看来问题一定出在您的数据上,因为您说使用不同的数据代码可以工作。如果没有看到您的数据样本,很难回答这个问题。但是,想到的一种可能性是训练数据中的标签可能不是整数值?你检查过吗?也许值得将你的训练标签的 class() 与那些不起作用的进行比较?