首页 > 解决方案 > 在装扮的 SVM 函数上调整参数时出现未使用的参数错误

问题描述

我的目标是调整适用于不同内核函数的函数 SVM 的略微修改版本,但我在此过程中收到错误。

这是拟合模型并计算误差的函数:

train.svm <-function(myKernel, myC){
  time0 <- Sys.time()

  switch(myKernel,
         linear={model <- svm(class ~ ., data = train, type="C-classification", cost=myC, kernel="linear", scale = FALSE)},
         poly.2={model <- svm(class ~ ., data = train, type="C-classification", cost=myC, kernel="polynomial", degree=2, coef0=1, scale = FALSE)},
         poly.3={model <- svm(class ~ ., data = train, type="C-classification", cost=myC, kernel="polynomial", degree=3, coef0=1, scale = FALSE)},
         RBF={model    <- svm(class ~ ., data = train, type="C-classification", cost=myC, kernel="radial", scale = FALSE)},
         stop("Enter one of 'linear', 'poly.2', 'poly.3', 'radial'"))

  pred_train <- predict(model, subset(train, select = -class), decision.values = TRUE)
  pred_test  <- predict(model, subset(test , select = -class), decision.values = TRUE)

  error_train <- sum(pred_train != train$class)/length(train$class)*100
  error_test <- sum(pred_test != test$class)/length(test$class)*100

  c(myC,error_train, error_test, Sys.time() -time0)
}

我尝试使用以下命令对其进行调整:

obj <- tune(train.svm, class ~ ., data = train, 
            ranges = list(myKernel = c("linear", "poly.2", "poly.3", "RBF"),cost = 2^(-4:4)),
            tunecontrol = tune.control(sampling = "fix")
        )

但收到以下错误:

Error in (function (myKernel, myC)  : 
  unused arguments (data = list(c(43, 35, 43, 52, 57, ...

我在这个 SVM 中运行的数据是:

V3   V4   V5   V6  class
43 -146   33 -108   0
35  -63  -89  101   0
43 -149   33  -79   0
52 -122  -22 -113   1
57 -198 -112  -69   1

我也意识到我并没有告诉tune函数应该根据哪个值来确定哪些值集是最好的

标签: rsvm

解决方案


推荐阅读