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

feat: add callbacks for resample and benchmark #1214

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open

feat: add callbacks for resample and benchmark #1214

wants to merge 58 commits into from

Conversation

be-marc
Copy link
Member

@be-marc be-marc commented Nov 21, 2024

Additional overhead is less than 3% when using 10ms models

Copy link
Member

@sebffischer sebffischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I think we should also provide an example for how to implement a custom callback.

R/CallbackEvaluation.R Outdated Show resolved Hide resolved
R/CallbackEvaluation.R Outdated Show resolved Hide resolved
R/CallbackEvaluation.R Outdated Show resolved Hide resolved
R/CallbackEvaluation.R Outdated Show resolved Hide resolved
R/ContextEvaluation.R Outdated Show resolved Hide resolved
R/ContextEvaluation.R Outdated Show resolved Hide resolved
R/ContextEvaluation.R Outdated Show resolved Hide resolved
R/as_result_data.R Outdated Show resolved Hide resolved
R/benchmark.R Outdated Show resolved Hide resolved
@be-marc
Copy link
Member Author

be-marc commented Dec 10, 2024

Looks good! I think we should also provide an example for how to implement a custom callback.

callback_evaluation() has an example now

R/CallbackEvaluation.R Outdated Show resolved Hide resolved
R/CallbackEvaluation.R Outdated Show resolved Hide resolved
tab = as.data.table(bmr, data_extra = TRUE)
expect_data_table(tab)
expect_names(names(tab), disjunct.from = "data_extra")
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any interesting cases where workhorse() is executed in a different (parallelization cluster) process that might be interesting here that should be tested?

R/CallbackEvaluation.R Outdated Show resolved Hide resolved
R/CallbackEvaluation.R Outdated Show resolved Hide resolved
R/ResultData.R Show resolved Hide resolved
R/ResultData.R Outdated Show resolved Hide resolved
@be-marc
Copy link
Member Author

be-marc commented Dec 11, 2024

Callbacks will behave differently depending on the parallelization.

  task = tsk("pima")
  learner = lrn("classif.rpart")
  resampling = rsmp("cv", folds = 3)

  callback = callback_evaluation("test",
    on_evaluation_begin = function(callback, context) {
      if (context$iteration == 1) context$task$select(c("age", "insulin"))
    }
  )

  rr = resample(task, learner, resampling, callbacks = callback)

  rr$learners[[1]]$state$feature_names
  # > [1] "age"     "insulin"
  rr$learners[[2]]$state$feature_names
  # > [1] "age"     "insulin"

  with_future("multisession", {
    rr = resample(task, learner, resampling, callbacks = callback)
  })

  rr$learners[[1]]$state$feature_names
  # > [1] "age"     "insulin"
  rr$learners[[2]]$state$feature_names
  # > [1] "age"      "glucose"  "insulin"  "mass"     "pedigree" "pregnant" "pressure" "triceps"

I think we should not clone these objects to get a consistent behavior. This will add unnecessary overhead. This is now documented in callback_evaluation().

@be-marc
Copy link
Member Author

be-marc commented Dec 19, 2024

Use cases:

  • Extract information from the model (without store_models = TRUE)
  • Score learner on additional set
  • Score HPCs on outer test set in nested resampling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants