mlr-org / mlr3book

Online version of Bischl, B., Sonabend, R., Kotthoff, L., & Lang, M. (Eds.). (2024). "Applied Machine Learning Using mlr3 in R". CRC Press.
https://mlr3book.mlr-org.com/
MIT License
252 stars 59 forks source link

Error in example of page26 #722

Closed fkgruber closed 1 year ago

fkgruber commented 1 year ago

Description

When I run

glrn_rf_tuned = as_learner(ppl("robustify") %>%
                           auto_tuner(
                             tnr("grid_search", resolution = 5),
                             lrn("classif.ranger",
                                 num.trees = to_tune(200, 500)),
                             rsmp("holdout")
                           ))

I get

Error in UseMethod("as_learner") : no applicable method for 'as_learner' applied to an object of class "c('TunerGridSearch', 'Tuner', 'R6')"

Reproducible example


library(tidyverse)
library(mlr3verse)
tasks = tsks(c("breast_cancer", "sonar"))

glrn_rf_tuned = as_learner(ppl("robustify") %>%
                           auto_tuner(
                             tnr("grid_search", resolution = 5),
                             lrn("classif.ranger",
                                 num.trees = to_tune(200, 500)),
                             rsmp("holdout")
                           ))

SessionInfo:

sessionInfo() R version 4.3.1 (2023-06-16) Platform: aarch64-apple-darwin22.4.0 (64-bit) Running under: macOS Ventura 13.2.1

Matrix products: default BLAS: /opt/homebrew/Cellar/openblas/0.3.23/lib/libopenblasp-r0.3.23.dylib LAPACK: /opt/homebrew/Cellar/r/4.3.1/lib/R/lib/libRlapack.dylib; LAPACK version 3.11.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Toronto tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] mlr3verse_0.2.8 mlr3_0.16.1 lubridate_1.9.2 forcats_1.0.0
[5] stringr_1.5.0 dplyr_1.1.2 purrr_1.0.1 readr_2.1.4
[9] tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0

loaded via a namespace (and not attached): [1] mlr3hyperband_0.4.5 gtable_0.3.3 mlr3data_0.7.0
[4] lattice_0.21-8 tzdb_0.3.0 vctrs_0.6.3
[7] tools_4.3.1 generics_0.1.3 stats4_4.3.1
[10] parallel_4.3.1 flexmix_2.3-19 fansi_1.0.4
[13] DEoptimR_1.0-11 cluster_2.1.4 pkgconfig_2.0.3
[16] data.table_1.14.9 checkmate_2.1.0 mlr3pipelines_0.5.0-1 [19] mlr3tuning_0.19.0 mlr3filters_0.7.1 uuid_1.1-0
[22] lifecycle_1.0.3 compiler_4.3.1 munsell_0.5.0
[25] codetools_0.2-19 clue_0.3-64 bbotk_0.7.2
[28] class_7.3-22 pillar_1.9.0 crayon_1.5.2
[31] mlr3tuningspaces_0.4.0 prabclus_2.3-2 MASS_7.3-60
[34] ellipsis_0.3.2 diptest_0.76-0 mlr3viz_0.6.1
[37] fpc_2.2-10 mlr3fselect_0.11.0 mclust_6.0.0
[40] parallelly_1.36.0 robustbase_0.95-0 mlr3mbo_0.2.1
[43] tidyselect_1.2.0 digest_0.6.33 stringi_1.7.12
[46] future_1.33.0 kernlab_0.9-32 listenv_0.9.0
[49] grid_4.3.1 colorspace_2.1-0 cli_3.6.1
[52] magrittr_2.0.3 paradox_0.11.1 utf8_1.2.3
[55] withr_2.5.0 scales_1.2.1 backports_1.4.1
[58] timechange_0.2.0 spacefillr_0.3.2 globals_0.16.2
[61] nnet_7.3-19 modeltools_0.2-23 hms_1.1.2
[64] mlr3cluster_0.1.8 mlr3misc_0.12.0 rlang_1.1.1
[67] Rcpp_1.0.11 glue_1.6.2 palmerpenguins_0.1.1
[70] lgr_0.4.4 R6_2.5.1 mlr3learners_0.5.6

larskotthoff commented 1 year ago

Thanks for the report -- looks like this is caused by ppl("robustify"). Some change in mlr3pipelines? @mb706

sebffischer commented 1 year ago

This was a typo in the book. It should be %>>% instead of %>%. I opened a PR to fix it here: https://github.com/mlr-org/mlr3book/pull/723