0

I have this code that renders "_xgb.Booster" "model_fit" object classes. I should, but I am not sure how to provide the entire reproducible example code with data here!

xgb <- boost_tree(mode = "classification",

                      trees = 100,
                      mtry = 0.7,
                      learn_rate = 0.15,
                      tree_depth = 10,
                      sample_size = 1) %>%
      set_engine("xgboost") %>%
      fit(Y ~ ., data = train)

How can I calculate the lift curves and decile lift charts using this xgb object?

Geet
  • 2,515
  • 2
  • 19
  • 42
  • please make this into reproducible example as stated in the `r` tag wiki https://stackoverflow.com/tags/r/info – Nate Aug 19 '20 at 13:30

1 Answers1

1

Once you have your data in the form such as what is in the example dataset two_class_example, you can use the lift_curve() function to compute this. Then you can make visualizations with the lift curve.

library(tidymodels)

two_class_lift <- two_class_example %>%
  lift_curve(truth, Class1) 

two_class_lift %>%
  autoplot()


two_class_lift %>%
  group_by(.percent_tested = cut_interval(.percent_tested, n = 10)) %>%
  summarise(.lift = mean(.lift, na.rm = TRUE)) %>%
  ggplot(aes(.percent_tested, .lift)) +
  geom_col() +
  theme_bw() +
  labs(x = "% Tested", y = "Lift")
#> `summarise()` ungrouping output (override with `.groups` argument)

Created on 2020-08-26 by the reprex package (v0.3.0.9001)

If you need help getting predictions out of your xgboost model, check out this article at tidymodels.org.

Julia Silge
  • 10,848
  • 2
  • 40
  • 48