Skip to content

Commit 6143c09

Browse files
committed
Fix plotFift
1 parent 979edf9 commit 6143c09

File tree

4 files changed

+10
-49
lines changed

4 files changed

+10
-49
lines changed

R/plotCGains.R

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#' @description Cumulative Gains Chartis a plot of the rate of positive prediction against true positive rate for the different thresholds.
44
#' It is useful for measuring and comparing the accuracy of the classificators.
55
#' @param object An object of class ModelAudit
6-
#' @param newdata optionally, a data frame in which to look for variables with which to plot CGains curve. If omitted, the data used to build model will be used.
7-
#' @param newy optionally, required if newdata used. Response vector for new data.
86
#' @param ... other modelAudit objects to be plotted together
97
#'
108
#' @return ggplot object
@@ -14,33 +12,20 @@
1412
#' @import ggplot2
1513
#' @import ROCR
1614
#'
17-
#' @examples
18-
#' library(auditor)
19-
#' library(mlbench)
20-
#' library(randomForest)
21-
#' data("PimaIndiansDiabetes")
22-
#'
23-
#' model_rf <- randomForest(diabetes~., data=PimaIndiansDiabetes)
24-
#' au_rf <- audit(model_rf, label="rf")
25-
#' plotCGains(au_rf)
26-
#'
27-
#' model_glm <- glm(diabetes~., family=binomial, data=PimaIndiansDiabetes)
28-
#' au_glm <- audit(model_glm)
29-
#' plotCGains(au_rf, au_glm)
3015
#'
3116
#' @export
3217

3318

34-
plotCGains <- function(object, ..., newdata = NULL, newy){
19+
plotCGains <- function(object, ...){
3520
if(class(object)!="modelAudit") stop("plotCGains requires object class modelAudit.")
3621
rpp <- tpr <- label <- NULL
37-
df <- getCGainsDF(object, newdata, newy)
22+
df <- getCGainsDF(object)
3823

3924
dfl <- list(...)
4025
if (length(dfl) > 0) {
4126
for (resp in dfl) {
4227
if(class(resp)=="modelAudit"){
43-
df <- rbind( df, getCGainsDF(resp, newdata, newy) )
28+
df <- rbind( df, getCGainsDF(resp) )
4429
}
4530
}
4631
}
@@ -52,15 +37,10 @@ plotCGains <- function(object, ..., newdata = NULL, newy){
5237
theme_light()
5338
}
5439

55-
getCGainsDF <- function(object, newdata, newy){
56-
if (is.null(newdata)) {
57-
predictions <- object$fitted.values
58-
y <- object$y
59-
} else {
60-
if(is.null(newy)) stop("newy must be provided.")
61-
predictions <- object$predict.function(object$model, newdata)
62-
y <- newy
63-
}
40+
getCGainsDF <- function(object){
41+
42+
predictions <- object$fitted.values
43+
y <- as.numeric(as.character(object$y))
6444

6545
pred <- prediction(predictions, y)
6646
gain <- performance(pred, "tpr", "rpp")

R/plotLift.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ plotLIFT <- function(object, ..., groups = 10, cumulative = TRUE){
4545

4646
getLIFTDF <- function(object, n.groups, cumulative = TRUE){
4747
pred <- NULL
48-
y = object$y
48+
y = as.numeric(as.character(object$y))
4949
df <- data.frame(pred=object$fitted.values, y=y)
5050
df <- arrange(df, desc(pred))
5151

R/plotModelPCA.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ plotModelPCA <- function(object, ...){
2929
}
3030
}
3131

32-
res.pca <- prcomp(df, scale = TRUE)
32+
res.pca <- prcomp(df, scale = FALSE)
3333

3434
fviz_pca_biplot(res.pca,
3535
repel = TRUE,

man/plotCGains.Rd

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

0 commit comments

Comments
 (0)