简体   繁体   English

R中e1071包的svm函数中概率= TRUE的函数

[英]Functionality of probability=TRUE in svm function of e1071 package in R

在R中, e1071包的svm函数中probability=TRUE的功能是什么?

model <- svm (Type ~ ., data, probability=TRUE, cost = 100, gamma = 1)

Setting the probability argument to TRUE for both model fitting and prediction returns, for each prediction, the vector of probabilities of belonging to each class of the response variable. 对于每个预测,将模型拟合和预测返回的probability参数设置为TRUE ,属于响应变量的每个类的概率向量。 These are stored in a matrix, as an attribute of the prediction object. 它们存储在矩阵中,作为预测对象的属性。

For example: 例如:

library(e1071)

model <- svm(Species ~ ., data = iris, probability=TRUE)
# (below I'm just predicting to the training dataset - it could of course just 
# as easily be a separate test dataset)
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

Note, however, that it's important to set probability=TRUE for the call to svm , and not just the call to predict , since the latter alone would produce: 但请注意,为svm调用设置probability=TRUE很重要,而不仅仅是调用predict ,因为后者单独会产生:

#      setosa versicolor virginica
# 1 0.3333333  0.3333333 0.3333333
# 2 0.3333333  0.3333333 0.3333333
# 3 0.3333333  0.3333333 0.3333333
# 4 0.3333333  0.3333333 0.3333333
# 5 0.3333333  0.3333333 0.3333333
# 6 0.3333333  0.3333333 0.3333333

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM