3

I would like to check intermediate steps in a calculation, but I could not figure out how to do this.

Example from the book:

mutate = mlr_pipeops$get("mutate")
filter = mlr_pipeops$get("filter",
  filter = mlr3filters::FilterVariance$new(),
  param_vals = list(filter.frac = 0.5))

graph = mutate %>>%
  filter %>>%
  mlr_pipeops$get("learner",
    learner = mlr_learners$get("classif.rpart"))

graph$keep_results=TRUE

task = mlr_tasks$get("iris")
graph$train(task)

Now, I would like to see the transformed data matrix of the task (after mutate and filter). This must be somewhere in graph, especially as I did set keep_results=TRUE . But I cannot see where. Can anyone help me here?

ds_col
  • 129
  • 10

1 Answers1

4

Setting keep_results=TRUE is the right start. When you set it, then the results of each PipeOp's computation are stored in the PipeOp's $.result slot. The result is a list, because a PipeOp could have multiple result objects, but for most preprocessing operation this has only one member ($output) and is just a Task that can be inspected:

# your code
graph$train(task)
#> $classif.rpart.output
#> NULL
#>

# E.g. the result of the "variance" filter:

graph$pipeops$variance$.result
#> $output
#> <TaskClassif:iris> (150 x 3)
#> * Target: Species
#> * Properties: multiclass
#> * Features (2):
#>   - dbl (2): Petal.Length, Sepal.Length

# $output is a Task, so the data can e.g. be seen with $data():

graph$pipeops$variance$.result$output$data()
#>        Species Petal.Length Sepal.Length
#>   1:    setosa          1.4          5.1
#>   2:    setosa          1.4          4.9
#>   3:    setosa          1.3          4.7
#>   4:    setosa          1.5          4.6
#>   5:    setosa          1.4          5.0
#>  ---                                    
#> 146: virginica          5.2          6.7
#> 147: virginica          5.0          6.3
#> 148: virginica          5.2          6.5
#> 149: virginica          5.4          6.2
#> 150: virginica          5.1          5.9
mb706
  • 652
  • 3
  • 5
  • How might one inspect warning messages, e.g. "In addition: Warning message: Number of logged events: 26 This happened PipeOp XXX's $train()"? – Alex Jul 12 '22 at 10:02