stack
Train multiple base learners and combine their predictions with a meta-learner. Cross-validated internally to prevent leakage between levels.
Signature
ml.stack(data, target, *, models=None, meta=None, cv_folds=5, seed, passthrough=False)
ml_stack(data, target, models = NULL, meta = NULL, cv_folds = 5L, seed = NULL)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | DataFrame | — | Training data |
target | str | — | Target column |
models | list | None | None | Base learner algorithm names. None = sensible defaults. |
meta | str | None | None | Meta-learner algorithm. Default: logistic (classification), linear (regression). |
cv_folds | int | 5 | CV folds for generating out-of-fold predictions |
seed | int | — | Random seed |
passthrough | bool | False | Include original features alongside base learner predictions (Python only) |
Returns
A Model (stacked ensemble). Use it like any other model — evaluate, assess, predict all work.
Examples
Default stack
model = ml.stack(s.train, "target", seed=42)
ml.evaluate(model, s.valid) model <- ml_stack(s$train, "target", seed = 42)
ml_evaluate(model, s$valid) Custom base learners
model = ml.stack(
s.train, "target",
models=["xgboost", "random_forest", "logistic"],
meta="logistic",
seed=42,
) model <- ml_stack(
s$train, "target",
models = c("xgboost", "random_forest", "logistic"),
meta = "logistic",
seed = 42
)