This file contains hidden or 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
| # Benchamrk---- | |
| resample <- rsmp("cv", folds = 5) | |
| models <- benchmark_grid(task, learners, resample) | |
| bnchmrk <- benchmark(models) | |
| # Aggregate result | |
| measures <- msrs(c("surv.cindex", "surv.graf")) | |
| bnchmrk$aggregate(measures) | |
| bm <- fortify(bnchmrk) | |
| aggr <- bnchmrk$aggregate(measures) |
This file contains hidden or 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
| # Create learners---- | |
| learners <- lrns( | |
| paste0("surv.", c("coxtime","deephit", "deepsurv", "loghaz", "pchazard")), | |
| frac = 0.3, activation = "relu", | |
| dropout = 0.1, | |
| early_stopping = TRUE, | |
| epochs = 10, | |
| batch_size = 32L | |
| ) | |
| learners <- c(learners, lrns(c("surv.kaplan", "surv.coxph"))) |
This file contains hidden or 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
| task <- TaskSurv$new("patient_id", backend = df_clean, time = "time", event = "event", type = "right") | |
| task |
This file contains hidden or 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
| # Pre processing---- | |
| df <- df %>% select(-6) | |
| colnames(df)[c(4,5,6)] <- c("age", "begin", "disease") | |
| # Encoding the categorical feature---- | |
| library(caret) | |
| dmy <- dummyVars(" ~ .", data = df) | |
| df_clean <- data.frame(predict(dmy, newdata = df)) %>% select(-c(1,6)) | |
| head(df_clean) |
This file contains hidden or 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(1) | |
| df <- read_csv("Dialysis.csv") | |
| head(df) |
This file contains hidden or 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
| required_packages <- c("tidyverse", "survivalmodels", "mlr3benchmark", | |
| "mlr3pipelines", "mlr3proba", "mlr3tuning", "mlr3extralearners") | |
| install.packages(required_packages) |
This file contains hidden or 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
| # Read Dialysis dataset from SurvSet.data | |
| from SurvSet.data import SurvLoader | |
| loader = SurvLoader() | |
| df, ref = loader.load_dataset(ds_name='Dialysis').values() | |
| df.to_csv('Dialysis.csv', index=False) |
NewerOlder