2016-11-12 131 views
4

我試圖從300*299培訓矩陣中學習相關的功能,將它作爲我的測試數據並應用sequentialfs。我用下面的代碼:Matlab功能選擇

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

xtrainytrain分別299*299299*1。預測會給我預測的標籤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) 

哪兒我去錯了嗎?

+0

不'xtest'有299列? –

+0

是的。它是一個1 * 299的行向量。 – Apurv

+6

我建議你加一個[mcve],否則我們不能測試它 –

回答

1

您應該在func之前建立分類器,而不是之前。 sequentialfs每次在不同的集合上調用該函數,並且必須專門爲每個集合構建一個分類器,只使用爲該迭代選擇的特徵sequentialfs

我不知道,我設法予以明確,在實踐中,你應該將你的代碼的第一行的func

來源體內:MathWorks