Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in ranger.unify() #39

Open
Novampe opened this issue Apr 22, 2024 · 3 comments
Open

Error in ranger.unify() #39

Novampe opened this issue Apr 22, 2024 · 3 comments

Comments

@Novampe
Copy link

Novampe commented Apr 22, 2024

I tried to unify my binary classification rf model trained by ranger. There is an error
Warning message:
In Ops.factor(get("Prediction"), n) : ‘/’ not meaningful for factors

I don't know how to get rid of it and make my code run. Any idea about this error would be appreciated.

@mayer79
Copy link
Contributor

mayer79 commented Apr 22, 2024

Please add a minimal reproducible example.

@nlebovits
Copy link

nlebovits commented Jul 30, 2024

@mayer79 I've been running into the same issue, plus an error where treeshap doesn't recognize a model_unified object:

library(treeshap)
library(ranger)
library(dplyr)
library(mlr)

set.seed(1)
data(iris)

dat_prepared <- iris
dat_prepared$Species <- as.factor(dat_prepared$Species)
predictors <- dat_prepared %>% select(-Species)
predictors_encoded <- createDummyFeatures(predictors)
dat_encoded <- cbind(predictors_encoded, Species = dat_prepared$Species)

rf <- ranger(Species ~ ., data = dat_encoded)
unified_model <- ranger.unify(rf, dat_encoded)
shaps <- treeshap(unified_model, dat_encoded[1:50, ])

After ranger.unify, it throws "Warning: '/' not meaningful for factors". Then, after treeshap, it breaks and throws "Error in treeshap.model_unified(unified_model, dat_encoded[1:50, ]) : unified_model parameter has to of class model_unified. Produce it using *.unify function."

I'm using treeshap version 0.3.1 and ranger version 0.16.0.

@mayer79
Copy link
Contributor

mayer79 commented Jul 30, 2024

@nlebovits I am not maintainer.

SHAP can't be calculated for non-probabilistic classification models. It requires numeric predictions, e.g., logit probabilities.

There is an open PR that allows probabilistic classification for ranger objects:

#43

Maybe you can test this?

library(remotes)

install_github("ModelOriented/treeshap", ref = github_pull("43"))

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

No branches or pull requests

3 participants