我如何将调优函数用于支持向量回归,而不是分类,因为当我尝试使用"svr“作为函数的第一个参数时,它不起作用,并且我找不到一个用于回归的调优示例。这是我使用e1071包执行的代码:
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平方?
发布于 2019-02-26 23:42:02
在e1071::svm()中,问题类型是从response变量自动推断出来的,但可以使用type参数覆盖。svm的tune()函数及其包装器的行为类似:
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: 28Since R-squared between two vectors is just the square of their Pearson correlation,您可以直接将其计算为
ypred <- predict( tuneSVR2$best.model, mtcars[,c("drat","wt")] )
cor( ypred, mtcars$mpg )^2
# [1] 0.8325807https://stackoverflow.com/questions/54888612
复制相似问题