r - 在装扮的 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
函数应该根据哪个值来确定哪些值集是最好的。
解决方案
推荐阅读
- amazon-s3 - AWS SDK C++:无法运行 S3 示例
- javascript - 仅当另一个 div 有内容时才显示一个 div (React)
- ruby-on-rails - 没有路线匹配 {:action=>"create", :controller=>"reviews", :id=>"2", :user_id=>#
我正在处理 user_profile_reviews 并且卡住了。我现在有 3 个模型,而且我知道,为个人资料制作单独的模型并不是一个好主意,
- bash - Bash 脚本 [macOS Sierra 终端] 为给定的每个子目录创建一个 .dmg
- java - 将字符串分离为数组
- php - WordPress:在用户个人资料页面中保存复选框并在公共页面中检索
- tensorflow - 创建像 relu6 这样的自定义非线性
- angular - 如何将 TradingView 嵌入到 Angular 8 项目中?
- c++ - 转换 std::variant到 std::variant
- delphi - 如何检测动画 GIF?