Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Ensure that the data arg in Predictor$new is always a data.frame #126

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions R/Predictor.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ Predictor <- R6Class("Predictor",
y <- NULL
}
}

# data needs to be a data.frame to work with class "Data" (#115)
if (inherits(data, "data.table")) {
data.table::setDF(data)
}

self$data <- Data$new(data, y = y)
self$class <- class
Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test-Predictor.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test_that("extracts y automatically for H2OBinomialModel", {
test_that("extracts y automatically for H2ORegressionModel", {
skip_on_os("windows")
skip_on_cran()
expect_equal(predictor.h2o.regr$data$y.names, "Sepal.Width")
expect_equal(predictor.h2o.regr$data$y.names, "Sepal.Width")
})

test_that("extracts data automatically for caret::train", {
Expand Down Expand Up @@ -114,12 +114,18 @@ test_that("Keras classification can get nice column names through custom predict
)
})

# Test single class predictions
# Test single class predictions

# mlr
predictor.mlr <- Predictor$new(mod.mlr, class = 2, data = iris)
# mlr3
predictor.mlr3 <- Predictor$new(learner_iris, class = 2, data = iris)
# mlr3_ check that mlr3 tasks work when supplied as "data" (#115)
train <- sample(task_iris$nrow, task_iris$nrow * 2 / 3)
predictor.mlr3_2 <- Predictor$new(learner_iris,
data = task_iris$data(train, cols = task_iris$feature_names),
y = task_iris$truth(train)
)
# S3 predict
predictor.S3 <- Predictor$new(mod.S3,
class = 2, predict.fun = predict.fun,
Expand Down