フィルターのクリア

How can I add the C parameter as a single value in fitcsvm?

12 ビュー (過去 30 日間)
Thomas Kirsh
Thomas Kirsh 2020 年 2 月 26 日
編集済み: Thomas Kirsh 2020 年 2 月 27 日
According to the documentation, fitcsvm require the Cost parameter to be a 2x2 matrix (or a structure), specifying the cost for each classification. I've never seen it written this way before, svmtrain and Scikit-learn's SVM classifier have the input be a single value.
For example using the libsvm package, I could enter the parameters as
model = svmtrain(y, X, sprintf('-m 3000 -t 0 -c %f -q', C))
where C = 0.1.
As a result, I'm unsure how to modify my code to work this way.
My thinking right now is if I want to use C = 0.1, I could specify the matrix as [0, C; C 0], such as
model = fitcsvm(y, X, 'KernelFunction', 'linear', 'CacheSize', 3000, 'Cost', [0, C; C, 0])
Would that be the same as adding C=0.1 in svmtrain?

採用された回答

Thomas Kirsh
Thomas Kirsh 2020 年 2 月 27 日
編集済み: Thomas Kirsh 2020 年 2 月 27 日
The 'Cost' parameter in fitcsvm is usually used to add weights to imbalanced classes, not modifying the constraint on the hyperplane, which is what you're doing in svmtrain.
In the fitcsvm function, the constraint on the hyperplane is called the 'BoxConstraint' and can easily be added the same way as
model = fitcsvm(X, y, 'KernelFunction', 'linear', 'CacheSize', 3000, 'BoxConstraint', C)
However, if you're using the libsvm package, you can still use svmtrain and svmpredict in the newer releases of MATLAB by simply re-making the package in MATLAB. Either method works and I ended up doing the latter.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by