Skip to content

Commit 1e61829

Browse files
committed
Fix issue where column name shap table changes
1 parent a853aa9 commit 1e61829

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

R/commonMachineLearningRegression.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,10 @@
753753
purpose <- "classification"
754754
}
755755
predictors <- model[["jaspVars"]][["encoded"]]$predictors
756+
predictorNames <- model[["jaspVars"]][["decoded"]]$predictors
756757
} else {
757758
predictors <- options[["predictors"]]
759+
predictorNames <- options[["predictors"]]
758760
}
759761
table$position <- position
760762
table$dependOn(options = c(
@@ -767,12 +769,12 @@
767769
))
768770
table$addColumnInfo(name = "id", title = gettext("Case"), type = "integer")
769771
if (purpose == "regression") {
770-
table$addColumnInfo(name = "pred", title = gettext("Predicted"), type = "number")
772+
table$addColumnInfo(name = "pred_jaspname", title = gettext("Predicted"), type = "number")
771773
} else {
772-
table$addColumnInfo(name = "pred", title = gettext("Predicted (Prob.)"), type = "string")
774+
table$addColumnInfo(name = "pred_jaspname", title = gettext("Predicted (Prob.)"), type = "string")
773775
}
774776
table$addColumnInfo(name = "avg", title = gettext("Base"), type = "number")
775-
for (i in predictors) {
777+
for (i in predictorNames) {
776778
table$addColumnInfo(name = i, title = i, type = "number")
777779
}
778780
jaspResults[["tableShap"]] <- table
@@ -791,7 +793,7 @@
791793
from <- min(c(options[["fromIndex"]], options[["toIndex"]] - 1, nrow(x_test)))
792794
to <- min(c(options[["toIndex"]], nrow(x_test)))
793795
out <- as.data.frame(matrix(NA, nrow = length(from:to), ncol = 3 + length(predictors)))
794-
colnames(out) <- c("id", "pred", "avg", predictors)
796+
colnames(out) <- c("id", "pred_jaspname", "avg", predictorNames)
795797
p <- try({
796798
for (i in seq_along(from:to)) {
797799
out[i, 1] <- (from:to)[i]

0 commit comments

Comments
 (0)