fix matrix form prediction
This commit is contained in:
parent
b04591cbfc
commit
930497e271
@ -95,6 +95,17 @@ 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)
|
||||||
|
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))
|
predictValues <- rep(0,xgb.numrow(dtrain))
|
||||||
history <- c()
|
history <- c()
|
||||||
for (i in 1:nrounds) {
|
for (i in 1:nrounds) {
|
||||||
@ -106,6 +117,9 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing =
|
|||||||
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)
|
res <- xgb.iter.eval(fd$booster, fd$watchlist, i - 1, feval, prediction)
|
||||||
|
if (mat_pred)
|
||||||
|
predictValues[fd$index,] <- res[[2]]
|
||||||
|
else
|
||||||
predictValues[fd$index] <- res[[2]]
|
predictValues[fd$index] <- res[[2]]
|
||||||
msg[[k]] <- res[[1]] %>% str_split("\t") %>% .[[1]]
|
msg[[k]] <- res[[1]] %>% str_split("\t") %>% .[[1]]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user