improve demo of cv in R
This commit is contained in:
parent
947f0a926d
commit
eb01acfad8
@ -128,7 +128,7 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing =
|
|||||||
for(line in split) dt <- line[2:length(line)] %>% str_extract_all(pattern = "\\d*\\.+\\d*") %>% unlist %>% as.list %>% {vec <- .; rbindlist(list(dt, vec), use.names = F, fill = F)}
|
for(line in split) dt <- line[2:length(line)] %>% str_extract_all(pattern = "\\d*\\.+\\d*") %>% unlist %>% as.list %>% {vec <- .; rbindlist(list(dt, vec), use.names = F, fill = F)}
|
||||||
|
|
||||||
if (prediction) {
|
if (prediction) {
|
||||||
return(list(dt,predictValues))
|
return(list(dt = dt,pred = predictValues))
|
||||||
}
|
}
|
||||||
return(dt)
|
return(dt)
|
||||||
}
|
}
|
||||||
@ -45,3 +45,7 @@ param <- list(max.depth=2,eta=1,silent=1)
|
|||||||
xgb.cv(param, dtrain, nround, nfold = 5,
|
xgb.cv(param, dtrain, nround, nfold = 5,
|
||||||
obj = logregobj, feval=evalerror)
|
obj = logregobj, feval=evalerror)
|
||||||
|
|
||||||
|
# do cross validation with prediction values for each fold
|
||||||
|
res <- xgb.cv(param, dtrain, nround, nfold=5, prediction = TRUE)
|
||||||
|
res$dt
|
||||||
|
length(res$pred)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user