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
- clone
(
logical(1))
Whether to deep clonexbefore wrapping it. IfFALSE(default),xis wrapped by reference, so changes tox, such as new hyperparameter values, also affect the resultingGraphLearner, and vice versa. Furthermore, ifxis trained, its$stateis reset by reference during conversion, as well as whenever theGraphLearneris trained or used for prediction. IfTRUE,xis left unchanged.- discard_state
(
logical(1))
Exists for compatibility with theas_learner()method forLearners, whichresample()relies on. Has no effect, since the resultingGraphLearneris always untrained, even ifxis trained.- ...
(any)
Foras_learner.PipeOp(), passed on toas_learner.Graph(). Foras_learner.Graph(), must be empty.- id
(
character(1)|NULL)
Identifier of the resultingGraphLearner. IfNULL(default), the IDs of thePipeOps inxare concatenated.- param_vals
(named
list())
Hyperparameter settings of the resultingGraphLearner. Defaultlist().- task_type
(
character(1)|NULL)
Task type of the resultingGraphLearner. IfNULL(default), it is inferred fromx.- predict_type
(
character(1)|NULL)
Predict type of the resultingGraphLearner. IfNULL(default), it is inferred fromx.
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
mlr_learners_graph for details on GraphLearner.
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
