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.3642202  0.0220805 -0.5888462  0.1127854 -0.5590241 -0.3642202

# Survival probabilities at specific horizons
predict(fit, x[1:5, ], type = "survival", times = c(90, 180, 365))
#>           [,1]      [,2]      [,3]
#> [1,] 0.9355729 0.8310152 0.5660436
#> [2,] 0.9066507 0.7615570 0.4328246
#> [3,] 0.9481922 0.8625464 0.6347063
#> [4,] 0.8982538 0.7421139 0.3997434
#> [5,] 0.9466665 0.8586941 0.6260319

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.6844847
importance(fit)
#>   feature     gain
#> 1     age 277.8700
#> 3 ph.ecog 107.0573
#> 2     sex   0.0000

Partial dependence

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