mlr3viz icon indicating copy to clipboard operation
mlr3viz copied to clipboard

LIFT curve

Open MathieuMarauri opened this issue 4 years ago • 2 comments

Hello,

I was wondering if there is a way to plot the LIFT curve associated with a binary classification model. It is possible to plot ROC curves using autoplot() but I could not find a way to plot LIFT curves.

Best regards, Mathieu

MathieuMarauri avatar Nov 22 '21 21:11 MathieuMarauri

Here is the code I used to make the Lift curve if it can be of any help.

library(ggplot2)
library(mlr3)
library(mlr3viz)
library(purrr)

task = tsk("spam")
learner = lrn("classif.rpart", predict_type = "prob")
object = learner$train(task)$predict(task)
# Part that could be included in the autoplot function
pred = object$clone(deep = TRUE)
tab = data.table(prob = seq(from = 0, to = 1, by = 0.01))
result = purrr::map_dfr(tab$prob, function(p) {
  pred$set_threshold(p)$score(list(
    msr('classif.tpr'), 
    msr('classif.tp'), 
    msr('classif.fp')
  ))
})
result = as.data.table(result)[, pp := (classif.tp + classif.fp) / length(pred$response)]
ggplot(
  data = result,
  mapping = aes_string(x = "pp", y = "classif.tpr")
) +
  geom_line() +
  labs(
    x = 'Positive rate',
    y = 'Sensibility',
    title = 'Lift curve'
  )

MathieuMarauri avatar Nov 24 '21 09:11 MathieuMarauri

@MathieuMarauri Thanks! Sounds like we could easily support this. I've never used a LIFT curve so far but it seems to be similar to ROC and not too complicated to implement.

@mllg What do you think?

pat-s avatar May 30 '22 19:05 pat-s