Effacer les filtres
Effacer les filtres

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

12 vues (au cours des 30 derniers jours)
Thomas Kirsh
Thomas Kirsh le 26 Fév 2020
Modifié(e) : Thomas Kirsh le 27 Fév 2020
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?

Réponse acceptée

Thomas Kirsh
Thomas Kirsh le 27 Fév 2020
Modifié(e) : Thomas Kirsh le 27 Fév 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.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by