Skip to content

Conversation

ck37
Copy link

@ck37 ck37 commented Jul 25, 2024

This is a minor fix to allow ranger.unify() to work correctly when probability = TRUE in a ranger::ranger() model, i.e. a probability forest.

This example code will now work correctly:

data = fifa20$data[, 1:8]
data$target_high = as.integer(fifa20$target > median(fifa20$target))
rf_model = ranger::ranger(target_high ~ ., data = data, num.trees = 10L, probability = TRUE)
unified = unify(rf_model, data)
treeshap1 = treeshap(unified, data[1:100, ], verbose = 0)
plot_feature_importance(treeshap1, max_vars = 6)

@mayer79
Copy link
Contributor

mayer79 commented Jul 30, 2024

This fix will work only if the response is 0-1 coded.

library(ranger)

fit <- ranger(Species ~ ., data = iris, probability = TRUE)
colnames(treeInfo(fit, 1))


# "nodeID"          "leftChild"       "rightChild"      "splitvarID"      "splitvarName"    
#"splitval"        "terminal"        "pred.setosa"     "pred.versicolor" "pred.virginica"
`` 

@ck37
Copy link
Author

ck37 commented Jul 30, 2024

Agreed, but I don't believe this package handles categorical outcomes. Looking at the different unify functions it's expecting there to be a single prediction column.

@mayer79
Copy link
Contributor

mayer79 commented Jul 30, 2024

Good point...

@ck37
Copy link
Author

ck37 commented Oct 3, 2024

@krzyzinskim Are you able to merge or propose any revisions?

@ck37
Copy link
Author

ck37 commented Aug 29, 2025

@krzyzinskim Checking back on this PR - are you able to review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants