tempor.methods.time_to_event.plugin_ts_xgb module

XGB survival analysis model with Dynamic DeepHit embeddings.

tempor.methods.time_to_event.plugin_ts_xgb.monkeypatch_xgbse_xgboost2_compatibility() Generator[source]

There is a bug that occurs in xgbse with xgboost 2.0+.

AttributeError: `best_iteration` is only defined when early stopping is used. will be thrown when early_stopping_rounds parameter has not been set.

This monkeypatch fixes this issue, until the problem is addressed by xgbse in a future version.

class tempor.methods.time_to_event.plugin_ts_xgb.XGBTimeToEventAnalysisParams(xgb_n_estimators: int = 100, xgb_colsample_bynode: float = 1.0, xgb_colsample_bytree: float = 1.0, xgb_colsample_bylevel: float = 1.0, xgb_max_depth: int = 5, xgb_subsample: float = 0.5, xgb_learning_rate: float = 0.05, xgb_min_child_weight: int = 50, xgb_tree_method: str = 'hist', xgb_booster: int = 0, xgb_objective: 'aft' | 'cox' = 'aft', xgb_strategy: 'weibull' | 'debiased_bce' | 'km' = 'debiased_bce', xgb_bce_n_iter: int = 1000, xgb_time_points: int = 100, xgb_reg_lambda: float = 1, xgb_reg_alpha: float = 0, n_iter: int = 1000, batch_size: int = 100, lr: float = 0.001, n_layers_hidden: int = 1, n_units_hidden: int = 40, split: int = 100, rnn_mode: 'GRU' | 'LSTM' | 'RNN' | 'Transformer' = 'GRU', alpha: float = 0.34, beta: float = 0.27, sigma: float = 0.21, dropout: float = 0.06, device: str = 'cpu', val_size: float = 0.1, patience: int = 20, output_mode: 'MLP' | 'LSTM' | 'GRU' | 'RNN' | 'Transformer' | 'TCN' | 'InceptionTime' | 'InceptionTimePlus' | 'ResCNN' | 'XCM' = 'MLP', random_state: int = 0)[source]

Bases: object

xgb_n_estimators : int = 100

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_colsample_bynode : float = 1.0

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_colsample_bytree : float = 1.0

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_colsample_bylevel : float = 1.0

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_max_depth : int = 5

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_subsample : float = 0.5

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_learning_rate : float = 0.05

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_min_child_weight : int = 50

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_tree_method : str = 'hist'

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_booster : int = 0

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_objective : Literal[aft] | Literal[cox] = 'aft'

XGB Objective, one of XGBObjective.

xgb_strategy : Literal[weibull] | Literal[debiased_bce] | Literal[km] = 'debiased_bce'

XGB Objective, one of XGBStrategy: weibull: XGBSEStackedWeibull, debiased_bce: XGBSEDebiasedBCE, km: XGBSEKaplanNeighbors.

xgb_bce_n_iter : int = 1000

Parameter for xgbse XGBSEDebiasedBCE initializer lr_params.max_iter.

xgb_time_points : int = 100

Number of discrete time points to use.

xgb_reg_lambda : float = 1

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

xgb_reg_alpha : float = 0

Respective parameter for xgbse XGBSE<Method> class initializer xgb_params.

n_iter : int = 1000

Number of training epochs.

batch_size : int = 100

Training batch size.

lr : float = 0.001

Training learning rate.

n_layers_hidden : int = 1

Number of hidden layers in the network.

n_units_hidden : int = 40

Number of units for each hidden layer.

split : int = 100

Number of discrete buckets.

rnn_mode : Literal[GRU] | Literal[LSTM] | Literal[RNN] | Literal[Transformer] = 'GRU'

Internal temporal architecture, one of RnnMode.

alpha : float = 0.34

Weighting (0, 1) likelihood and rank loss (L2 in paper). 1 gives only likelihood, and 0 gives only rank loss.

beta : float = 0.27

Beta, see paper.

sigma : float = 0.21

From eta in rank loss (L2 in paper).

dropout : float = 0.06

Network dropout value.

device : str = 'cpu'

PyTorch Device.

val_size : float = 0.1

size of validation set.

Type:

Early stopping (embeddings training)

patience : int = 20

training patience without any improvement.

Type:

Early stopping (embeddings training)

output_mode : Literal[MLP] | Literal[LSTM] | Literal[GRU] | Literal[RNN] | Literal[Transformer] | Literal[TCN] | Literal[InceptionTime] | Literal[InceptionTimePlus] | Literal[ResCNN] | Literal[XCM] = 'MLP'

Output network, on of OutputMode.

random_state : int = 0

Random seed.

class tempor.methods.time_to_event.plugin_ts_xgb.XGBSurvivalAnalysis(n_estimators: int = 100, colsample_bynode: float = 1, colsample_bylevel: float = 1, colsample_bytree: float = 1, max_depth: int = 5, subsample: float = 0.5, learning_rate: float = 0.05, min_child_weight: int = 50, reg_lambda: float = 1.0, reg_alpha: float = 0.0, tree_method: str = 'hist', booster: int = 0, random_state: int = 0, objective: Literal[aft] | Literal[cox] = 'aft', strategy: Literal[weibull] | Literal[debiased_bce] | Literal[km] = 'debiased_bce', bce_n_iter: int = 1000, time_points: int = 100, **kwargs: Any)[source]

Bases: OutputTimeToEventAnalysis

XGB survival analysis model.

Parameters:
n_estimators : int, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 100.

colsample_bynode : float, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 1.

colsample_bylevel : float, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 1.

colsample_bytree : float, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 1.

max_depth : int, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 5.

subsample : float, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 0.5.

learning_rate : float, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 5e-2.

min_child_weight : int, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 50.

reg_lambda : float, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 1.

reg_alpha : float, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 0.

tree_method : str, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to "hist".

booster : int, optional

Passed as the corresponding parameter in xgb_params to the xgbse model as XGBSurvivalAnalysis.booster[booster]. Defaults to 0.

random_state : int, optional

Passed as the corresponding parameter in xgb_params to the xgbse model. Defaults to 0.

objective : XGBObjective, optional

"aft" or "cox". Chooses whether to use survival:aft or survival:cox as xgbse model’s "objective" parameter. Each case has some corresponding default parameters, see source code. Defaults to "aft".

strategy : XGBStrategy, optional

One of "debiased_bce", "weibull", or "km", chooses the corresponding xgbse model. Defaults to "debiased_bce".

bce_n_iter : int, optional

Passed as the "max_iter" parameter in lr_params of the XGBSEDebiasedBCE model, only relevant to the "debiased_bce" case. Defaults to 1000.

time_points : int, optional

Number of timepoints for time binning. Defaults to 100.

**kwargs : Any

Additional parameters to be passed to the xgbse model (in xgb_params).

Raises:

ValueError – _description_

booster = ['gbtree', 'gblinear', 'dart']
fit(X: DataFrame, T: Series, Y: Series) Self[source]

Fit the model.

Parameters:
X : pd.DataFrame

Input covariates of fixed shape - time-series data should be embedded first.

T : pd.Series

Event times.

Y : pd.Series

Event values.

Returns:

Fitted model.

Return type:

Self

predict_risk(X: DataFrame, time_horizons: list) DataFrame[source]

Predict risk scores.

Parameters:
X : pd.DataFrame

Input covariates of fixed shape - time-series data should be embedded first.

time_horizons : List

Time horizons to predict risk at.

Returns:

Risk scores.

Return type:

pd.DataFrame

class tempor.methods.time_to_event.plugin_ts_xgb.XGBTimeToEventAnalysis(**params: Any)[source]

Bases: BaseTimeToEventAnalysis

XGB survival analysis model.

Parameters:
**params : Any

Parameters and defaults as defined in XGBTimeToEventAnalysisParams.

category : ClassVar[plugin_typing.PluginCategory] = 'time_to_event'

Plugin category, such as 'prediction.one_off.classification'. Must be set by the plugin class using @register_plugin.

name : ClassVar[plugin_typing.PluginName] = 'ts_xgb'

Plugin name, such as 'my_nn_classifier'. Must be set by the plugin class using @register_plugin.

plugin_type : ClassVar[plugin_typing.PluginTypeArg] = 'method'

Plugin type, such as 'method'. May be optionally set by the plugin class using @register_plugin, else will set the default plugin type.

ParamsDefinition

alias of XGBTimeToEventAnalysisParams

params : XGBTimeToEventAnalysisParams
static hyperparameter_space(*args: Any, **kwargs: Any) list[Params][source]

The hyperparameter search domain, used for tuning.

Can provide variadics *args and **kwargs, these will be received from sample_hyperparameters.