Getting Started

fastgbm is a compact gradient boosting engine with a compiled (Rcpp + RcppParallel) backend, covering three task types with one interface: regression (squared error), binary classification (logistic), and right-censored survival analysis (Cox, AFT, or piecewise-exponential objectives), with native missing-value routing throughout. See vignette("regression"), vignette("classification"), and vignette("survival") for task-specific examples; this vignette walks through the survival interface end to end since it has the most moving parts (baseline hazard, survival-probability prediction).

Matrix interface

library(fastgbm)
library(survival)

lung_dat <- na.omit(lung[, c("time", "status", "age", "sex", "ph.ecog")])
x <- as.matrix(lung_dat[, c("age", "sex", "ph.ecog")])

fit <- fastgbm(
  x,
  time = lung_dat$time,
  status = lung_dat$status,
  objective = "cox",
  ntrees = 100L,
  learning_rate = 0.05,
  max_depth = 3L,
  seed = 1L,
  verbose = FALSE
)
fit
#> fastgbm model
#>   objective: cox 
#>   trees: 100 
#>   learning rate: 0.05 
#>   max depth: 3

Predictions

# Linear predictor (log relative risk)
lp <- predict(fit, x, type = "link")
head(lp)
#> [1] -0.1063293  0.2358925 -0.4168496  0.2601784 -0.3662904 -0.1063293

# Survival probabilities at specific horizons
predict(fit, x[1:5, ], type = "survival", times = c(90, 180, 365))
#>           [,1]      [,2]      [,3]
#> [1,] 0.9231172 0.7981076 0.4904070
#> [2,] 0.8934682 0.7279397 0.3666750
#> [3,] 0.9430419 0.8476267 0.5931407
#> [4,] 0.8909975 0.7222795 0.3577420
#> [5,] 0.9401782 0.8403910 0.5772898

Formula interface

fit2 <- fastgbm(Surv(time, status) ~ age + sex + ph.ecog, data = lung_dat, ntrees = 100L, verbose = FALSE)

Evaluation and importance

metrics(fit, y = Surv(lung_dat$time, lung_dat$status))
#> $objective
#> [1] "cox"
#> 
#> $metric
#> [1] "cindex"
#> 
#> $value
#> [1] 0.7095681
importance(fit)
#>   feature      gain
#> 1     age 285.02654
#> 3 ph.ecog 123.79429
#> 2     sex  63.53745

Partial dependence

pd <- pdp(fit, "age", data = as.data.frame(x), grid_resolution = 15)
plot(pd)