diff --git a/R-package/R/xgb.importance.R b/R-package/R/xgb.importance.R index 69995d9ef..72e2a0719 100644 --- a/R-package/R/xgb.importance.R +++ b/R-package/R/xgb.importance.R @@ -128,4 +128,4 @@ linearDump <- function(feature_names, text){ # Avoid error messages during CRAN check. # The reason is that these variables are never declared # They are mainly column names inferred by Data.table... -globalVariables(".", "Feature", "Split", "No", "Missing") +globalVariables(c(".", "Feature", "Split", "No", "Missing")) diff --git a/R-package/R/xgb.plot.importance.R b/R-package/R/xgb.plot.importance.R index 627266a7e..b34a16c8b 100644 --- a/R-package/R/xgb.plot.importance.R +++ b/R-package/R/xgb.plot.importance.R @@ -45,6 +45,9 @@ xgb.plot.importance <- function(importance_matrix = NULL, numberOfClusters = c(1 stop("importance_matrix: Should be a data.table.") } + # To avoid issues in clustering when co-occurences are used + importance_matrix <- importance_matrix[, .(Gain = sum(Gain)), by = Feature] + clusters <- suppressWarnings(Ckmeans.1d.dp(importance_matrix[,Gain], numberOfClusters)) importance_matrix[,"Cluster":=clusters$cluster %>% as.character] @@ -56,4 +59,4 @@ xgb.plot.importance <- function(importance_matrix = NULL, numberOfClusters = c(1 # Avoid error messages during CRAN check. # The reason is that these variables are never declared # They are mainly column names inferred by Data.table... -globalVariables(c("Feature","Gain", "Cluster")) \ No newline at end of file +globalVariables(c("Feature", "Gain", "Cluster")) \ No newline at end of file