mlr-org / mlr3pipelines

Dataflow Programming for Machine Learning in R
https://mlr3pipelines.mlr-org.com/
GNU Lesser General Public License v3.0
140 stars 25 forks source link

Unable to call functions from a pipeop in a graph #550

Closed henrifnk closed 2 months ago

henrifnk commented 3 years ago

If I construct a simple GraphLearner and train it like this

graph <- GraphLearner$new(po("scale") %>>% lrn("regr.ranger"))
mt <- tsk("mtcars")
graph$train(task = mt)

I am not able to call on the functions defined in the learner like

graph$oob_error()

nor do I have the possibility to call on the modell in a unified syntax like

graph$modell$oob.error

also the following does not work anymore because the learner inside the graph is not trained

graph$graph$pipeops[["regr.ranger"]]$learner$oob.error()

you would have to call instead:

graph$state$model$regr.ranger$model$prediction.error

I'm asking this because it makes it hard to implement gerneric solutions for such workflows and it makes it impossible to call on the measure if you have a prediction:

prediction <- graph$predict(task = mt)
prediction$score(msr("oob_error"))

Is there already a solution existing, which i am not aware of?

mb706 commented 2 months ago

By now, we have the $base_learner() function for GraphLearner, which gives access to the learner at the end of the Graph.

graph$base_learner()$model
graph$base_learner()$oob_error()
prediction$score(msr("oob_error"), learner = graph$base_learner())