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:
parent
ad3a0bbab8
commit
7707982a85
@ -275,7 +275,8 @@ xgb.createFolds <- function(y, k = 10)
|
||||
## add enough random integers to get length(seqVector) == numInClass[i]
|
||||
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
|
||||
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 {
|
||||
foldVector <- seq(along = y)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user