tune: Tune a survival learner over a hyperparameter grid

View source: R/verb-tune.R

tuneR Documentation

Tune a survival learner over a hyperparameter grid

Description

Grid search over resampling folds. Learners listed by listlearners(has_tune = TRUE) have a built-in default grid; any other learner, including a custom one (see fit()), is tuned over the grid you supply, with every configuration scored on the same splits. The best configuration is refit on the full data and returned as a ready-to-use survalis_fit.

Usage

tune(
  formula,
  data,
  model,
  grid = NULL,
  times = NULL,
  resampling = cv(),
  metric = "ibs",
  ncores = 1,
  ...
)

Arguments

formula

A survival formula.

data

A data frame.

model

A learner id (listlearners()$learner) or a custom learner.

grid

A data frame of hyperparameter combinations (one row per configuration, for example from expand.grid()). NULL uses the learner's built-in default grid, if it has one. A grid need not name every tuned parameter: parameters it leaves out take the learner's default values (those of fit() with no spec).

times

Evaluation grid; NULL picks one from the data quantiles.

resampling

A resampling spec. The built-in tuner uses cv() only (its v and seed drive the inner cross-validation). It runs when grid is NULL or has exactly the columns of the built-in grid; any other grid is scored on shared splits and accepts any spec.

metric

A single metric to optimise (default "ibs").

ncores

Cores for the inner CV (default 1).

...

Fixed learner arguments: forwarded to the built-in tuner, or added to every configuration of a supplied grid.

Value

A survalis_tune object: fit (the refit survalis_fit at the best configuration), results (the scored grid), best (one-row best config), times, resampling, metric, model.

Examples


tuned <- tune(Surv(time, status) ~ age + karno, veteran, "ranger",
              grid = expand.grid(num.trees = c(100, 300), mtry = 2, min.node.size = c(5, 15)),
              times = c(90, 180), resampling = cv(3), metric = "ibs")
tuned
predict(tuned, veteran[1:3, ], times = c(90, 180))


survalis documentation built on Nov. 14, 2026, 5:10 p.m.