2012-02-03 29 views
0

我想實現的特徵選擇sequentialfs。我看到這個帖子:Sequential feature selection Matlab實施Sequentialfs

試圖按照給出實施解決方案的例子。

我TrainVec是尺寸268 x1475的矩陣而TestVec是116x1475和TestLabel是116 X 1和TestLabel是268×1.

我實現的代碼是

f = @(TrainVec,TrainLabel,TestVec,TestLabel) sum(TestLabel ~= predict_label); 
fs = sequentialfs(f,Vec,Label); 

錯誤我得到是:

??? Error using ==> crossval>evalFun at 505 
The function 
'@(TrainVec,TrainLabel,TestVec,TestLabel)sum(TestLabel~=predict_label)' 
generated the following error: 
Matrix dimensions must agree. 

Error in ==> crossval>getFuncVal at 524 
funResult = evalFun(funorStr,arg(:)); 

Error in ==> crossval at 363 
    funResult = getFuncVal(1, nData, cvp, data, funorStr, []); 

Error in ==> sequentialfs>callfun at 495 
    funResult = crossval(fun,x,other_data{:},... 

我檢查了我所有的矩陣,並確保它們是相同的尺寸。不知道什麼是錯的。需要一些指導。 錯誤在357 爆擊(K)= callfun(樂趣,X,other_data,CV,mcreps)==> sequentialfs;

回答

0

我不知道這裏是否predict_label是一個變量或零個輸入參數的函數。我猜如果它是一個變量,它的大小與TestLabel的大小不一樣;如果它是一個函數,它要麼沒有返回與TestLabel相同的大小,要麼它有一些中間計算出錯。

無論哪種方式,您通常會希望被寫

f = @(TrainVec,TrainLabel,TestVec,TestLabel) sum(TestLabel ~= predict_label(TrainVec,TrainLabel,TestVec)); 

其中predict_label現在是一個函數,它在你的TrainVecTrainLabel,建立一個模型,評估其對TestVec,並返回預測的數組標籤尺寸與TestLabel相同。

+0

仍然沒有能夠做到這一點......順便說一句,我使用的模型預測LIBSVM。無論如何影響? – lakesh 2012-02-05 11:17:03

+0

我有雙重檢查。 TestLabel和predict_label具有相同的尺寸...但錯誤仍然存​​在... – lakesh 2012-02-09 18:03:21

+0

我的TrainLabel值是-1和1 ..應該是0還是1?這有什麼不同嗎? – lakesh 2012-02-09 18:48:10