Skip to content

Commit

Permalink
fix(prediction): predict_time for no predictions (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebffischer authored Sep 3, 2024
1 parent d686b87 commit ee3f39d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/worker.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ workhorse = function(iteration, task, learner, resampling, param_values = NULL,
lg$debug("Creating Prediction for predict set '%s'", set)
learner_predict(learner, task, row_ids)
}, set = predict_sets, row_ids = pred_data$sets, task = pred_data$tasks)

if (!length(predict_sets)) {
learner$state$predict_time = 0L
}
pdatas = discard(pdatas, is.null)

# set the model slot after prediction so it can be sent back to the main process
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test_resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,10 @@ test_that("resample results works with no predicted predict set", {
expect_list(tab$prediction, len = 1)
expect_list(tab$prediction[[1]], len = 0)
})

test_that("predict_time is 0 if no predict_set is specified", {
learner = lrn("classif.featureless", predict_sets = NULL)
rr = resample(task, learner, resampling)
times = rr$score(msr("time_predict"))$time_predict
expect_true(all(times == 0))
})

0 comments on commit ee3f39d

Please sign in to comment.