| mlr_learners_graph {mlr3pipelines} | R Documentation |
Encapsulate a Graph as a Learner
Description
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.
A GraphLearner is always constructed in an untrained state. When the graph argument has a
non-NULL $state, it is ignored.
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
Graphto wrap. Can be aPipeOp, which is automatically converted to aGraph. This argument is usually cloned, unlessclone_graphisFALSE; to access theGraphinsideGraphLearnerby-reference, use$graph.
-
id::character(1)Identifier of the resultingLearner. -
param_vals:: namedlist
List of hyperparameter settings, overwriting the hyperparameter settings . Defaultlist(). -
task_type::character(1)
Whattask_typetheGraphLearnershould have; usually automatically inferred forGraphs that are simple enough. -
predict_type::character(1)
Whatpredict_typetheGraphLearnershould have; usually automatically inferred forGraphs that are simple enough. -
clone_graph::logical(1)
Whether to clonegraphupon construction. Unintentionally changinggraphby reference can lead to unexpected behaviour, soTRUE(default) is recommended. In particular, note that the$stateof$graphis set toNULLby reference on construction ofGraphLearner, during$train(), and during$predict()whenclone_graphisFALSE.
Fields
Fields inherited from PipeOp, as well as:
-
graph::Graph
Graphthat is being wrapped. This field contains the prototype of theGraphthat is being trained, but does not contain the model. Usegraph_modelto access the trainedGraphafter$train(). Read-only. -
graph_model::Learner
Graphthat is being wrapped. ThisGraphcontains a trained state after$train(). Read-only. -
internal_tuned_values:: namedlist()orNULL
The internal tuned parameter values collected from allPipeOps.NULLis returned if the learner is not trained or none of the wrapped learners supports internal tuning. -
internal_valid_scores:: namedlist()orNULL
The internal validation scores as retrieved from thePipeOps. The names are prefixed with the respective IDs of thePipeOps.NULLis returned if the learner is not trained or none of the wrapped learners supports internal validation. -
validate::numeric(1),"predefined","test"orNULL
How to construct the validation data. This also has to be configured for the individualPipeOps such asPipeOpLearner, seeset_validate.GraphLearner. For more details on the possible values, seemlr3::Learner. -
marshaled::logical(1)
Whether the learner is marshaled.
Methods
-
marshal(...)
(any) ->self
Marshal the model. -
unmarshal(...)
(any) ->self
Unmarshal the model.
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.
See Also
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!
# The following is therefore NULL:
lr$graph$pipeops$classif.rpart$learner_model$model
# To access the trained model from the PipeOpLearner's Learner, use:
lr$graph_model$pipeops$classif.rpart$learner_model$model
# Feature importance (of principal components):
lr$graph_model$pipeops$classif.rpart$learner_model$importance()