如何在R中使用libSVM(包e1071)获得概率?

时间:2016-08-23 14:56:00

标签: r machine-learning svm libsvm

我试图在libSVM中获取概率输出(R中的packeage e1071),但输出对我的数据集只有TRUE或FALSE。

按照代码:

dadosBrutos<-read.csv("Dataset/circle.data",header = FALSE)


svm.modelo <- svm(V3 ~ ., 
              data=conjuntoTreinamento,
              type='C-classification',
              probability=TRUE)
              #cost=c, 
              #type='C-classification', 
              #kernel='linear',
              #scale=FALSE, 
              #verbose=FALSE 
svm.predict <- predict(svm.modelo,
                       subset(conjuntoTreinamento, 
                       select = -V3),
                       probability=TRUE)

posterior <- as.matrix(svm.predict)

但是,当我使用数据集Iris时,概率输出是%而不是类的名称。

library(e1071)

model <- svm(Species ~ ., data = iris, probability=TRUE)
pred <- predict(model, iris, probability=TRUE)
head(attr(pred, "probabilities"))

#      setosa versicolor   virginica
# 1 0.9803339 0.01129740 0.008368729
# 2 0.9729193 0.01807053 0.009010195
# 3 0.9790435 0.01192820 0.009028276
# 4 0.9750030 0.01531171 0.009685342
# 5 0.9795183 0.01164689 0.008834838
# 6 0.9740730 0.01679643 0.009130620

有人可以帮助我理解这个吗?

1 个答案:

答案 0 :(得分:1)

您必须从属性中提取它:

attr(svm.predict,“概率”)

请参阅: https://stat.ethz.ch/pipermail/r-help/2006-February/088476.html