This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set_seed(1234) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mlr3) | |
library(mlr3proba) | |
## get the `whas` task from mlr3proba | |
whas <- tsk("whas") | |
## create our own task from the rats dataset | |
rats_data <- survival::rats | |
## convert characters to factors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mlr3pipelines) | |
create_pipeops <- function(learner) { | |
po("encode") %>>% po("scale") %>>% po("learner", learner) | |
} | |
## apply our function | |
learners <- lapply(learners, create_pipeops) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(survivalmodels) | |
install_pycox(pip = TRUE, install_torch = TRUE) | |
install_keras(pip = TRUE, install_tensorflow = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## load ggplot2 for autoplots | |
library(ggplot2) | |
## critical difference diagrams for IGS | |
autoplot(bma, meas = "graf", type = "cd", ratio = 1/3, p.value = 0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mlr3tuning) | |
create_autotuner <- function(learner) { | |
AutoTuner$new( | |
learner = learner, | |
search_space = search_space, | |
resampling = rsmp("holdout"), | |
measure = msr("surv.cindex"), | |
terminator = trm("evals", n_evals = 2), | |
tuner = tnr("random_search") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(paradox) | |
search_space <- ps( | |
## p_dbl for numeric valued parameters | |
dropout = p_dbl(lower = 0, upper = 1), | |
weight_decay = p_dbl(lower = 0, upper = 0.5), | |
learning_rate = p_dbl(lower = 0, upper = 1), | |
## p_int for integer valued parameters | |
nodes = p_int(lower = 1, upper = 32), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## learners are stored in mlr3extralearners | |
library(mlr3extralearners) | |
## load learners | |
learners <- lrns( | |
paste0("surv.", c("coxtime", "deephit", "deepsurv", "loghaz", "pchazard")), | |
frac = 0.3, early_stopping = TRUE, epochs = 10, optimizer = "adam" | |
) | |
# apply our function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mlr3benchmark) | |
## create mlr3benchmark object | |
bma <- as.BenchmarkAggr(bm) | |
## run global Friedman test | |
bma$friedman_test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`%=%` <- function(l, r) { | |
l <- trimws(strsplit(l, ",", TRUE)[[1]]) | |
if (all(l == "USE.NAMES") || all(l == "*") || all(l == "?")) { | |
stopifnot(length(names(r)) > 0) | |
l <- names(r) | |
} else { | |
stopifnot(identical(length(l), length(r))) | |
which <- l == "?" | |
if (any(which)) { | |
stopifnot(length(names(r)) > 0) |
OlderNewer