Skip to content

Commit cdb8d6a

Browse files
Merge pull request #202 from tidymodels/xgboost-fix
2 parents 4ecb4cf + d887acb commit cdb8d6a

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# lime (development version)
22

3+
* Make package work with all versions of xgboost. (#202)
4+
35
# lime 0.5.3
46

57
* Emil Hvitfelt is taking over maintenance

R/models.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ predict_model.xgb.Booster <- function(x, newdata, type, ...) {
155155
if (is.data.frame(newdata)) {
156156
newdata <- xgboost::xgb.DMatrix(as.matrix(newdata))
157157
}
158-
p <- data.frame(
159-
predict(x, newdata = newdata, reshape = TRUE, ...),
160-
stringsAsFactors = FALSE
161-
)
158+
if (is.null(x$params)) {
159+
p <- data.frame(predict(x, newdata = newdata, ...))
160+
} else {
161+
p <- data.frame(predict(x, newdata = newdata, reshape = TRUE, ...))
162+
}
162163
if (type == 'raw') {
163164
names(p) <- 'Response'
164165
} else if (type == 'prob') {
@@ -277,7 +278,7 @@ model_type.WrappedModel <- function(x, ...) {
277278
}
278279
#' @export
279280
model_type.xgb.Booster <- function(x, ...) {
280-
obj <- x$params$objective
281+
obj <- x$params$objective %||% attr(x, "params")$objective
281282
if (is.null(obj)) {
282283
return('regression')
283284
}

tests/testthat/test-text.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ xgb_model <- xgb.train(
2828
nrounds = 50
2929
)
3030

31-
3231
test_that("single sentence explanation", {
33-
skip("xgboost: will fix soon")
3432
to_explain <- "Since our motivation is an application in bioinformatics, our notation and terminology will be drawn from that area"
3533
expect_gt(predict(xgb_model, get_matrix(to_explain)), 0.5)
3634
explainer <- lime(x = to_explain, model = xgb_model, preprocess = get_matrix)

0 commit comments

Comments
 (0)