Skip to contents

Methods for as_learner() that wrap a Graph or a PipeOp in a GraphLearner. A PipeOp is first converted to a Graph using as_graph().

Usage

# S3 method for class 'Graph'
as_learner(
  x,
  clone = FALSE,
  discard_state = FALSE,
  ...,
  id = NULL,
  param_vals = list(),
  task_type = NULL,
  predict_type = NULL
)

# S3 method for class 'PipeOp'
as_learner(x, clone = FALSE, ...)

Arguments

x

(Graph | PipeOp)
Object to convert.

clone

(logical(1))
Whether to deep clone x before wrapping it. If FALSE (default), x is wrapped by reference, so changes to x, such as new hyperparameter values, also affect the resulting GraphLearner, and vice versa. Furthermore, if x is trained, its $state is reset by reference during conversion, as well as whenever the GraphLearner is trained or used for prediction. If TRUE, x is left unchanged.

discard_state

(logical(1))
Exists for compatibility with the as_learner() method for Learners, which resample() relies on. Has no effect, since the resulting GraphLearner is always untrained, even if x is trained.

...

(any)
For as_learner.PipeOp(), passed on to as_learner.Graph(). For as_learner.Graph(), must be empty.

id

(character(1) | NULL)
Identifier of the resulting GraphLearner. If NULL (default), the IDs of the PipeOps in x are concatenated.

param_vals

(named list())
Hyperparameter settings of the resulting GraphLearner. Default list().

task_type

(character(1) | NULL)
Task type of the resulting GraphLearner. If NULL (default), it is inferred from x.

predict_type

(character(1) | NULL)
Predict type of the resulting GraphLearner. If NULL (default), it is inferred from x.

Value

GraphLearner

Internals

The arguments id, param_vals, task_type, and predict_type are passed on to the GraphLearner constructor. Unknown arguments raise an error.

See also

Examples

library("mlr3")

graph = po("pca") %>>% lrn("classif.rpart")
learner = as_learner(graph, id = "pca_rpart", param_vals = list(classif.rpart.cp = 0.1))
learner$id
#> [1] "pca_rpart"
learner$param_set$values$classif.rpart.cp
#> [1] 0.1

# x is wrapped by reference, unless clone is TRUE
identical(learner$graph, graph)
#> [1] TRUE
identical(as_learner(graph, clone = TRUE)$graph, graph)
#> [1] FALSE