Skip to content

Commit 2fead9d

Browse files
authored
Update eSHAP_plot.R
fixed feature ordering on the plot
1 parent 9d0aaef commit 2fead9d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

R/eSHAP_plot.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,13 @@ eSHAP_plot <- function(task,
211211
filter(!is.na(f_val), is.finite(f_val)) %>%
212212
mutate(
213213
feature = as.character(feature),
214-
feature = factor(feature),
215214
Phi = as.numeric(Phi),
216215
f_val = as.numeric(f_val),
217216
mean_phi = as.numeric(mean_phi),
218217
sample_num = as.integer(sample_num)
219-
)
218+
) %>%
219+
# Order features by absolute mean SHAP importance, most important at top
220+
mutate(feature = forcats::fct_reorder(feature, mean_phi, .fun = function(x) mean(abs(x), na.rm = TRUE), .desc = TRUE))
220221

221222
# Check if we have data to plot
222223
if (nrow(plot_data) == 0) {

0 commit comments

Comments
 (0)