[R-package] use as.factor() instead of factor() in lgb.cv()

This commit is contained in:
James Lamb 2020-11-12 19:33:39 -06:00
Родитель 1bc27939a4
Коммит e397ca3f24
1 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -445,7 +445,7 @@ generate.cv.folds <- function(nfold, nrows, stratified, label, group, params) {
if (isTRUE(stratified) && params$objective %in% c("binary", "multiclass") && length(label) == length(rnd_idx)) {
y <- label[rnd_idx]
y <- factor(y)
y <- as.factor(y)
folds <- lgb.stratified.folds(y, nfold)
} else {
@ -495,7 +495,7 @@ generate.cv.folds <- function(nfold, nrows, stratified, label, group, params) {
}
# Creates CV folds stratified by the values of y.
# It was borrowed from caret::lgb.stratified.folds and simplified
# It was borrowed from caret::createFolds and simplified
# by always returning an unnamed list of fold indices.
#' @importFrom stats quantile
lgb.stratified.folds <- function(y, k = 10L) {
@ -529,7 +529,7 @@ lgb.stratified.folds <- function(y, k = 10L) {
## Reset levels so that the possible levels and
## the levels in the vector are the same
y <- factor(as.character(y))
y <- as.factor(as.character(y))
numInClass <- table(y)
foldVector <- vector(mode = "integer", length(y))