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()).NULLuses the learner's built-in default grid, if it has one. Agridneed not name every tuned parameter: parameters it leaves out take the learner's default values (those offit()with nospec).- times
Evaluation grid;
NULLpicks one from the data quantiles.- resampling
A resampling spec. The built-in tuner uses
cv()only (itsvandseeddrive the inner cross-validation). It runs whengridisNULLor has exactly the columns of the built-in grid; any othergridis 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
#> <survalis_tune> model = ranger | optimise ibs over 4 configs
#> <survalis_resampling> 3-fold CV, strata = status
#> best: num.trees = 100, mtry = 2, min.node.size = 15
#> ibs at best: 0.2016
predict(tuned, veteran[1:3, ], times = c(90, 180))
#> <survmat> survival | 3 obs x 2 times [90, 180]
#> t=90 t=180
#> [1,] 0.3742667 0.1699102
#> [2,] 0.8498103 0.3458225
#> [3,] 0.5941357 0.3412420