Commit 54a2356c authored by Laurae's avatar Laurae Committed by Guolin Ke
Browse files

Attempt to fix categorical issue in R package (#228)

* Attempt to fix categorical issue in R package

* Add small fix for categorical IDs

* Add error for unknown numbers/columns
parent 57d55272
...@@ -78,27 +78,17 @@ Dataset <- R6Class( ...@@ -78,27 +78,17 @@ Dataset <- R6Class(
} }
# Get categorical feature index # Get categorical feature index
if (!is.null(private$categorical_feature)) { if (!is.null(private$categorical_feature)) {
fname_dict <- list() if (typeof(private$categorical_feature) == "character") {
if (!is.null(private$colnames)) { cate_indices <- as.list(match(private$categorical_feature, private$colnames) - 1)
fname_dict <- `names<-`( if (length(cate_indices) != length(private$categorical_feature)) {
list((seq_along(private$colnames) - 1)), stop("lgb.self.get.handle: cannot find feature name ", sQuote(private$categorical_feature[!private$categorical_feature %in% private$colnames]))
private$colnames
)
}
cate_indices <- list()
for (key in private$categorical_feature) {
if (is.character(key)) {
idx <- fname_dict[[key]]
if (is.null(idx)) {
stop("lgb.self.get.handle: cannot find feature name ", sQuote(key))
} }
cate_indices <- c(cate_indices, idx)
} else { } else {
# one-based indices to zero-based if (max(private$categorical_feature) > length(private$colnames)) {
idx <- as.integer(key - 1) stop("lgb.self.get.handle: supplied a too large value in categorical_feature")
cate_indices <- c(cate_indices, idx) }
cate_indices <- as.list(private$categorical_feature - 1)
} }
}
private$params$categorical_feature <- cate_indices private$params$categorical_feature <- cate_indices
} }
# Check has header or not # Check has header or not
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment