【发布时间】:2021-10-31 20:47:31
【问题描述】:
在 R 中,我正在尝试打包如下数据框:
library(datasets)
require(e1071)
fit <- function(x,y,method="rpart", control = rpart.control(maxdepth=1,maxsurrogate = 0)){
train(x,y,method,control=control)
}
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
bagged <- bag(x = iris[, names(iris) != "Species"],
y = iris$Species,
B=4,
bagControl = bagControl(
fit = fit,
predict = predict,
aggregate = getmode)
)
我收到错误消息:
Something is wrong; all the Accuracy metric values are missing:
Accuracy Kappa
Min. : NA Min. : NA
1st Qu.: NA 1st Qu.: NA
Median : NA Median : NA
Mean :NaN Mean :NaN
3rd Qu.: NA 3rd Qu.: NA
Max. : NA Max. : NA
NA's :3 NA's :3
Error in fitter(btSamples[[iter]], x = x, y = y, ctrl = bagControl, v = vars, :
task 1 failed - "Stopping"
改用 ldaBag 中的函数,有效
library(datasets)
require(e1071)
bagged <- bag(x = iris[, names(iris) != "Species"],
y = iris$Species,
B=4,
bagControl = bagControl(
fit = ldaBag$fit,
predict = ldaBag$pred,
aggregate = ldaBag$aggregate)
)
那么我的自定义拟合和聚合函数有什么问题?
【问题讨论】:
-
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。
标签: r dataframe classification