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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With