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

Example for PipeOpDropNA in section 6.3.2.1 isn't working #173

Closed andreassot10 closed 3 years ago

andreassot10 commented 4 years ago

I have been unable to reproduce the example for PipeOpDropNA in section 6.3.2.1 of the mlr3 book:

PipeOpDropNA = R6::R6Class("PipeOpDropNA",
  inherit = mlr3pipelines::PipeOpTaskPreproc,
  public = list(
    initialize = function(id = "drop.na") {
      super$initialize(id)
    },

    train_task = function(task) {
      self$state = list()
      featuredata = task$data(cols = task$feature_names)
      exclude = apply(is.na(featuredata), 1, any)
      task$filter(task$row_ids[!exclude])
    },

    predict_task = function(task) {
      # nothing to be done
      task
    }
  )
)

smalliris = iris[(1:5) * 30, ]
smalliris[1, 1] = NA
smalliris[2, 2] = NA
sitask = TaskClassif$new("smalliris", as_data_backend(smalliris), "Species")
print(sitask$data())

gr = Graph$new()
gr$add_pipeop(PipeOpDropNA$new())

filtered_task = gr$train(sitask)[[1]]

#Error in private$.train_dt(dt, task_levels(task, cols), target) : 
#  Abstract.

traceback()

#8: stop("Abstract.")
#7: private$.train_dt(dt, task_levels(task, cols), target)
#6: as.data.table(private$.train_dt(dt, task_levels(task, cols), 
#       target))
#5: private$.train_task(intask)
#4: private$.train(input)
#3: op[[fun]](input)
#2: graph_reduce(self, input, "train", single_input)
#1: gr$train(sitask)

Session info:

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
 [1] mlr3viz_0.1.1.9002       mlr3tuning_0.1.2-9000   
 [3] mlr3pipelines_0.1.3.9000 mlr3misc_0.2.0          
 [5] mlr3learners_0.2.0.9001  mlr3filters_0.2.0.9000  
 [7] mlr3_0.2.0-9000          paradox_0.2.0           
 [9] yardstick_0.0.5          rsample_0.0.5           
[11] recipes_0.1.9            parsnip_0.0.5           
[13] infer_0.5.1              dials_0.0.4             
[15] scales_1.1.0             broom_0.5.4             
[17] tidymodels_0.0.3         reshape2_1.4.3          
[19] janitor_1.2.1            data.table_1.12.8       
[21] forcats_0.4.0            stringr_1.4.0           
[23] dplyr_1.0.0              purrr_0.3.3             
[25] readr_1.3.1              tidyr_1.0.2             
[27] tibble_3.0.1             ggplot2_3.3.0           
[29] tidyverse_1.3.0         

loaded via a namespace (and not attached):
  [1] uuid_0.1-4           readxl_1.3.1         backports_1.1.7     
  [4] tidytext_0.2.2       workflows_0.1.1      plyr_1.8.5          
  [7] igraph_1.2.4.2       splines_3.6.2        crosstalk_1.0.0     
 [10] listenv_0.8.0        SnowballC_0.6.0      rstantools_2.0.0    
 [13] inline_0.3.15        digest_0.6.25        foreach_1.4.7       
 [16] htmltools_0.4.0      rsconnect_0.8.16     fansi_0.4.1         
 [19] checkmate_2.0.0      magrittr_1.5         globals_0.12.5      
 [22] modelr_0.1.5         gower_0.2.1          matrixStats_0.55.0  
 [25] xts_0.12-0           prettyunits_1.1.1    colorspace_1.4-1    
 [28] rvest_0.3.5          xfun_0.12            haven_2.2.0         
 [31] callr_3.4.1          crayon_1.3.4         jsonlite_1.6.1      
 [34] lme4_1.1-21          survival_3.1-8       zoo_1.8-7           
 [37] iterators_1.0.12     glue_1.4.0           gtable_0.3.0        
 [40] ipred_0.9-9          pkgbuild_1.0.6       rstan_2.19.2        
 [43] DBI_1.1.0            miniUI_0.1.1.1       Rcpp_1.0.4.6        
 [46] xtable_1.8-4         GPfit_1.0-8          stats4_3.6.2        
 [49] lava_1.6.6           StanHeaders_2.21.0-1 prodlim_2019.11.13  
 [52] DT_0.12              htmlwidgets_1.5.1    httr_1.4.1          
 [55] threejs_0.3.3        ellipsis_0.3.0       pkgconfig_2.0.3     
 [58] loo_2.2.0            nnet_7.3-12          dbplyr_1.4.2        
 [61] tidyselect_1.1.0     rlang_0.4.6          DiceDesign_1.8-1    
 [64] later_1.0.0          munsell_0.5.0        cellranger_1.1.0    
 [67] tools_3.6.2          cli_2.0.1            generics_0.0.2      
 [70] ggridges_0.5.2       fastmap_1.0.1        knitr_1.28          
 [73] processx_3.4.1       fs_1.3.1             lgr_0.3.4           
 [76] packrat_0.5.0        bbotk_0.1            future_1.17.0       
 [79] nlme_3.1-142         mime_0.8             rstanarm_2.19.2     
 [82] xml2_1.2.2           tokenizers_0.2.1     compiler_3.6.2      
 [85] bayesplot_1.7.1      shinythemes_1.1.2    rstudioapi_0.10     
 [88] reprex_0.3.0         tidyposterior_0.0.2  lhs_1.0.1           
 [91] stringi_1.4.4        ps_1.3.0             lattice_0.20-38     
 [94] Matrix_1.2-18        nloptr_1.2.1         markdown_1.1        
 [97] shinyjs_1.1          vctrs_0.3.1          pillar_1.4.3        
[100] lifecycle_0.2.0      furrr_0.1.0          httpuv_1.5.2        
[103] R6_2.4.1             promises_1.1.0       gridExtra_2.3       
[106] janeaustenr_0.1.5    codetools_0.2-16     boot_1.3-23         
[109] colourpicker_1.0     MASS_7.3-51.4        gtools_3.8.1        
[112] assertthat_0.2.1     withr_2.2.0          shinystan_2.5.0     
[115] parallel_3.6.2       hms_0.5.3            grid_3.6.2          
[118] rpart_4.1-15         timeDate_3043.102    class_7.3-15        
[121] minqa_1.2.4          snakecase_0.11.0     pROC_1.16.1         
[124] tidypredict_0.4.3    shiny_1.4.0          lubridate_1.7.4     
[127] base64enc_0.1-3      dygraphs_1.1.1.6
pfistfl commented 3 years ago

Should be fixed by now, reason was change in pipelines to . prefix for private functions that had not been updated here.