A Learner that encapsulates a Graph to be used in mlr3 resampling and benchmarks.

The Graph must return a single Prediction on its $predict() call. The result of the $train() call is discarded, only the internal state changes during training are used.

The predict_type of a GraphLearner can be obtained or set via it's predict_type active binding. Setting a new predict type will try to set the predict_type in all relevant PipeOp / Learner encapsulated within the Graph. Similarly, the predict_type of a Graph will always be the smallest denominator in the Graph.

## Format

R6Class object inheriting from mlr3::Learner.

## Construction

GraphLearner$new(graph, id = NULL, param_vals = list(), task_type = NULL, predict_type = NULL)  • graph :: Graph | PipeOp Graph to wrap. Can be a PipeOp, which is automatically converted to a Graph. This argument is always cloned; to access the Graph inside GraphLearner by-reference, use $graph.

• id :: character(1) Identifier of the resulting Learner.

• param_vals :: named list
List of hyperparameter settings, overwriting the hyperparameter settings . Default list().

• task_type :: character(1)
What task_type the GraphLearner should have; usually automatically inferred for Graphs that are simple enough.

• predict_type :: character(1)
What predict_type the GraphLearner should have; usually automatically inferred for Graphs that are simple enough.

## Fields

Fields inherited from PipeOp, as well as:

• graph :: Graph
Graph that is being wrapped. This field contains the prototype of the Graph that is being trained, but does not contain the model. Use graph_model to access the trained Graph after $train(). Read-only. • graph_model :: Learner Graph that is being wrapped. This Graph contains a trained state after $train(). Read-only.

## Internals

as_graph() is called on the graph argument, so it can technically also be a list of things, which is automatically converted to a Graph via gunion(); however, this will usually not result in a valid Graph that can work as a Learner. graph can furthermore be a Learner, which is then automatically wrapped in a Graph, which is then again wrapped in a GraphLearner object; this usually only adds overhead and is not recommended.

Other Learners: mlr_learners_avg

## Examples

library("mlr3")

graph = po("pca") %>>% lrn("classif.rpart")

lr = GraphLearner$new(graph) lr = as_learner(graph) # equivalent lr$train(tsk("iris"))

lr$graph$state  # untrained version!
#> $pca #> NULL #> #>$classif.rpart
#> NULL
#>
# The following is therefore NULL:
lr$graph$pipeops$classif.rpart$learner_model$model #> NULL # To access the trained model from the PipeOpLearner's Learner, use: lr$graph_model$pipeops$classif.rpart$learner_model$model
#> n= 150
#>
#> node), split, n, loss, yval, (yprob)
#>       * denotes terminal node
#>
#> 1) root 150 100 setosa (0.33333333 0.33333333 0.33333333)
#>   2) PC1< -1.553145 50   0 setosa (1.00000000 0.00000000 0.00000000) *
#>   3) PC1>=-1.553145 100  50 versicolor (0.00000000 0.50000000 0.50000000)
#>     6) PC1< 1.142805 44   1 versicolor (0.00000000 0.97727273 0.02272727) *
#>     7) PC1>=1.142805 56   7 virginica (0.00000000 0.12500000 0.87500000) *

# Feature importance (of principal components):
lr$graph_model$pipeops$classif.rpart$learner_model\$importance()
#>       PC1       PC2       PC3       PC4
#> 85.795455 18.016529  5.694731  3.254132