[R] Avoid modifying importance dt in-place, fix aggregation (#9740)

This commit is contained in:
david-cortes
2023-10-31 22:10:59 +01:00
committed by GitHub
parent bc995a4865
commit d3f0646779
2 changed files with 20 additions and 1 deletions

View File

@@ -87,7 +87,13 @@ xgb.plot.importance <- function(importance_matrix = NULL, top_n = NULL, measure
}
# also aggregate, just in case when the values were not yet summed up by feature
importance_matrix <- importance_matrix[, Importance := sum(get(measure)), by = Feature]
importance_matrix <- importance_matrix[
, lapply(.SD, sum)
, .SDcols = setdiff(names(importance_matrix), "Feature")
, by = Feature
][
, Importance := get(measure)
]
# make sure it's ordered
importance_matrix <- importance_matrix[order(-abs(Importance))]