首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“svr”的参数调整

“svr”的参数调整
EN

Stack Overflow用户
提问于 2019-02-26 23:12:36
回答 1查看 1K关注 0票数 0

我如何将调优函数用于支持向量回归,而不是分类,因为当我尝试使用"svr“作为函数的第一个参数时,它不起作用,并且我找不到一个用于回归的调优示例。这是我使用e1071包执行的代码:

代码语言:javascript
复制
tuneSVR <- tune(svm, 
                train.x = train_[, -which(names(train) %in% c("Identifier", "Sales"))],
                train.y = train$Sales,
                data = train,
                ranges = list(epsilon = seq(0,1,0.1), cost = 2^(seq(0.5,8,.5))))

是不是因为我的问题是回归问题就错了?这些代码行需要很长时间才能执行,这正常吗?如何计算svr的R平方?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-26 23:42:02

e1071::svm()中,问题类型是从response变量自动推断出来的,但可以使用type参数覆盖。svm的tune()函数及其包装器的行为类似:

代码语言:javascript
复制
library( e1071 )

# Option 1: using the wrapper
tuneSVR1 <- tune.svm( mtcars[,c("drat","wt")], mtcars$mpg )

# Option 2: using the base function
tuneSVR2 <- tune( svm, mpg~drat+wt, data=mtcars )

# In both cases, the methods correctly infer that the task is regression
tuneSVR2$best.model

# Call:
# best.tune(method = svm, train.x = mpg ~ drat + wt, data = mtcars)
# 
# Parameters:
#    SVM-Type:  eps-regression 
#  SVM-Kernel:  radial 
#        cost:  1 
#       gamma:  0.5 
#     epsilon:  0.1 
# 
# Number of Support Vectors:  28

Since R-squared between two vectors is just the square of their Pearson correlation,您可以直接将其计算为

代码语言:javascript
复制
ypred <- predict( tuneSVR2$best.model, mtcars[,c("drat","wt")] )
cor( ypred, mtcars$mpg )^2
# [1] 0.8325807
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54888612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档