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

histogram plot from plot.model_performance() is in reverse order #400

Closed
llendway opened this issue Mar 25, 2021 · 3 comments
Closed

histogram plot from plot.model_performance() is in reverse order #400

llendway opened this issue Mar 25, 2021 · 3 comments
Assignees
Labels
invalid ❕ This doesn't seem right, potential bug R 🐳 Related to R

Comments

@llendway
Copy link

The code below uses the example from the plot.model_performance() code. When used with multiple models and geom="histogram", the labels are incorrect (in reverse order, it seems).

library(patchwork)
library(DALEX)

titanic_ranger_model2 <- ranger(survived~gender + fare, data = titanic_imputed,
num.trees = 50, probability = TRUE)
explainer_ranger2 <- explain(titanic_ranger_model2, data = titanic_imputed[,-8],
y = titanic_imputed$survived,
label = "ranger2")
mp_ranger2 <- model_performance(explainer_ranger2)

titanic_glm_model <- glm(survived~., data = titanic_imputed, family = "binomial")
explainer_glm <- explain(titanic_glm_model, data = titanic_imputed[,-8],
y = titanic_imputed$survived, label = "glm",
predict_function = function(m,x) predict.glm(m,x,type = "response"))
mp_glm <- model_performance(explainer_glm)

titanic_lm_model <- lm(survived~., data = titanic_imputed)
explainer_lm <- explain(titanic_lm_model, data = titanic_imputed[,-8],
y = titanic_imputed$survived, label = "lm")
mp_lm <- model_performance(explainer_lm)

The histogram labels are reversed - the bottom graph should be ranger2 and the top glm.

plot(mp_glm, mp_ranger2, mp_lm, geom = "histogram") +
plot(mp_glm, mp_ranger2, mp_lm, geom = "boxplot")

This is clear after looking at the graph of only ranger2.

plot(mp_ranger2, geom = "histogram") +
plot(mp_ranger2, geom = "boxplot")

@hbaniecki hbaniecki added invalid ❕ This doesn't seem right, potential bug R 🐳 Related to R labels Mar 25, 2021
@hbaniecki
Copy link
Member

hbaniecki commented Mar 26, 2021

Indeed, this is due to this line:

# if factor, then levels shall be reversed
if (length(levels(df$label)) > 1) levels(df$label) <- rev(levels(df$label))

@pbiecek any idea why it is there? I found a mismatch of colours in EMA too. Can we delete it?

image

image

@pbiecek pbiecek self-assigned this Mar 26, 2021
@pbiecek
Copy link
Member

pbiecek commented Mar 26, 2021

thanks,
in fact labels were not consistent
and it was a problem not only in model_performance() but also model_parts()

it should be fixed in 24ba9cf

library(patchwork)
library(DALEX)
library(ranger)

titanic_ranger_model2 <- ranger(survived~gender + fare, data = titanic_imputed,
                                num.trees = 50, probability = TRUE)
explainer_ranger2 <- explain(titanic_ranger_model2, data = titanic_imputed[,-8],
                             y = titanic_imputed$survived,
                             label = "ranger2")
mp_ranger2 <- model_performance(explainer_ranger2)

titanic_glm_model <- glm(survived~., data = titanic_imputed, family = "binomial")
explainer_glm <- explain(titanic_glm_model, data = titanic_imputed[,-8],
                         y = titanic_imputed$survived, label = "glm",
                         predict_function = function(m,x) predict.glm(m,x,type = "response"))
mp_glm <- model_performance(explainer_glm)

titanic_lm_model <- lm(survived~., data = titanic_imputed)
explainer_lm <- explain(titanic_lm_model, data = titanic_imputed[,-8],
                        y = titanic_imputed$survived, label = "lm")
mp_lm <- model_performance(explainer_lm)
mp_pa <- model_parts(explainer_lm)
mp_pa2 <- model_parts(explainer_glm)
mp_pa3 <- model_parts(explainer_ranger2)

plot(mp_glm, mp_ranger2, mp_lm, geom = "histogram") +
  plot(mp_glm, mp_ranger2, mp_lm, geom = "boxplot") +
  plot(mp_pa2, mp_pa3, mp_pa)

@pbiecek
Copy link
Member

pbiecek commented May 9, 2021

fixed in 24ba9cf

@pbiecek pbiecek closed this as completed May 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid ❕ This doesn't seem right, potential bug R 🐳 Related to R
Projects
None yet
Development

No branches or pull requests

3 participants