Amend xgb.createFolds to handle classes of a single element. (#3630)

* Amend xgb.createFolds to handle classes of a single element.

* Fix variable name
This commit is contained in:
jakehoare 2018-09-13 00:23:05 +10:00 committed by Vadim Khotilovich
parent ad3a0bbab8
commit 7707982a85

View File

@ -275,7 +275,8 @@ xgb.createFolds <- function(y, k = 10)
## add enough random integers to get length(seqVector) == numInClass[i] ## add enough random integers to get length(seqVector) == numInClass[i]
if (numInClass[i] %% k > 0) seqVector <- c(seqVector, sample.int(k, numInClass[i] %% k)) if (numInClass[i] %% k > 0) seqVector <- c(seqVector, sample.int(k, numInClass[i] %% k))
## shuffle the integers for fold assignment and assign to this classes's data ## shuffle the integers for fold assignment and assign to this classes's data
foldVector[y == dimnames(numInClass)$y[i]] <- sample(seqVector) ## seqVector[sample.int(length(seqVector))] is used to handle length(seqVector) == 1
foldVector[y == dimnames(numInClass)$y[i]] <- seqVector[sample.int(length(seqVector))]
} }
} else { } else {
foldVector <- seq(along = y) foldVector <- seq(along = y)