Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging / checking steps in mlr pipeops

Tags:

mlr3

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?

like image 268
ds_col Avatar asked May 12 '26 01:05

ds_col


1 Answers

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
like image 101
mb706 Avatar answered May 17 '26 15:05

mb706