1

For example, is there a way to count the number of support vectors in this classification model?

library(LiblineaR)
data(iris)
attach(iris)

x <- iris[,1:4]
y <- factor(iris[, 5])
set.seed(1)
train <- sample(1:dim(iris)[1],100)
detach(iris)

xTrain <- x[train,]
xTest <- x[-train,]
yTrain <- y[train]
yTest <- y[-train]

s <- scale(xTrain, center=T, scale=T)

m <- LiblineaR(data=s, target=yTrain, type=5, cost=0.1)
m

Output

$TypeDetail
[1] "L1-regularized L2-loss support vector classification (L1R_L2LOSS_SVC)"

$Type
[1] 5

$W
           Sepal.Length Sepal.Width Petal.Length Petal.Width       Bias
setosa                0   0.2075367   -0.9154018    0.000000 -0.4105989
versicolor            0  -0.4238142    0.0303085    0.000000 -0.2447197
virginica             0   0.0000000    0.0000000    1.183732 -0.6795709

$Bias
[1] 1

$ClassNames
[1] setosa     versicolor virginica 
Levels: setosa versicolor virginica

$NbClass
[1] 3

attr(,"class")
[1] "LiblineaR"
Whitebeard
  • 5,945
  • 5
  • 24
  • 31

1 Answers1

1

The liblineaR package does not store support vectors in the model output but packages like kernlab do:

> library kernlab
> your.svm <- ksvm(s,yTrain,type="C-svc",kernel="polydot", 
      prob.model=TRUE,kpar=list(degree=1, scale=1, offset=0))

You can access the number of support vectors like this:

> your.svm@nSV
[1] 23

Or change the parameters to run a different type of SVM:

> your.svm <- ksvm(s,yTrain,type="one-svc", 
     kernel="splinedot",prob.model=TRUE)
 Setting default kernel parameters  
> your.svm@nSV
[1] 22

There are lots of different values stored in the your.svm object - type str(your.svm) to see them. Additionally, here are all the type you can use:

C-svc - C classification
nu-svc - nu classification
C-bsvc - bound-constraint svm classification
spoc-svc - Crammer, Singer native multi-class
kbb-svc - Weston, Watkins native multi-class
one-svc - novelty detection
eps-svr - epsilon regression
nu-svr - nu regression
eps-bsvr - bound-constraint svm regression
mysteRious
  • 4,102
  • 2
  • 16
  • 36