Skip to content

Commit

Permalink
Merge pull request #136 from ModelOriented/check-predictions
Browse files Browse the repository at this point in the history
Add checks to prediction output
  • Loading branch information
mayer79 authored Jul 6, 2024
2 parents 5c3914f + adff5c1 commit 8adc4e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ This release is intended to be the last before stable version 1.0.0.

## Major changes

- Factor-valued predictions are not anymore supported.
- Factor-valued predictions are not supported anymore.

## Maintenance

- Fix CRAN note about unavailable link to `gam::gam()`.
- Added dependency to {MASS} for calculating Moore-Penrose generalized matrix inverse.
- Slight code improvements.

# kernelshap 0.5.0

Expand Down
8 changes: 7 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ align_pred <- function(x) {
if (is.data.frame(x) && ncol(x) == 1L) {
x <- x[[1L]]
}
as.matrix(x)
if (!is.matrix(x)) {
x <- as.matrix(x)
}
if (!is.numeric(x) && !is.logical(x)) {
stop("Predictions must be numeric!")
}
return(x)
}

#' Head of List Elements
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ test_that("wrowmean_vector() works for 1D matrices", {
expect_equal(out2, cbind(a = c(a, b)))
})

test_that("align_pred() works", {
expect_error(align_pred(c("A", "B")))
expect_error(align_pred(factor(c("A", "B"))))
expect_equal(align_pred(1:4), as.matrix(1:4))
})

0 comments on commit 8adc4e7

Please sign in to comment.