Skip to content

Commit b0d00d9

Browse files
committed
Update LIFT chart
1 parent c06326b commit b0d00d9

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Imports: car,
2323
plotROC,
2424
ROCR,
2525
tseries
26-
RoxygenNote: 6.0.1
26+
RoxygenNote: 6.1.0
2727
Suggests: aods3,
2828
breakDown,
2929
DALEX,

R/modelEvaluation.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ modelEvaluation <- function(object, variable = NULL){
1010
if(!("modelAudit" %in% class(object))) stop("The function requires an object created with audit().")
1111

1212
CGainsDF <- getCGainsDF(object)[-1,]
13+
idealCGainsDF <- getidealCGainsDF(object)[-1,]
1314

1415
result <- data.frame(
1516
y=object$y,
@@ -18,6 +19,7 @@ modelEvaluation <- function(object, variable = NULL){
1819

1920
class(result) <- c("modelEvaluation", "data.frame")
2021
attr(result,'CGains') <- CGainsDF
22+
attr(result,'idealCGains') <- idealCGainsDF
2123
return(result)
2224
}
2325

@@ -35,3 +37,15 @@ getCGainsDF <- function(object){
3537
return(res)
3638
}
3739

40+
getidealCGainsDF <- function(object){
41+
42+
predictions <- object$y
43+
y <- as.numeric(as.character(object$y))
44+
45+
pred <- ROCR::prediction(predictions, y)
46+
gain <- ROCR::performance(pred, "tpr", "rpp")
47+
48+
res <- data.frame(rpp = gain@x.values[[1]], tp = pred@tp[[1]], alpha = gain@alpha.values[[1]],
49+
label = "ideal")
50+
return(res)
51+
}

R/plotLift.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ plotLIFT <- function(object, ...){
3232
rpp <- tp <- label <- NULL
3333

3434
df <- attributes(object)$CGains
35+
idealdf <- attributes(object)$idealCGains
36+
idealdf <- rbind(idealdf, c(0, 0, 0, "ideal"))
37+
idealdf$tp <- as.numeric(idealdf$tp)
38+
idealdf$rpp <- as.numeric(idealdf$rpp)
39+
idealdf$alpha <- as.numeric(idealdf$alpha)
40+
41+
randomdf <- data.frame(rpp = c(0, 1), tp = c(0, max(idealdf$tp)), alpha = c(0, 1),
42+
label =c("random", "random"))
3543

3644
dfl <- list(...)
3745
if (length(dfl) > 0) {
@@ -48,6 +56,8 @@ plotLIFT <- function(object, ...){
4856

4957
ggplot(df, aes(x = rpp, y = tp, color = label)) +
5058
geom_line() +
59+
geom_line(data = idealdf, aes(x = rpp, y = tp), color = "orange") +
60+
geom_line(data = randomdf, aes(x = rpp, y = tp), color = "black") +
5161
xlab("rate of positive prediction") +
5262
ylab("true positive") +
5363
ggtitle("LIFT Chart") +

R/plotModelRanking.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ plotModelRanking <- function(object, ..., scores = c("MAE", "MSE", "REC", "RROC"
6969
df$scaled <- scr
7070
df$scaled <- format(as.numeric(df$scaled), scientific = FALSE, digits = 3)
7171
df$score <- format(df$score, scientific = TRUE, digits = 3)
72-
df <- df[ ,c(3,2,4,1)]
72+
df <- df[ ,c(3,2,1,4)]
7373

7474

7575
table_score <- tableGrob(df,

R/plotREC.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ plotREC <- function(object, ...){
5454
labels = paste(seq(0, 100, 10),"%")) +
5555
theme_light() +
5656
xlab("error tolerance") +
57+
ylab("") +
5758
ggtitle("REC Curve")
5859

5960
}

man/plot.modelAudit.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotResidual.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)