I am new to machine learning and SVMs. I have a general question regarding the optimization of parameters in one-class SVM in libsvm in R. I found similar posts but yet not conclusive answer. Can someone tell me, do I need to optimize both c (cost) and nu parameters in one-class SVM?

Actually my preliminary results using e1071 package (libsvm implementation in R) show that predictions (at least in terms of number of positive versus negative classifications) are dependent only from nu and not from c.

  • 1
    $\begingroup$ Please register &/or merge your accounts (you can find information on how to do this in the My Account section of our help center), then you will be able to edit & comment on your own question. $\endgroup$ Feb 15, 2016 at 15:36
  • $\begingroup$ Specifically, please merge your first and second accounts $\endgroup$
    – Glen_b
    Feb 15, 2016 at 16:24

2 Answers 2


The C parameter is used for multiple classification. The nu parameter is used in one-class classification, so as long as you optimize nu you are fine. nu is the upper bound in the fraction of training points. Please check this link

Depending on the kernel function you choose, you will have to optimize gamma too. The hyperplane varies depending on both parameters. If you choose the linear kernel, then there is no need to optimize gamma, as it uses the default value=0 where the gamma value is equal to 1/n (n is the number of features).

To tune your parameters, you can use the tune.svm function:

tuned <- tune.svm(x=yourFeatures, y=yourLabelY, data = yourData, 
              nu =  0.001:0.5,
              gamma = 10^(-2:0), 

Then you can use the best values to design your one-class svm model:

model <-svm(x=yourFeatures, y=yourLabelY,type='one-classification', 
            nu = tuned$best.parameters$nu, 
                    gamma = tuned$best.parameters$gamma

This means your nu value will be the best value between 1% and 50%, meaning you will allow up to 50% of outliers (but you want the best value).

  • $\begingroup$ Hi, thanks for the answer. Just one question:nu = 0.001:0.5,..., This means your nu value will be the best value between 1% and 50% shouldn't this mean a value between 0.1% and 50%, or am I getting something wrong? $\endgroup$
    – mkaran
    Nov 28, 2016 at 10:03
  • $\begingroup$ Hi @mkaran. Sorry for late answer, but you are right. It is from 0.1% to 50%. Regards $\endgroup$
    – Turay Melo
    May 6, 2017 at 15:35

nu and C are alternative constants from alternative formulations of the SVM. You have to choose one or the other. If you are using the svm function of e1071 please check the type parameter in http://www.rdocumentation.org/packages/e1071/functions/svm

type="C-classification" which is the default will use the C-SVM formulation which requires the C parameter, which is called cost in the function

type="nu-classification" uses the nu-SVM formulation which requires setting the nu parameter


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.