Merge branch 'master' of ssh://github.com/dmlc/xgboost

This commit is contained in:
tqchen 2015-03-30 16:06:18 -07:00
commit 8d1f4a40a5
2 changed files with 28 additions and 8 deletions

View File

@ -95,19 +95,39 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing =
} }
folds <- xgb.cv.mknfold(dtrain, nfold, params) folds <- xgb.cv.mknfold(dtrain, nfold, params)
predictValues <- rep(0,xgb.numrow(dtrain)) obj_type = params[['objective']]
mat_pred = FALSE
if (!is.null(obj_type) && obj_type=='multi:softprob')
{
num_class = params[['num_class']]
if (is.null(num_class))
stop('must set num_class to use softmax')
predictValues <- matrix(0,xgb.numrow(dtrain),num_class)
mat_pred = TRUE
}
else
predictValues <- rep(0,xgb.numrow(dtrain))
history <- c() history <- c()
for (i in 1:nrounds) { for (i in 1:nrounds) {
msg <- list() msg <- list()
for (k in 1:nfold) { for (k in 1:nfold) {
fd <- folds[[k]] fd <- folds[[k]]
succ <- xgb.iter.update(fd$booster, fd$dtrain, i - 1, obj) succ <- xgb.iter.update(fd$booster, fd$dtrain, i - 1, obj)
if (!prediction){ if (i<nrounds) {
msg[[k]] <- xgb.iter.eval(fd$booster, fd$watchlist, i - 1, feval) %>% str_split("\t") %>% .[[1]] msg[[k]] <- xgb.iter.eval(fd$booster, fd$watchlist, i - 1, feval) %>% str_split("\t") %>% .[[1]]
} else { } else {
res <- xgb.iter.eval(fd$booster, fd$watchlist, i - 1, feval, prediction) if (!prediction) {
predictValues[fd$index] <- res[[2]] msg[[k]] <- xgb.iter.eval(fd$booster, fd$watchlist, i - 1, feval) %>% str_split("\t") %>% .[[1]]
msg[[k]] <- res[[1]] %>% str_split("\t") %>% .[[1]] } else {
res <- xgb.iter.eval(fd$booster, fd$watchlist, i - 1, feval, prediction)
if (mat_pred) {
pred_mat = matrix(res[[2]],num_class,length(fd$index))
predictValues[fd$index,] <- t(pred_mat)
} else {
predictValues[fd$index] <- res[[2]]
}
msg[[k]] <- res[[1]] %>% str_split("\t") %>% .[[1]]
}
} }
} }
ret <- xgb.cv.aggcv(msg, showsd) ret <- xgb.cv.aggcv(msg, showsd)

View File

@ -7,9 +7,9 @@ Contributors: https://github.com/dmlc/xgboost/graphs/contributors
Turorial and Documentation: https://github.com/dmlc/xgboost/wiki Turorial and Documentation: https://github.com/dmlc/xgboost/wiki
Issues Tracker: [https://github.com/dmlc/xgboost/issues](https://github.com/dmlc/xgboost/issues?q=is%3Aissue+label%3Aquestion) Issues Tracker: [https://github.com/dmlc/xgboost/issues](https://github.com/dmlc/xgboost/issues?q=is%3Aissue+label%3Aquestion) for bugreport and other issues
Please join [XGBoost User Group](https://groups.google.com/forum/#!forum/xgboost-user/) to ask questions and share your experience on xgboost. Please join [XGBoost User Group](https://groups.google.com/forum/#!forum/xgboost-user/) to ask usage questions and share your experience on xgboost.
Examples Code: [Learning to use xgboost by examples](demo) Examples Code: [Learning to use xgboost by examples](demo)