[R] ksvm accessing the slots of S4 object

Nair, Murlidharan T mnair at iusb.edu
Sun Sep 14 17:12:14 CEST 2008

I am using kernlab to build svm models. I am not sure how to access the different slots of the object. For instance if I want to get the nuber of support vectors for each of model I am building and store it in a vector.

>ksvm.model <- ksvm(Class ~ ., data = somedata,kernel = "vanilladot", cross = 10, type ="C-svc")
[1] "param"      "scaling"    "coef"       "alphaindex" "b"
 [6] "obj"        "SVindex"    "nSV"        "prior"      "prob.model"
[11] "alpha"      "type"       "kernelf"    "kpar"       "xmatrix"
[16] "ymatrix"    "fitted"     "lev"        "nclass"     "error"
[21] "cross"      "n.action"   "terms"      "kcall"      "class"

Support Vector Machine object of class "ksvm"

SV type: C-svc  (classification)
 parameter : cost C = 1

Linear (vanilla) kernel function.

Number of Support Vectors : 144

Objective Function Value : -4.3162
Training error : 0
Cross validation error : 0.4

In the above dummy example how do I access the number of support vectors?

I tried the following


Thanks ../Murli

More information about the R-help mailing list