Borrar filtros
Borrar filtros

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

12 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Thomas Kirsh
Thomas Kirsh el 27 de Feb. de 2020
Editada: Thomas Kirsh el 27 de Feb. de 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.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by