A layer holds one or more modelblueprint objects that run in parallel.
Each blueprint appends its prediction (under @yhat_name) to the dataset.
aggregate_fn then receives the enriched dataset and can add further derived
columns. yhat_name declares the layer's primary output column – this is
what predict() returns when return_all = FALSE, and what downstream
layers can reference as a feature.
Arguments
- blueprints
A list of
modelblueprintobjects. Every blueprint must have@yhat_nameset.- aggregate_fn
function(df) -> df. Receives the dataset after all blueprint predictions have been appended and returns it, optionally with additional columns. Defaults to the identity function whenblueprintshas one element; required when there are multiple blueprints.- yhat_name
[character(1)]The primary output column of this layer. Whenaggregate_fnisNULL, defaults to the single blueprint's@yhat_name. Whenaggregate_fnis provided, set this to the columnaggregate_fnadds that represents the layer's combined prediction.
See also
mb_seq() to combine layers into a pipeline.
Examples
if (FALSE) { # \dontrun{
# Single model -- aggregate_fn and yhat_name default to the blueprint's yhat_name
l1 <- mb_layer(list(mb_freq))
# Two models combined as a product
l2 <- mb_layer(
blueprints = list(mb_freq, mb_sev),
yhat_name = "pred_pure",
aggregate_fn = function(df) {
df[["pred_pure"]] <- df[["pred_freq"]] * df[["pred_sev"]]
df
}
)
} # }