我以前只使用大型矩阵作为sequentialfs
MATLAB 函数中的参数。我有一个新升级的 MATLAB,其中包含Table
数据类型——非常方便。我试图重新编写一个使用表集执行顺序特征选择的脚本,但遇到了麻烦。
normfmat = ngmft(:,4:end-1); % ngmft is previously loaded data table
y = gmft(:,2); % categorical variable with two classes
c = cvpartition(y,'k',10); % first error produced here
fun = @(trainData,trainClass,testData,testClass)...
(sum(~strcmp(testClass,predict(ClassificationKNN.fit(trainData,trainClass,'NumNeighbors',1),testData))));
[fs,history] = sequentialfs(fun,X,y,'cv',c) % second error here
产生的第一个错误是
使用 statslib.internal.grp2idx 时出错(第 44 行) 您不能只使用一个下标为表下标。表下标 > 需要行和变量下标。
grp2idx 错误(第 28 行)[varargout{1:nargout}] = statslib.internal.grp2idx(s);
cvpartition 错误(第 164 行) cv.Group = grp2idx(N);
脚本错误(第 32 行) c = cvpartition(group,'k',10);
如果我将 转换为分类数组,此错误就会消失,但随后会在调用classlab
时产生第二个错误:sequentialfs
使用 sequencefs 时出错(第 345 行)所有输入参数必须是表。
所以我的问题是,本质上,如何在顺序特征选择过程中使用表格?特别是,第一个错误让我感到困惑,因为我给它提供了一个带有指定索引的表。对于第二个错误,cvpartition
返回一个 cvpartition 对象并y
已转换为分类数组。第一个从来不是一张桌子,而在第二个中,由于第一个错误生成,我似乎被锁定了。