1

例如,有没有办法统计这个分类模型中支持向量的数量?

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

输出

$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"
4

1 回答 1

1

liblineaR包不在模型输出中存储支持向量,但包如下kernlab

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

您可以像这样访问支持向量的数量:

> your.svm@nSV
[1] 23

或者更改参数以运行不同类型的 SVM:

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

对象中存储了许多不同的值your.svm- 键入str(your.svm)以查看它们。此外,type您可以使用以下所有内容:

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
于 2018-03-29T06:05:47.267 回答