Error in matlab code for best c and gamma using svmtrain()

In the following code snippet:
for i=1:numel(C)
cv_acc(i) = svmtrain(labels, data, sprintf('-c %f -g %f -v %d ', 2^C(i), 2^gamma(i), folds));
end
I get the Error: label vector and instance matrix must be double In an assignment A(I) = B, the number of elements in B and I must be the same.
Please advise.

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 1 月 20 日

0 投票

It looks to me that you are using libsvm syntax. However I suspect that you are getting the svmtrain that is part of the Statistics toolbox which uses a different syntax.
Your code assumes that you will get back a single value each time. We cannot tell whether it expecting a numeric value or a structure member or a cell array. Whatever it expected, it is not getting back exactly one of whatever is being returned. That can happen if a routine returns an empty variable rather than a single value.
If you were expecting a single numeric value returned then you are probably not calling the routine correctly.

2 件のコメント

Astha Ameta
Astha Ameta 2017 年 1 月 21 日
The same statement has been used by many programmers through libsvm, so I am unable to understand what is going wrong here.
What should be the correct way to call the routine as I need to return the value of svmtrain in an array variable only so that I can find the maximum of it by comparing.
Walter Roberson
Walter Roberson 2017 年 1 月 21 日
Use
which svmtrain
I suspect you will find you are using svmtrain from the Statistics toolbox

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

タグが未入力です。

質問済み:

2017 年 1 月 20 日

コメント済み:

2017 年 1 月 21 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by