survival_estimator
survival_estimator
¶
sklearn-compatible survival estimator for ngboost-lightning.
LightningBoostSurvival
¶
LightningBoostSurvival(
dist: type[Distribution] = LogNormal,
n_estimators: int = 500,
learning_rate: float = 0.01,
minibatch_frac: float = 1.0,
col_sample: float = 1.0,
natural_gradient: bool = True,
tol: float = 0.0001,
random_state: int | None = None,
verbose: bool = True,
verbose_eval: int = 100,
num_leaves: int = 31,
max_depth: int = -1,
min_child_samples: int = 20,
subsample: float = 1.0,
colsample_bytree: float = 1.0,
reg_alpha: float = 0.0,
reg_lambda: float = 0.0,
lgbm_params: dict[str, Any] | None = None,
validation_fraction: float | None = None,
)
Bases: BaseEstimator
Natural gradient boosting for survival analysis with right censoring.
Outputs full probability distributions over survival times by boosting the parameters of a conditional distribution using the natural gradient of the censored log-likelihood.
Supports right-censored observations: uncensored samples contribute
-logpdf(T) to the loss while censored samples contribute
-logsf(T) = -log(1 - CDF(T)).
The distribution must implement logsf(y) (Exponential, LogNormal,
and Weibull support this).
| PARAMETER | DESCRIPTION |
|---|---|
dist
|
Distribution class to use. Must support
TYPE:
|
n_estimators
|
Number of boosting iterations.
TYPE:
|
learning_rate
|
Outer learning rate applied to each boosting step.
TYPE:
|
minibatch_frac
|
Fraction of training rows to subsample each iteration for gradient computation. 1.0 means no subsampling.
TYPE:
|
col_sample
|
Fraction of columns to subsample each boosting iteration. 1.0 means no column subsampling. All K parameter-boosters see the same feature subset each iteration.
TYPE:
|
natural_gradient
|
Whether to use the natural gradient.
TYPE:
|
tol
|
Convergence tolerance.
TYPE:
|
random_state
|
Seed for reproducibility.
TYPE:
|
verbose
|
Whether to log training progress.
TYPE:
|
verbose_eval
|
Log progress every this many iterations.
TYPE:
|
num_leaves
|
Maximum number of leaves per tree.
TYPE:
|
max_depth
|
Maximum tree depth. -1 means no limit.
TYPE:
|
min_child_samples
|
Minimum number of samples in a leaf.
TYPE:
|
subsample
|
LightGBM-level row subsampling ratio per tree.
TYPE:
|
colsample_bytree
|
Column subsampling ratio per tree.
TYPE:
|
reg_alpha
|
L1 regularization on leaf weights.
TYPE:
|
reg_lambda
|
L2 regularization on leaf weights.
TYPE:
|
lgbm_params
|
Additional parameters passed to each LightGBM Booster.
TYPE:
|
validation_fraction
|
Fraction of training data to hold out for
early stopping. Defaults to
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
engine_ |
The fitted
|
n_features_in_ |
Number of features seen during
|
n_estimators_ |
Actual number of boosting iterations.
|
Examples:
>>> from ngboost_lightning import LightningBoostSurvival
>>> surv = LightningBoostSurvival(n_estimators=100, learning_rate=0.05)
>>> surv.fit(X_train, T_train, E_train)
>>> median_times = surv.predict(X_test)
>>> dist = surv.pred_dist(X_test)
Initialize the survival estimator. See class docstring for params.
Source code in ngboost_lightning/survival_estimator.py
feature_importances_
property
¶
Feature importances per distribution parameter.
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Importance array, shape |
fit
¶
fit(
X: NDArray[floating],
T: NDArray[floating],
E: NDArray[integer] | NDArray[bool_],
X_val: NDArray[floating] | None = None,
T_val: NDArray[floating] | None = None,
E_val: NDArray[integer] | NDArray[bool_] | None = None,
early_stopping_rounds: int | None = None,
sample_weight: NDArray[floating] | None = None,
val_sample_weight: NDArray[floating] | None = None,
train_loss_monitor: Callable[
[Distribution, NDArray[floating]], float
]
| None = None,
val_loss_monitor: Callable[
[Distribution, NDArray[floating]], float
]
| None = None,
) -> Self
Fit the survival model on right-censored data.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Training features, shape
TYPE:
|
T
|
Times to event or censoring, shape
TYPE:
|
E
|
Event indicators, shape
TYPE:
|
X_val
|
Validation features for early stopping.
TYPE:
|
T_val
|
Validation times for early stopping.
TYPE:
|
E_val
|
Validation event indicators for early stopping.
TYPE:
|
early_stopping_rounds
|
Stop if validation loss hasn't improved for this many consecutive iterations.
TYPE:
|
sample_weight
|
Per-sample training weights, shape
TYPE:
|
val_sample_weight
|
Per-sample validation weights.
TYPE:
|
train_loss_monitor
|
Custom callable for computing training loss.
Signature:
TYPE:
|
val_loss_monitor
|
Custom callable for computing validation loss.
Signature:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The fitted estimator. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If both |
Source code in ngboost_lightning/survival_estimator.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
predict
¶
Predict median survival time.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Features, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Median survival times, shape |
Source code in ngboost_lightning/survival_estimator.py
pred_dist
¶
pred_dist(X: NDArray[floating]) -> Distribution
Predict the full conditional survival distribution.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Features, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Distribution
|
A Distribution instance for all samples. |
Source code in ngboost_lightning/survival_estimator.py
staged_predict
¶
Yield median survival times after each boosting iteration.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Features, shape
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
Generator[NDArray[floating]]
|
Median survival times at iteration i, shape |
Source code in ngboost_lightning/survival_estimator.py
staged_pred_dist
¶
staged_pred_dist(
X: NDArray[floating],
) -> Generator[Distribution]
Yield the full conditional distribution after each iteration.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Features, shape
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
Generator[Distribution]
|
Distribution at iteration i. |
Source code in ngboost_lightning/survival_estimator.py
score
¶
Negative mean censored NLL (higher is better).
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Features, shape
TYPE:
|
T
|
Times to event or censoring, shape
TYPE:
|
E
|
Event indicators, shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
|