Skip to content

Commit eb0644a

Browse files
committed
Fail upfront for explain_forest when local importance is absent and accuracy_decrease / mse_increase is asked for.
1 parent 9d4bb38 commit eb0644a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

R/explain_forest.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ explain_forest <- function(forest, interactions = FALSE, data = NULL, vars = NUL
2525
measures = if(forest$type == "classification")
2626
c("mean_min_depth", "accuracy_decrease", "gini_decrease", "no_of_nodes", "times_a_root") else
2727
c("mean_min_depth", "mse_increase", "node_purity_increase", "no_of_nodes", "times_a_root")){
28+
if(any(c("accuracy_decrease", "mse_increase") %in% measures) & dim(forest$importance)[2] == 1) {
29+
stop(paste("Your forest does not contain information on local importance so",
30+
paste(intersect(c("accuracy_decrease", "mse_increase"), measures), sep=", "),
31+
"measure cannot be extracted.",
32+
"To add it regrow the forest with the option localImp = TRUE and run this function again."))
33+
}
2834
environment <- new.env()
2935
environment$forest <- forest
3036
environment$data <- data

0 commit comments

Comments
 (0)