tempor.methods.time_to_event.plugin_ts_coxph module

CoxPH survival analysis model with Dynamic DeepHit embeddings.

tempor.methods.time_to_event.plugin_ts_coxph.monkeypatch_lifelines_pd2_compatibility() Generator[source]

lifelines (before 0.27.6) is not compatible with pandas 2.0.0+, due to TypeError: describe() got an unexpected keyword argument 'datetime_is_numeric' thrown by pandas in e.g. CoxPHFitter.fit. This monkeypatch fixes this compatibility issue, until the problem is addressed by lifelines.

class tempor.methods.time_to_event.plugin_ts_coxph.CoxPHTimeToEventAnalysisParams(coxph_alpha: float = 0.05, coxph_penalizer: float = 0.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

coxph_alpha : float = 0.05

alpha parameter for lifelines.CoxPHFitter.

coxph_penalizer : float = 0.0

penalizer parameter for lifelines.CoxPHFitter.

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.

tempor.methods.time_to_event.plugin_ts_coxph.drop_constant_columns(dataframe: DataFrame) list[source]

Drops constant value columns of pandas dataframe.

class tempor.methods.time_to_event.plugin_ts_coxph.CoxPHSurvivalAnalysis(alpha: float = 0.05, penalizer: float = 0, fit_options: dict | None = None, **kwargs: Any)[source]

Bases: OutputTimeToEventAnalysis

CoxPHFitter wrapper.

Parameters:
alpha : float, optional

The level in the confidence intervals. Defaults to 0.05.

penalizer : float, optional

Attach a penalty to the size of the coefficients during regression. Defaults to 0.

fit_options : Optional[Dict], optional

Pass kwargs for the fitting algorithm. Defaults to {"step_size": 0.1}.

**kwargs : Any

Additional keyword arguments for lifelines.CoxPHFitter.

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 estimation.

class tempor.methods.time_to_event.plugin_ts_coxph.CoxPHTimeToEventAnalysis(**params: Any)[source]

Bases: BaseTimeToEventAnalysis

CoxPH survival analysis model.

Parameters:
**params : Any

Parameters and defaults as defined in CoxPHTimeToEventAnalysisParams.

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_coxph'

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 CoxPHTimeToEventAnalysisParams

params : CoxPHTimeToEventAnalysisParams
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.