diff --git a/R-package/R/xgb.importance.R b/R-package/R/xgb.importance.R index d9f70c510..4e22efd19 100644 --- a/R-package/R/xgb.importance.R +++ b/R-package/R/xgb.importance.R @@ -9,6 +9,7 @@ #' @importFrom magrittr %>% #' @importFrom Matrix colSums #' @importFrom Matrix cBind +#' @importFrom Matrix sparseVector #' #' @param feature_names names of each feature as a character vector. Can be extracted from a sparse matrix (see example). If model dump already contains feature names, this argument should be \code{NULL}. #' @@ -82,6 +83,10 @@ xgb.importance <- function(feature_names = NULL, filename_dump = NULL, model = N stop("data/label: Provide the two arguments if you want co-occurence computation or none of them if you are not interested but not one of them only.") } + if(class(label) == "numeric"){ + if(sum(label == 0) / length(label) > 0.5) label <- as(label, "sparseVector") + } + if(is.null(model)){ text <- readLines(filename_dump) } else {