【问题标题】:Matlab feature selectionMatlab特征选择
【发布时间】:2016-11-16 19:00:27
【问题描述】:

我正在尝试通过从中获取随机行作为我的测试数据并在其上应用 sequentialfs 来学习 300*299 训练矩阵中的相关特征。我使用了以下代码:

>> Md1=fitcdiscr(xtrain,ytrain);
>> func = @(xtrain, ytrain, xtest, ytest) sum(ytest ~= predict(Md1,xtest));
>> learnt = sequentialfs(func,xtrain,ytrain)

xtrainytrain 分别是 299*299299*1。 Predict 会给我xtest 的预测标签(这是来自原始 xtrain 的一些随机行)。

但是,当我运行我的代码时,我收到以下错误:

Error using crossval>evalFun (line 480)
The function '@(xtrain,ytrain,xtest,ytest)sum(ytest~=predict(Md1,xtest))' generated the following error:
X must have 299 columns.

Error in crossval>getFuncVal (line 497)
funResult = evalFun(funorStr,arg(:));

Error in crossval (line 343)
    funResult = getFuncVal(1, nData, cvp, data, funorStr, []);

Error in sequentialfs>callfun (line 485)
    funResult = crossval(fun,x,other_data{:},...

Error in sequentialfs (line 353)
                crit(k) = callfun(fun,x,other_data,cv,mcreps,ParOptions);

Error in new (line 13)
    learnt = sequentialfs(func,xtrain,ytrain)

我哪里做错了?

【问题讨论】:

  • xtest 有 299 列吗?
  • 是的。它是一个 1*299 行向量。
  • 我建议你加一个minimal reproducible example,否则我们无法测试它

标签: matlab machine-learning runtime-error feature-selection


【解决方案1】:

您应该在内部 func 构建您的分类器,而不是之前。 sequentialfs 每次在不同的集合上调用该函数,并且必须专门为每个集合构建分类器,仅使用为该迭代选择的特征 sequentialfs

我不确定我是否清楚,实际上您应该将代码的第一行移到 func 的正文中

来源:MathWorks

【讨论】:

    猜你喜欢
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 2013-04-17
    • 2013-02-21
    • 2017-04-06
    相关资源
    最近更新 更多