I have tried a number of different things but cannot get rid of this error message. Do not see how my code differs from numerous other scripts.
y_train = train$y
train$y = c()
train= as.matrix(train)
train = xgb.DMatrix(data = train, label = y_train)
MSE = function(yhat,train){
y = getinfo(train, "label")
err = mean((y-yhat)^2)
return(list(metric = "RMSE", value = err))
}
params = list(
eta = 0.1,
max_depth = 3,
tweedie_variance_power = 1.5,
objective = "reg:tweedie",
feval = MSE
)
model = xgb.cv(
data = train,
nfold = 3,
params = params,
nrounds = 2000
)
I get the following error:
Error in as.character(x) :
cannot coerce type 'closure' to vector of type 'character'
I find the traceback a bit odd (see below). I use custom folds and xgb.cv is runnable if I remove the fevl and instead use the built in nloglike eval metric.
> traceback()
7: FUN(X[[i]], ...)
6: lapply(p, function(x) as.character(x)[1])
5: `xgb.parameters<-`(`*tmp*`, value = params)
4: xgb.Booster.handle(params, list(dtrain, dtest))
3: FUN(X[[i]], ...)
2: lapply(seq_along(folds), function(k) {
dtest <- slice(dall, folds[[k]])
dtrain <- slice(dall, unlist(folds[-k]))
handle <- xgb.Booster.handle(params, list(dtrain, dtest))
list(dtrain = dtrain, bst = handle, watchlist = list(train = dtrain,
test = dtest), index = folds[[k]])
})
1: xgb.cv(data = train, folds = folds, params = params, nrounds = 2000)
Any suggestions?