diff --git a/R/plotCGains.R b/R/plotCGains.R index 7f270d9e..54bf4d55 100644 --- a/R/plotCGains.R +++ b/R/plotCGains.R @@ -3,8 +3,6 @@ #' @description Cumulative Gains Chartis a plot of the rate of positive prediction against true positive rate for the different thresholds. #' It is useful for measuring and comparing the accuracy of the classificators. #' @param object An object of class ModelAudit -#' @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. -#' @param newy optionally, required if newdata used. Response vector for new data. #' @param ... other modelAudit objects to be plotted together #' #' @return ggplot object @@ -14,33 +12,20 @@ #' @import ggplot2 #' @import ROCR #' -#' @examples -#' library(auditor) -#' library(mlbench) -#' library(randomForest) -#' data("PimaIndiansDiabetes") -#' -#' model_rf <- randomForest(diabetes~., data=PimaIndiansDiabetes) -#' au_rf <- audit(model_rf, label="rf") -#' plotCGains(au_rf) -#' -#' model_glm <- glm(diabetes~., family=binomial, data=PimaIndiansDiabetes) -#' au_glm <- audit(model_glm) -#' plotCGains(au_rf, au_glm) #' #' @export -plotCGains <- function(object, ..., newdata = NULL, newy){ +plotCGains <- function(object, ...){ if(class(object)!="modelAudit") stop("plotCGains requires object class modelAudit.") rpp <- tpr <- label <- NULL - df <- getCGainsDF(object, newdata, newy) + df <- getCGainsDF(object) dfl <- list(...) if (length(dfl) > 0) { for (resp in dfl) { if(class(resp)=="modelAudit"){ - df <- rbind( df, getCGainsDF(resp, newdata, newy) ) + df <- rbind( df, getCGainsDF(resp) ) } } } @@ -52,15 +37,10 @@ plotCGains <- function(object, ..., newdata = NULL, newy){ theme_light() } -getCGainsDF <- function(object, newdata, newy){ - if (is.null(newdata)) { - predictions <- object$fitted.values - y <- object$y - } else { - if(is.null(newy)) stop("newy must be provided.") - predictions <- object$predict.function(object$model, newdata) - y <- newy - } +getCGainsDF <- function(object){ + + predictions <- object$fitted.values + y <- as.numeric(as.character(object$y)) pred <- prediction(predictions, y) gain <- performance(pred, "tpr", "rpp") diff --git a/R/plotLift.R b/R/plotLift.R index e12b8778..1b575800 100644 --- a/R/plotLift.R +++ b/R/plotLift.R @@ -45,7 +45,7 @@ plotLIFT <- function(object, ..., groups = 10, cumulative = TRUE){ getLIFTDF <- function(object, n.groups, cumulative = TRUE){ pred <- NULL - y = object$y + y = as.numeric(as.character(object$y)) df <- data.frame(pred=object$fitted.values, y=y) df <- arrange(df, desc(pred)) diff --git a/R/plotModelPCA.R b/R/plotModelPCA.R index 630448bb..7dc81f23 100644 --- a/R/plotModelPCA.R +++ b/R/plotModelPCA.R @@ -29,7 +29,7 @@ plotModelPCA <- function(object, ...){ } } - res.pca <- prcomp(df, scale = TRUE) + res.pca <- prcomp(df, scale = FALSE) fviz_pca_biplot(res.pca, repel = TRUE, diff --git a/man/plotCGains.Rd b/man/plotCGains.Rd index 452e6edc..59cff486 100644 --- a/man/plotCGains.Rd +++ b/man/plotCGains.Rd @@ -4,16 +4,12 @@ \alias{plotCGains} \title{Cumulative Gains Chart} \usage{ -plotCGains(object, ..., newdata = NULL, newy) +plotCGains(object, ...) } \arguments{ \item{object}{An object of class ModelAudit} \item{...}{other modelAudit objects to be plotted together} - -\item{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.} - -\item{newy}{optionally, required if newdata used. Response vector for new data.} } \value{ ggplot object @@ -21,21 +17,6 @@ ggplot object \description{ Cumulative Gains Chartis a plot of the rate of positive prediction against true positive rate for the different thresholds. It is useful for measuring and comparing the accuracy of the classificators. -} -\examples{ -library(auditor) -library(mlbench) -library(randomForest) -data("PimaIndiansDiabetes") - -model_rf <- randomForest(diabetes~., data=PimaIndiansDiabetes) -au_rf <- audit(model_rf, label="rf") -plotCGains(au_rf) - -model_glm <- glm(diabetes~., family=binomial, data=PimaIndiansDiabetes) -au_glm <- audit(model_glm) -plotCGains(au_rf, au_glm) - } \seealso{ \code{\link{plot.modelAudit}}