Azzera filtri
Azzera filtri

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

12 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Thomas Kirsh
Thomas Kirsh il 27 Feb 2020
Modificato: Thomas Kirsh il 27 Feb 2020
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.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by