mlr3viz
mlr3viz copied to clipboard
LIFT curve
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
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 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?