Skip to content

Commit

Permalink
remove DALEX from examples
Browse files Browse the repository at this point in the history
  • Loading branch information
agosiewska committed May 27, 2020
1 parent e95565b commit 7acf1d4
Show file tree
Hide file tree
Showing 129 changed files with 440 additions and 618 deletions.
2 changes: 1 addition & 1 deletion R/audit.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @importFrom stats model.frame sd
#'
#' @examples
#' library(DALEX)
#' data(titanic_imputed, package = "DALEX")
#'
#' model_glm <- glm(survived ~ ., family = binomial, data = titanic_imputed)
#' audit_glm <- audit(model_glm,
Expand Down
26 changes: 10 additions & 16 deletions R/check_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
#' @importFrom utils head tail
#'
#' @examples
#' library(DALEX)
#' dragons <- DALEX::dragons[1:100, ]
#' lm_model <- lm(life_length ~ ., data = dragons)
#' lm_exp <- explain(lm_model, data = dragons, y = dragons$life_length)
#' library(auditor)
#' check_residuals(lm_exp)
#' lm_audit <- audit(lm_model, data = dragons, y = dragons$life_length)
#' check_residuals(lm_audit)
#' \dontrun{
#' library("randomForest")
#' rf_model <- randomForest(life_length ~ ., data = dragons)
#' rf_exp <- explain(rf_model, data = dragons, y = dragons$life_length)
#' check_residuals(rf_exp)
#' rf_audit <- audit(rf_model, data = dragons, y = dragons$life_length)
#' check_residuals(rf_audit)
#' }
check_residuals <- function(object, ...) {
if(!("explainer" %in% class(object))) stop("The function requires an object created with explain() function from the DALEX package.")
Expand All @@ -47,14 +45,12 @@ check_residuals <- function(object, ...) {
#' @export
#'
#' @examples
#' library(DALEX)
#' dragons <- DALEX::dragons[1:100, ]
#' lm_model <- lm(life_length ~ ., data = dragons)
#' library(auditor)
#' lm_exp <- explain(lm_model, data = dragons, y = dragons$life_length)
#' check_residuals_outliers(lm_exp)
#' lm_audit <- audit(lm_model, data = dragons, y = dragons$life_length)
#' check_residuals_outliers(lm_audit)
check_residuals_outliers <- function(object, n = 5) {
if(!("explainer" %in% class(object))) stop("The function requires an object created with explain() function from the DALEX package.")
if(!("explainer" %in% class(object))) stop("The function requires an object created with audit() function.")


model_name <- object$label
Expand Down Expand Up @@ -95,14 +91,12 @@ check_residuals_outliers <- function(object, n = 5) {
#' @export
#'
#' @examples
#' library(DALEX)
#' dragons <- DALEX::dragons[1:100, ]
#' lm_model <- lm(life_length ~ ., data = dragons)
#' lm_exp <- explain(lm_model, data = dragons, y = dragons$life_length)
#' library(auditor)
#' check_residuals_autocorrelation(lm_exp)
#' lm_audit <- audit(lm_model, data = dragons, y = dragons$life_length)
#' check_residuals_autocorrelation(lm_audit)
check_residuals_autocorrelation <- function(object, method = "pearson") {
if(!("explainer" %in% class(object))) stop("The function requires an object created with explain() function from the DALEX package.")
if(!("explainer" %in% class(object))) stop("The function requires an object created with audit().")

model_name <- object$label

Expand Down
7 changes: 3 additions & 4 deletions R/model_cooksdistance.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
#' @return An object of the class \code{auditor_model_cooksdistance}.
#'
#' @examples
#' library(DALEX)
#' data(titanic_imputed, package = "DALEX")
#'
#' # fit a model
#' model_glm <- glm(survived ~ ., family = binomial, data = titanic_imputed)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_glm <- explain(model_glm,
#' glm_audit <- audit(model_glm,
#' data = titanic_imputed,
#' y = titanic_imputed$survived)
#'
#' # validate a model with auditor
#' library(auditor)
#' mc <- model_cooksdistance(exp_glm)
#' mc <- model_cooksdistance(glm_audit)
#' mc
#'
#' plot(mc)
Expand Down
8 changes: 3 additions & 5 deletions R/model_evaluation.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
#' @return An object of the class \code{auditor_model_evaluation}.
#'
#' @examples
#' library(DALEX)
#' data(titanic_imputed, package = "DALEX")
#'
#' # fit a model
#' model_glm <- glm(survived ~ ., family = binomial, data = titanic_imputed)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_glm <- explain(model_glm,
#' glm_audit <- audit(model_glm,
#' data= titanic_imputed,
#' y = titanic_imputed$survived)
#'
#' # validate a model with auditor
#' library(auditor)
#' me <- model_evaluation(exp_glm)
#' me <- model_evaluation(glm_audit)
#' me
#'
#' plot(me)
Expand Down
8 changes: 3 additions & 5 deletions R/model_halfnormal.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@
#' @param ... other parameters passed do \code{\link[hnp]{hnp}} function.
#'
#' @examples
#' library(DALEX)
#' data(titanic_imputed, package = "DALEX")
#'
#' # fit a model
#' model_glm <- glm(survived ~ ., family = binomial, data = titanic_imputed)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_glm <- explain(model_glm,
#' glm_audit <- audit(model_glm,
#' data = titanic_imputed,
#' y = titanic_imputed$survived)
#'
#' # validate a model with auditor
#' library(auditor)
#' mh <- model_halfnormal(exp_glm)
#' mh <- model_halfnormal(glm_audit)
#' mh
#'
#' plot(mh)
Expand Down
6 changes: 3 additions & 3 deletions R/model_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
#' @return An object of the class \code{auditor_model_performance}.
#'
#' @examples
#' library(DALEX)
#' data(titanic_imputed, package = "DALEX")
#'
#' # fit a model
#' model_glm <- glm(survived ~ ., family = binomial, data = titanic_imputed)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_glm <- explain(model_glm,
#' glm_audit <- audit(model_glm,
#' data = titanic_imputed,
#' y = titanic_imputed$survived)
#'
#' # validate a model with auditor
#' library(auditor)
#' mp <- model_performance(exp_glm)
#' mp <- model_performance(glm_audit)
#' mp
#'
#' plot(mp)
Expand Down
6 changes: 2 additions & 4 deletions R/model_residual.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
#' # fit a model
#' model_glm <- glm(m2.price ~ ., data = apartments)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_glm <- explain(model_glm,
#' glm_audit <- explain(model_glm,
#' data = apartments,
#' y = apartments$m2.price)
#'
#' # validate a model with auditor
#' library(auditor)
#' mr <- model_residual(exp_glm)
#' mr <- model_residual(glm_audit)
#' mr
#'
#' plot(mr)
Expand Down
14 changes: 6 additions & 8 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,24 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' mr_lm <- model_residual(exp_lm)
#' mr_lm <- model_residual(lm_audit)
#'
#' # plot results
#' plot(mr_lm)
#' plot(mr_lm, type = "prediction")
#'
#' hn_lm <- model_halfnormal(exp_lm)
#' hn_lm <- model_halfnormal(lm_audit)
#' plot(hn_lm)
#'
#' library(randomForest)
#' model_rf <- randomForest(life_length~., data = dragons)
#' exp_rf <- DALEX::explain(model_rf, data = dragons, y = dragons$life_length)
#' rf_audit <- audit(model_rf, data = dragons, y = dragons$life_length)
#'
#' mp_rf <- model_performance(exp_rf)
#' mp_lm <- model_performance(exp_lm)
#' mp_rf <- model_performance(rf_audit)
#' mp_lm <- model_performance(lm_audit)
#' plot(mp_lm, mp_rf)
#'
#' @import ggplot2
Expand Down
8 changes: 3 additions & 5 deletions R/plotD3.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' mr_lm <- model_residual(exp_lm)
#' mr_lm <- model_residual(lm_audit)
#'
#' # plot results
#' plotD3(mr_lm)
#' plotD3(mr_lm, type = "prediction")
#'
#' hn_lm <- model_halfnormal(exp_lm)
#' hn_lm <- model_halfnormal(lm_audit)
#' plotD3(hn_lm)
#'
#'
Expand Down
10 changes: 4 additions & 6 deletions R/plotD3_acf.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' mr_lm <- model_residual(exp_lm)
#' mr_lm <- model_residual(lm_audit)
#'
#' # plot results
#' plotD3_acf(mr_lm)
#'
#' library(randomForest)
#' model_rf <- randomForest(life_length~., data = dragons)
#' exp_rf <- DALEX::explain(model_rf, data = dragons, y = dragons$life_length)
#' mr_rf <- model_residual(exp_rf)
#' rf_audit <- audit(model_rf, data = dragons, y = dragons$life_length)
#' mr_rf <- model_residual(rf_audit)
#' plotD3_acf(mr_lm, mr_rf)
#'
#' @importFrom stats qnorm acf
Expand Down
6 changes: 2 additions & 4 deletions R/plotD3_autocorrelation.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' mr_lm <- model_residual(exp_lm)
#' mr_lm <- model_residual(lm_audit)
#'
#' # plot results
#' plotD3_autocorrelation(mr_lm)
Expand Down
6 changes: 2 additions & 4 deletions R/plotD3_cooksdistance.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' cd_lm <- model_cooksdistance(exp_lm)
#' cd_lm <- model_cooksdistance(lm_audit)
#'
#' # plot results
#' plotD3_cooksdistance(cd_lm, nlabel = 5)
Expand Down
6 changes: 2 additions & 4 deletions R/plotD3_halfnormal.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' hn_lm <- model_halfnormal(exp_lm)
#' hn_lm <- model_halfnormal(lm_audit)
#'
#' # plot results
#' plotD3_halfnormal(hn_lm)
Expand Down
12 changes: 5 additions & 7 deletions R/plotD3_lift.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,29 @@
#' @seealso \code{\link{plot_lift}}
#'
#' @examples
#' library(DALEX)
#' data(titanic_imputed, package = "DALEX")
#'
#' # fit a model
#' model_glm <- glm(survived ~ ., family = binomial, data = titanic_imputed)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_glm <- explain(model_glm,
#' glm_audit <- audit(model_glm,
#' data = titanic_imputed,
#' y = titanic_imputed$survived)
#'
#' # validate a model with auditor
#' library(auditor)
#' eva_glm <- model_evaluation(exp_glm)
#' eva_glm <- model_evaluation(glm_audit)
#'
#' # plot results
#' plot_roc(eva_glm)
#' plot(eva_glm)
#'
#' #add second model
#' model_glm_2 <- glm(survived ~ .-age, family = binomial, data = titanic_imputed)
#' exp_glm_2 <- explain(model_glm_2,
#' glm_audit_2 <- audit(model_glm_2,
#' data = titanic_imputed,
#' y = titanic_imputed$survived,
#' label = "glm2")
#' eva_glm_2 <- model_evaluation(exp_glm_2)
#' eva_glm_2 <- model_evaluation(glm_audit_2)
#'
#' plotD3_lift(eva_glm, eva_glm_2)
#'
Expand Down
10 changes: 4 additions & 6 deletions R/plotD3_prediction.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' mr_lm <- model_residual(exp_lm)
#' mr_lm <- model_residual(lm_audit)
#'
#' # plot results
#' plotD3_prediction(mr_lm, abline = TRUE)
#' plotD3_prediction(mr_lm, variable = "height", smooth = TRUE)
#'
#' library(randomForest)
#' model_rf <- randomForest(life_length~., data = dragons)
#' exp_rf <- DALEX::explain(model_rf, data = dragons, y = dragons$life_length)
#' mr_rf <- model_residual(exp_rf)
#' rf_audit <- audit(model_rf, data = dragons, y = dragons$life_length)
#' mr_rf <- model_residual(rf_audit)
#' plotD3_prediction(mr_lm, mr_rf, variable = "weight", smooth = TRUE)
#'
#' @export
Expand Down
10 changes: 4 additions & 6 deletions R/plotD3_rec.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@
#' # fit a model
#' model_lm <- lm(life_length ~ ., data = dragons)
#'
#' # use DALEX package to wrap up a model into explainer
#' exp_lm <- DALEX::explain(model_lm, data = dragons, y = dragons$life_length)
#' lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#'
#' # validate a model with auditor
#' library(auditor)
#' mr_lm <- model_residual(exp_lm)
#' mr_lm <- model_residual(lm_audit)
#' plotD3_rec(mr_lm)
#'
#' library(randomForest)
#' model_rf <- randomForest(life_length~., data = dragons)
#' exp_rf <- DALEX::explain(model_rf, data = dragons, y = dragons$life_length)
#' mr_rf <- model_residual(exp_rf)
#' rf_audit <- audit(model_rf, data = dragons, y = dragons$life_length)
#' mr_rf <- model_residual(rf_audit)
#' plotD3_rec(mr_lm, mr_rf)
#'
#' @export
Expand Down
Loading

0 comments on commit 7acf1d4

Please sign in to comment.