Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Staniak committed Jan 9, 2018
1 parent a591c7e commit 33fd052
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion R/explain.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ prepare_forestplot <- function(model) {
#'
#' @return plot (ggplot2 or base)
#'

plot_regression <- function(plot_type, fitted_model, explained_instance, scale = NULL) {
if(plot_type == "forestplot") {
prepare_forestplot(fitted_model)
} else {
if(scale == "probability") {
plot(breakDown::broken(fitted_model, explained_instance, baseline = "intercept"),
trans = function(x) exp(x)/(1 + exp(x))) +
scale_y_continuous(limits = c(0, 1), name = "probability", expand = c(0, 0))
ggplot2::scale_y_continuous(limits = c(0, 1),
name = "probability",
expand = c(0, 0))

} else {
plot(breakDown::broken(fitted_model, explained_instance, baseline = "intercept"))
Expand Down
21 changes: 18 additions & 3 deletions vignettes/HR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trees <- randomForest(left~., data = HR_data, ntree=1000)
similar <- sample_locally(data = HR_data,
explained_instance = HR_data[2,],
explained_var = "left",
size = 200)
size = 2000)
head(similar$data)
similar <- add_predictions(HR_Data, similar, black_box_model = trees)
Expand All @@ -32,8 +32,23 @@ trained <- fit_explanation(live_object = similar,
selection = FALSE)
# trained
plot_explanation(trained, "waterfallplot",
explained_instance = HR_data[1,],
explained_instance = HR_data[2,],
scale = "probability")
plot_explanation(trained, "forestplot",
explained_instance = HR_data[1,])
explained_instance = HR_data[2,])
HR_data$left <- as.numeric(as.character(HR_data$left))
trees <- randomForest(left~., data = HR_data, ntree=1000)
similar2 <- sample_locally(data = HR_data,
explained_instance = HR_data[2,],
explained_var = "left",
size = 2000)
similar2 <- add_predictions(HR_Data, similar2, black_box_model = trees)
glimpse(similar2$data)
trained2 <- fit_explanation(live_object = similar2,
white_box = "regr.lm",
selection = F)
plot_explanation(trained2, "forestplot",
explained_instance = HR_data[2,])
```

0 comments on commit 33fd052

Please sign in to comment.