Skip to content

Code error in Section 12.5.1 mlr::resample #1166

@dustin-duncan

Description

@dustin-duncan

Hello, I am currently running through the code in the book and receiving the following error when running mlr::resample(task = task, learner = learner, resampling = resampling ) :

Error in if (!is.null(resampling$task_row_hash) && resampling$task_row_hash != : missing value where TRUE/FALSE needed

I am not sure where the issue is arising, but it doesn't appear that resampling$task_row_hash is storing properly.

Here is the code I've run (from the book) that is generating the error, as well as some outputs for troubleshooting under the "Check for expected values from troubleshooting". Note that I ran just the book code to start, which generated the same error.

# 1. create task
task = mlr3spatiotempcv::as_task_classif_st(
  mlr3::as_data_backend(lsl),
  target = "lslpts",
  id = "ecuador_lsl",
  positive = "TRUE",
  coordinate_names = c("x", "y"),
  crs = "EPSG:32717",
  coords_as_features = FALSE
  )

# 2. Set up learner 
learner = mlr3::lrn("classif.log_reg", predict_type = "prob")

# 3. Set up resampling
resampling = mlr3::rsmp("repeated_spcv_coords", folds = 5, repeats = 100)

# Check for expected values between resampling and task 
task$row_ids # 1-350
resampling$is_instantiated # [1] FALSE
resampling$instantiate(task)
resampling$is_instantiated # [1] TRUE 
task$hash # [1] "48ec36253896ff33"
resampling$task_hash # [1] "48ec36253896ff33"
resampling$task_hash == task$hash # [1] TRUE
task$row_hash # [1] "8ce098287dbf2050"
resampling$task_row_hash # NA 
resampling$task_nrow # 350 
resampling$task_row_hash == task$row_hash # NA 

# reduce verbosity
lgr::get_logger("mlr3")$set_threshold("warn")

# Now run resampling
rr_spcv_glm = mlr3::resample(
  task = task,
  learner = learner,
  resampling = resampling)

It appears that the resampling$task_row_hash is not inheriting from task. Any help would be appreciated!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions