How to manipulate the cost function in SVM in R

svm

#1

Hello,

In case when a slack variable is used to create a soft margin to penalize for errors,a wider margin increases the cost function and hence a narrower margin is better,??
How do i manipulate the cost function in R?


#2

@pagal_guy - The C parameter tells the SVM optimization how much you want to avoid misclassifying each training example. For large values of C, the optimization will choose a smaller-margin hyperplane if that hyperplane does a better job of getting all the training points classified correctly. Conversely, a very small value of C will cause the optimizer to look for a larger-margin separating hyperplane, even if that hyperplane misclassifies more points. For very tiny values of C, you should get misclassified examples, often even if your training data is linearly separable.

To manipulate the cost function value, you can specify the cost value at the training stage.

m <- svm(~., data = X, cost = 0.1) # here the cost value is 0.1

You can use according to the given problem.

Hope this helps!

Regards,
Hinduja