svm                  package:e1071                  R Documentation

_S_u_p_p_o_r_t _V_e_c_t_o_r _M_a_c_h_i_n_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     `svm' is used to train a support vector machine. It can be used to
     carry out general regression and 3 types of classification. At the
     moment, no more than 2 classes can be classified.

_U_s_a_g_e:

     svm(x, y, svm.type=NULL, kernel.type="radial", degree=3, gamma=1/dim(x)[2],
     coef0=0, cost=1, nu=0.5, cachesize=40, tolerance=0.001, epsilon=0.5,
     shrinking=TRUE)
     summary (svm.obj)

_A_r_g_u_m_e_n_t_s:

       x: A data matrix.

       y: A response vector with one label for each row of `x'. Can be
          either a factor or a numeric vector.

svm.type: `svm' can either be used as a classification machine or as a
          regresson machine. Depending of whether `y' is a factor or
          not, the default setting for `svm.type' is `C-classification'
          or `regression', respectively, but may be overwritten by
          setting an explicit value.
          Valid options are:

             *  `C-classification'

             *  `nu-classification'

             *  `one-classification'

             *  `regression'

kernel.type: The kernel used in training and predicting. You might
          consider changing some of the following parameters, depending
          on the kernel type.

          _l_i_n_e_a_r: u'*v

          _p_o_l_y_n_o_m_i_a_l: (gamma*u'*v + coef0)^degree

          _r_a_d_i_a_l _b_a_s_i_s: exp(-gamma*|u-v|^2)

          _s_i_g_m_o_i_d: tanh(gamma*u'*v + coef0)

  degree: parameter needed for kernel of type `polynomial' (default: 3)

   gamma: parameter needed for all kernels except `linear' (default:
          1/(data dimension))

   coef0: parameter needed for kernels of type `polynomial' and
          `sigmoid' (default: 0)

    cost: cost of constraints violation. (default: 1)

      nu: parameter needed for `nu-classification' and
          `one-classification'

cachesize: cache memory in MB. (default 40)

tolerance: tolerance of termination criterion (default: 0.001)

 epsilon: epsilon in the insensitive-loss function (default: 0.5)

shrinking: option whether to use the shrinking-heuristics (default:
          TRUE)

 svm.obj: An object of type `svm' as returned by `svm'

_V_a_l_u_e:

     An object of class `svm' containing the fitted model, especially: 

      sv: the resulting support vectors

   index: the index of the resulting support vectors in the data matrix

   coefs: the corresponding coefficiants

     (Use `summary' and `print' to get some output).

_A_u_t_h_o_r(_s):

     David Meyer (based on C++-code by Chih-Chung Chang and Chih-Jen
     Lin)
     david.meyer@ci.tuwien.ac.at

_R_e_f_e_r_e_n_c_e_s:

        *  Chang, Chih-Chung and Lin, Chih-Jen:
           LIBSVM 2.0: Solving Different Support Vector Formulations.
           <URL:
           http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm2.ps.gz>

        *  Chang, Chih-Chung and Lin, Chih-Jen:
           Libsvm: Introduction and Benchmarks
           <URL: http://www.csie.ntu.edu.tw/~cjlin/papers/q2.ps.gz>

_S_e_e _A_l_s_o:

     `predict.svm'

_E_x_a_m_p_l_e_s:

     data(iris)
     # amputate data to two factors
     iris.sub <- subset(iris, Species != "virginica")

     # get independent vars
     x <- subset (iris.sub, select = -Species)

     # get responses
     y <- iris.sub[,"Species"]

     # coercion needed for correct factor levels
     y <- as.factor(as.character(y))

     # default with factor response: classification mode
     model <- svm (x, y)
     print (model)
     summary (model)

     # test with train data
     pred <- predict (model, x)

     # should be TRUE:
     all.equal (pred, y)

     # try regression mode on two dimensions in linear mode
     model <- svm (x[,"Petal.Length"], x[,"Petal.Width"],
     svm.type="regression", kernel.type="linear")
     print (model)

     pred <- predict (model,x[,"Petal.Length"])

     par (mfcol=c(1,2))
     plot(x[,"Petal.Length"],x[,"Petal.Width"])
     plot(x[,"Petal.Length"],pred)

