survivalpredict.estimators.CoxNeuralNetPH

class survivalpredict.estimators.CoxNeuralNetPH(hidden_layers=[100], alpha=0.0, l1_ratio=0.5, init_dis='uniform', track_loss=True, max_iter=100, gradient_updater='adam', learning_rate=0.01, beta1=0.9, beta2=0.999, epsilon=1e-07, rho=0.95, decay=0.9)

Artificial neural network proportional hazards Model.

A neural network model for estimating relative risk. Cox proportional hazards model’s ‘negative log likelihood for Breslow ties’ is used as a loss function. Breslow’s base hazard for relative risk is used to estimate survival across time. The combination of relative risk and base hazard is used to generate survival curves, like Cox proportional hazards. Implemented using Jax. All activation functions as assumed to be relu.

Parameters:
  • hidden_layers (list of ints, default=[100,]) – The ith element represents the number of neurons in the ith hidden layer.

  • alpha (float, default=0.0) – Constant that multiplies the penalty terms. Used to penalize coefficients durring training.

  • l1_ratio (float, default=0.5) – The ElasticNet mixing parameter, with 0 <= l1_ratio <= 1. For l1_ratio = 0 the penalty is an L2 penalty. For l1_ratio = 1 it is an L1 penalty. For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

  • init_dis (Literal["uniform", "normal"], default="uniform") – Distribution of the He/Kaiming weight initialization.

  • track_loss (bool, default=True) – If True, changes to loss over training itteration is tracked.

  • max_iter (int, default=100) – The maximum number of iterations.

  • gradient_updater ({"adadelta", "adagrad", "adam", "adamax", "rmsprop"}, default="adam") – Gradient updating strategy, used for training. Corresponds to optax Optimizers.

  • learning_rate (float, default=0.01) – Corresponds to optax Optimizer parameter.

  • beta1 (float, default=0.9) – Corresponds to optax Optimizer parameter.

  • beta2 (float, default=0.999) – Corresponds to optax Optimizer parameter.

  • epsilon (float, default=0.0000001) – Corresponds to optax Optimizer parameter.

  • rho (float, default=0.95) – Corresponds to optax Optimizer parameter.

  • decay (float, default=0.9) – Corresponds to optax Optimizer parameter.

coef_

Coefficients of the model.

Type:

ndarray of ndarray of shape (n_features,)

_loss

Negative log likelihood of the model at the point of convergence.

Type:

float

_breslow_base_hazard

Base hazard generated from training data, used for predicting survival curves.

Type:

ndarray of ndarray of shape (max_time_seen,) or shape (n_strata,max_time_seen)

_breslow_base_survival

Base survival generated from training data, used for predicting survival curves.

Type:

ndarray of ndarray of shape (max_time_seen,) or shape (n_strata,max_time_seen)

losses_per_steps

If track_loss is set to True, loss at each itteration while training.

Type:

list of float

Methods

fit(X, times, events[, strata, check_input, ...])

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X[, strata, max_time])

Build survival curves on an array of vectors X.

predict_risk(X)

Build relative risk on an array of vectors X.

__init__(hidden_layers=[100], alpha=0.0, l1_ratio=0.5, init_dis='uniform', track_loss=True, max_iter=100, gradient_updater='adam', learning_rate=0.01, beta1=0.9, beta2=0.999, epsilon=1e-07, rho=0.95, decay=0.9)
Parameters:
  • hidden_layers (list[int])

  • alpha (float)

  • l1_ratio (float)

  • init_dis (Literal['uniform', 'normal'])

  • gradient_updater (Literal['adadelta', 'adagrad', 'adam', 'adamax', 'rmsprop'])

  • learning_rate (float)

  • beta1 (float)

  • beta2 (float)

  • epsilon (float)

  • rho (float)

  • decay (float)

Methods

__init__([hidden_layers, alpha, l1_ratio, ...])

fit(X, times, events[, strata, check_input, ...])

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X[, strata, max_time])

Build survival curves on an array of vectors X.

predict_risk(X)

Build relative risk on an array of vectors X.

set_fit_request(*[, check_input, events, ...])

Configure whether metadata should be requested to be passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

set_predict_request(*[, max_time, strata])

Configure whether metadata should be requested to be passed to the predict method.

fit(X, times, events, strata=None, check_input=True, times_start=None)

Fit model.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • times (array-like of shape (n_samples), dtype=np.int64) – Point in time last observed.

  • events (array-like of shape (n_samples), dtype=np.bool_) – Experianed event.

  • strata (array-like of shape (n_samples,), dtype=np.int64, default=None) – If passed in, associated strata for per observation.

  • check_input (bool, default=True) – If True, validates and casts inputs.

  • times_start (array-like of shape (n_samples, dtype=np.int64), default=None) – Starting point for observation. If not passed in, all times_start times are assumed to be 0.

Returns:

Fitted Estimator.

Return type:

object

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X, strata=None, max_time=None)

Build survival curves on an array of vectors X.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Predicting data.

  • strata (array-like of shape (n_samples,), dtype=np.int64, default=None) – If passed in, associated strata for per observation.

  • max_time (int, default=None) – Maximum time of built survival curves. If none, maximum time is max time seen on training data.

Returns:

The estimated survival curves, the left-most column is the probability of survival at time 1, and the right-most column ends at max_time.

Return type:

ndarray of shape (n_samples, max_time), dtype=np.float64

predict_risk(X)

Build relative risk on an array of vectors X.

Parameters:

X (array-like of shape (n_samples, n_features)) – Predicting data.

Returns:

The Relative risk of X, used under the hood for building survival curves. Relative risk is what ‘Concordance Index’ examines.

Return type:

ndarray of shape (n_samples), dtype=np.float64