From 2353a30550b815611d0416d1aad8a0ba59623135 Mon Sep 17 00:00:00 2001 From: Hubert Baniecki Date: Fri, 2 Apr 2021 17:00:52 +0200 Subject: [PATCH] potential fix for #93 --- NEWS.md | 3 ++- R/break_down_uncertainty.R | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index e6446a3..c46a711 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ -iBreakDown (development) +iBreakDown 2.0.1 --------------------------------------------------------------- * add `reload` argument to `plotD3`, which by default is `FALSE` (behavior unchanged); `TRUE` reloads the plot on resize [#89](https://github.com/ModelOriented/iBreakDown/issues/89) +* fixes explanations when data has one column [#93](https://github.com/ModelOriented/iBreakDown/issues/93) iBreakDown 1.3.1 --------------------------------------------------------------- diff --git a/R/break_down_uncertainty.R b/R/break_down_uncertainty.R index 7992927..fc07449 100644 --- a/R/break_down_uncertainty.R +++ b/R/break_down_uncertainty.R @@ -141,9 +141,9 @@ break_down_uncertainty.default <- function(x, data, predict_function = predict, # average or selected path if (head(path, 1) == "average") { # let's calculate an average attribution - extracted_contributions <- sapply(result, function(chunk) { + extracted_contributions <- do.call(cbind, lapply(result, function(chunk) { chunk[order(chunk$label, chunk$variable), "contribution"] - }) + })) result_average <- result[[1]] result_average <- result_average[order(result_average$label, result_average$variable),] result_average$contribution <- rowMeans(extracted_contributions) @@ -206,7 +206,9 @@ get_single_random_path <- function(x, data, predict_function, new_observation, l } diffs <- apply(do.call(rbind, yhats), 2, diff) - + if (is.vector(diffs)) { #93 + diffs <- t(diffs) + } #76 new_observation_vec <- sapply(as.data.frame(new_observation), nice_format) # same as in BD