estimators

CoxProportionalHazard

Cox Proportional Hazards.

ParametricDiscreteTimePH

Parametric Discrete Time Proportional Hazards.

KaplanMeierSurvivalEstimator

The Kaplan-Meier estimate of the survival estimation.

KNeighborsSurvival

Survival curves implementing the k-nearest neighbors vote.

CoxNeuralNetPH

Artificial neural network proportional hazards Model.

AalenAdditiveHazard

Aalen Additive Hazards.

CoxPHElasticNet

Cox Proportional Hazards with Elastic Net penalty and feature shrinkage.

MultiTaskLogisticRegression

Multi-Task Logistic Regression.

DecisionTreeSurvival

Decision Tree for survival curves.

RandomForestSurvival

Random Forest for survival curves.

class survivalpredict.estimators.CoxProportionalHazard(*, alpha=0.0, max_iter=25, solver='newton', ties='breslow', tol=1e-09)

Cox Proportional Hazards.

The ‘Cox Proportional Hazards’ model is a linear semi-parametric relative risk model. A staple of survival analysis. Cox more or less trains on ranking relative risk to estimate its coefficients. After training, the ‘Breslow estimator’ is run on relative risk and events over time to build the base hazard. A product of the relative risk and base hazard at each point in time is used to build the survival curves.

The Cox is called ‘semi-parametric’ due to the fact that is does not directly estimate the hazard, but only relative hazard. Hence, ‘partial-likelihood’ is what Cox estimates maximizes.

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

  • max_iter (int, default=25) – The maximum number of iterations used for newton and adaptive_newton methods.

  • solver ({"newton", "adaptive_newton","BFGS","L-BFGS-B"}) – Numerical solver to use.

  • ties ({"breslow", "efron"}, default='breslow') – The method to handle ‘tied’ event times. Cox’s coefficients are intended to represent the relative risk of observations in proportion to each other, independent of time. The presence of ‘tied’ or concurrent failures muddies the interpretability of Cox’s coefficients.‘Breslow ties’ ignore said issue and perform best on predictions. ‘Efron ties’ shaves some of the influence of some tied data on the likelihood, in hopes of solving said problem and at the price of prediction performance. Use Breslow if prediction performance is your primary concern, and use Efron in cases of inference.

  • tol (float, default=1e-9) – The tolerance for the optimization: if the updates are smaller or equal to tol, the optimization code checks the dual gap for optimality and continues until it is smaller or equal to tol.

See also

survivalpredict.estimators.ParametricDiscreteTimePH

Fully parametric equivalent.

survivalpredict.estimators.CoxNeuralNetPH

Deep Cox model.

survivalpredict.estimators.CoxPHElasticNet

Cox with ElasticNet/Lasso shrinkage.

coef_

Coefficients of the model.

Type:

ndarray of ndarray of shape (n_features,)

n_log_likelihood

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)

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

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

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

get_pymc_model(X, times, events[, ...])

Return a pymc model that is equivalent to the initialized Cox Proportional Hazards.

predict(X[, strata, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, strata, max_time])

Build hazards on an array of vectors X.

predict_risk(X)

Build relative risk on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

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.

get_pymc_model(X, times, events, labes_names=None, strata=None, times_start=None, coefs_sigma=10, empirical_bayes=True)

Return a pymc model that is equivalent to the initialized Cox Proportional Hazards. Allows for generating ‘Markov chain Monte Carlo’ traces for inference.

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.

  • labes_names (list of str, default=None) – Names for feature, allows for parameters associated with each feature to be named accordingly.

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

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

  • coefs_sigma (float, default=10.0) – Sigma of the normal distribution used for the coefficients.

  • empirical_bayes (bool, default=True) – If True and the class has been fit/trained, the initial coefficient values will be the trained coefficients.

Return type:

“pymc.Model”

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_hazard(X, strata=None, max_time=None)

Build hazards 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 hazards. If none, maximum time is max time seen on training data.

Returns:

The estimated hazards, the left-most column is the hazards 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

class survivalpredict.estimators.ParametricDiscreteTimePH(*, distribution='chen', alpha=0.0, l1_ratio=0.5, pytensor_mode='JAX', strata_uses_pytensor_scan=False, coef_prior_normal_sigma=1.5, base_harard_prior_exponential_lam=5.0, scipy_minimize_method='L-BFGS-B')

Parametric Discrete Time Proportional Hazards.

A fully parametric linear proportional hazards model. Unlike Cox, both the coefficients and the base hazard are directly estimated from observed survival over time. Various distributions are available as base hazards; namely, Chen, Weibull, Log-Normal, Log-logistic, Gompertz, Gamma and Additive-Chen-Weibull[1] are available as hyperparameters. Maximum likelihood is estimated using a survival distinct time likelihood[2] with censorship. Implemented with Pymc/Pytensor, with either a Jax or numba backend.

Parameters:
  • distribution ({"chen", "weibull","log_normal","log_logistic","gamma","gompertz","additive_chen_weibull"}, default='chen') – Distribution of base hazard.

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

  • pytensor_mode ({"JAX", "NUMBA","FAST_COMPILE"}, default='JAX') – Pytensor backend. ‘JAX’ has the fastest compile time, but is not multiprocessing safe. NUMBA is multiprocessing safe, but has a long compile time. Pytensor’s ‘FAST_COMPILE’ mode is multiprocessing safe and has a fast compile time, but runs slower than the other modes. ‘JAX’ is a good default, but ‘NUMBA’ is recommended when using multiprocessing.

  • strata_uses_pytensor_scan (bool, default=False) – If strata are present and ‘strata_uses_pytensor_scan’ is True, Pytensor’s ‘scan’ functionality is used to map strata to observations during training. Using Pytensor scan might increase the Pytensor compile time, but will lead to a faster runtime. For considerable data and a high quantity of starta, it is recommended to set strata_uses_pytensor_scan to True.

  • coef_prior_normal_sigma (float, default=1.5) – This class runs a Pymc model under the hood. The coefficients are modeled as normal distributions. This parameter is the sigma of the prior. The larger the sigma, the wider the possible set of values coverage. It is recommended to scale the data to avoid tuning this parameter.

  • base_harard_prior_exponential_lam (float, default=5.0) – This class runs a Pymc model under the hood. The base hazard distribution’s parameters are modeled as exponential distributions. This parameter is the ‘lam’ of the prior of the base hazard distribution’ parameters. It is recommended to scale the data to avoid tuning this parameter.

  • scipy_minimize_method ({"nelder-mead","powell","CG","BFGS","Newton-CG","L-BFGS-B","TNC","COBYLA","SLSQP","trust-constr","dogleg","trust-ncg","trust-exact","trust-krylov","basinhopping",}, default='L-BFGS-B') – This class runs a Pymc model under the hood. Durring training we simply find the ‘Maximum likelihood estimation’(MLE)/ ‘Maximum a posteriori estimation’(MAP). This is the exposed method that PYMC find the MLE/MAP.

See also

survivalpredict.estimators.CoxProportionalHazard

Semi-parametric equivalent.

References

[1] Thanh Thach T, Briš R. An additive Chen-Weibull distribution and its applications in reliability modeling. Qual Reliab Engng Int. 2021;37:352–373. https://doi.org/10.1002/qre.2740

[2] Suresh K, Severn C, Ghosh D. Survival prediction models: an introduction to discrete-time modeling. BMC Med Res Methodol. 2022 Jul 26;22(1):207. doi: 10.1186/s12874-022-01679-6. PMID: 35883032; PMCID: PMC9316420.

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

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

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

get_base_hazard([max_time])

Retrieve base hazards estimated by model.

get_pymc_model(X, times, events[, max_time, ...])

Return the underlying Pymc model.

predict(X[, strata, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, strata, max_time])

Build hazards on an array of vectors X.

predict_risk(X)

Build relative risk on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

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.

get_base_hazard(max_time=None)

Retrieve base hazards estimated by model.

Parameters:

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 base hazard; used in building survival curves.

Return type:

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

get_pymc_model(X, times, events, max_time=None, labes_names=None, strata=None, strata_names=None, times_start=None, empirical_bayes=True)

Return the underlying Pymc 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.

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

  • labes_names (list of str, default=None) – Names for feature, allows for parameters associated with each feature to be named accordingly.

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

  • strata_names (list of str, default=None) – Names for strata, allows for parameters associated with each strata to be named accordingly.

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

  • empirical_bayes (bool, default=True) – If True and the class has been fit/trained, the initial coefficient values will be the trained coefficients.

Return type:

“pymc.Model”

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 (Optional[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_hazard(X, strata=None, max_time=None)

Build hazards 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 hazards. If none, maximum time is max time seen on training data.

Returns:

The estimated hazards, the left-most column is the hazards 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

class survivalpredict.estimators.KaplanMeierSurvivalEstimator

The Kaplan-Meier estimate of the survival estimation.

Kaplan-Meier is a univariate non-parametric survival curve estimation. It can be useful as a baseline/dummy estimator.

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

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_hazard(X[, strata, max_time])

Build hazards on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

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_hazard(X, strata=None, max_time=None)

Build hazards 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 hazards. If none, maximum time is max time seen on training data.

Returns:

The estimated hazards, the left-most column is the hazards at time 1, and the right-most column ends at max_time.

Return type:

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

class survivalpredict.estimators.KNeighborsSurvival(n_neighbors=10, algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_param=None, n_jobs=None)

Survival curves implementing the k-nearest neighbors vote.

Builds Kaplan Meier curves on k-nearest neighbors. Parameters docs are taken from scikit-learn.

Parameters:
  • n_neighbors (int, default=5) – Number of neighbors to use by default for kneighbors() queries.

  • algorithm ({'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto') –

    Algorithm used to compute the nearest neighbors:

    • ’ball_tree’ will use BallTree

    • ’kd_tree’ will use KDTree

    • ’brute’ will use a brute-force search.

    • ’auto’ will attempt to decide the most appropriate algorithm based on the values passed to fit() method.

  • leaf_size (int, default=30) – Leaf size passed to BallTree or KDTree. This can affect the speed of the construction and query, as well as the memory required to store the tree. The optimal value depends on the nature of the problem.

  • p (float, default=2) – Power parameter for the Minkowski metric. When p = 1, this is equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used. This parameter is expected to be positive.

  • metric (str or callable, default='minkowski') –

    Metric to use for distance computation. Default is “minkowski”, which results in the standard Euclidean distance when p = 2. See the documentation of scipy.spatial.distance and the metrics listed in distance_metrics for valid metric values.

    If metric is “precomputed”, X is assumed to be a distance matrix and must be square during fit. X may be a sparse graph, in which case only “nonzero” elements may be considered neighbors.

    If metric is a callable function, it takes two arrays representing 1D vectors as inputs and must return one value indicating the distance between those vectors. This works for Scipy’s metrics, but is less efficient than passing the metric name as a string.

  • metric_param (dict, default=None) – Additional keyword arguments for the metric function.

  • n_jobs (int, default=None) – The number of parallel jobs to run for neighbors search. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. Doesn’t affect fit method.

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

fit(X, times, events[, check_input, times_start])

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X[, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, max_time])

Build hazards on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

fit(X, times, events, 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.

  • 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, max_time=None)

Build survival curves on an array of vectors X.

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

  • 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_hazard(X, max_time=None)

Build hazards on an array of vectors X.

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

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

Returns:

The estimated hazards, the left-most column is the hazards at time 1, and the right-most column ends at max_time.

Return type:

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

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

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

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_hazard(X[, strata, max_time])

Build hazards on an array of vectors X.

predict_risk(X)

Build relative risk on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

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_hazard(X, strata=None, max_time=None)

Build hazards 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 hazards. If none, maximum time is max time seen on training data.

Returns:

The estimated hazards, the left-most column is the hazards 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

class survivalpredict.estimators.AalenAdditiveHazard(clip_hazards=True, alpha=0.0)

Aalen Additive Hazards.

Aalen Additive Hazards is a linear multivariate non-parametric estimation of hazard. It allows for each interval of time and feature to have an associated coefficient, allowing for the effects of features to change over time. Aalen Additive Hazards simply runs (ridge) linear regressions at different points in time, 1 if the event and 0 otherwise , censored times are ignored. The results of the linear regressions are used for generating hazards and ultimately survival curves. AalenAdditiveHazard models are tricky to train.

Parameters:
  • clip_hazards (bool, default=True) – If True, clips hazards to be between 0 and 1. Ensuring that hazard values are realistic.

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

_hazard_weights

Coefficients of the model.

Type:

ndarray of ndarray of shape (n_features,n)

_hazard_weights_times

Times associated for each interval of time in the _hazard_weights array.

Type:

ndarray of ndarray of shape (n)

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

fit(X, times, events[, check_input, times_start])

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X[, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, max_time])

Build hazards on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

fit(X, times, events, 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.

  • 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, max_time=None)

Build survival curves on an array of vectors X.

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

  • max_time (Optional[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_hazard(X, max_time=None)

Build hazards on an array of vectors X.

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

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

Returns:

The estimated hazards, the left-most column is the hazards at time 1, and the right-most column ends at max_time.

Return type:

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

class survivalpredict.estimators.CoxPHElasticNet(*, alpha=0.0, l1_ratio=0.5, max_iter=100, tol=1e-09)

Cox Proportional Hazards with Elastic Net penalty and feature shrinkage.

A Cox Proportional Hazards model with Elastic Net penalty estimated via coordinate descent. The coordinate descent algorithm for Elastic Net/Lasso allows shrinking features asynchronously as the ‘alpha’ parameter increases, and the ‘l1_ratio’ is greater than 0. The raphson-newton-like for coordinate descent described in Simon et al. (2011)[1] is used.

Only ‘breslow’ ties are available; the literature is currently unclear on how to add stratification to Simon’s algorithm.

Parameters:
  • 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.

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

  • tol (float, default=1e-9) – The tolerance for the optimization: if the updates are smaller or equal to tol, the optimization code checks the dual gap for optimality and continues until it is smaller or equal to tol.

References

[1] Simon N, Friedman J, Hastie T, Tibshirani R. Regularization Paths for Cox’s Proportional Hazards Model via Coordinate Descent. J Stat Softw. 2011 Mar;39(5):1-13. doi: 10.18637/jss.v039.i05. PMID: 27065756; PMCID: PMC4824408.

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

fit(X, times, events[, check_input, times_start])

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X[, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, max_time])

Build hazards on an array of vectors X.

predict_risk(X)

Build relative risk on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

fit(X, times, events, 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.

  • 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, max_time=None)

Build survival curves on an array of vectors X.

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

  • 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_hazard(X, max_time=None)

Build hazards on an array of vectors X.

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

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

Returns:

The estimated hazards, the left-most column is the hazards 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

class survivalpredict.estimators.MultiTaskLogisticRegression(*, c1=0.0, c2=0.0, fit_intercept=True, solver='L-BFGS-B')

Multi-Task Logistic Regression.

Multi-Task Logistic Regression is a survival model with time-varying coefficients. Each interval of time and feature has an associated coefficient. Each interval of time’s estimation of survival is dependent on the previous estimation of survival[1]. The ‘brown loss’ for discrete time survival is used[2] instead of the log-likelihood of the original paper. The c1 and c2 regulation from the Yu et al[1] paper is present.

Implemented with Jax.

Parameters:
  • c1 (float, default=0.0) – Regulation penatly for smoothing the effects of features across time.

  • c2 (float, default=0.0) – Penatly for l2 regularization of weights.

  • fit_intercept (bool, default=True) – If true, adds constants to X array.

  • solver ({"BFGS","L-BFGS-B"}, default='L-BFGS-B') – Numerical solver to use.

coef_

Coefficients of the model.

Type:

ndarray of shape (n_features,max_time)

loss_

Loss at point the point of convergence.

Type:

float

max_iter_seen_

Number of training iterations point of convergence.

Type:

int

References

[1] Yu, Chun-Nam & Greiner, Russ & Lin, Hsiu-Chin & Baracos, Vickie. (2012). Learning Patient-Specific Cancer Survival Distributions as a Sequence of Dependent Regressors.

[2] Suresh K, Severn C, Ghosh D. Survival prediction models: an introduction to discrete-time modeling. BMC Med Res Methodol. 2022 Jul 26;22(1):207. doi: 10.1186/s12874-022-01679-6. PMID: 35883032; PMCID: PMC9316420.

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

fit(X, times, events[, check_input, times_start])

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X[, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, max_time])

Build hazards on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

fit(X, times, events, 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.

  • 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, max_time=None)

Build survival curves on an array of vectors X.

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

  • 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_hazard(X, max_time=None)

Build hazards on an array of vectors X.

It should be noted that MTLR does not have a native notion of hazard. What is presented here is a modified formula of MTLR, before probabilities per time of survival are multiplied. It can function as an equivalent to hazards; survival curves can also be built from it.

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

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

Returns:

The estimated hazards, the left-most column is the hazards at time 1, and the right-most column ends at max_time.

Return type:

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

class survivalpredict.estimators.DecisionTreeSurvival(*, criterion='log_rank', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0, parallel_split_finding=False)

Decision Tree for survival curves.

Non-parametric recursive partitioning builder for survival curves. Various splitting criteria for partitioning evaluation are available [1]. There is no support for missing data. Both left and right censorship are supported. On estimation, the associated Kaplan–Meier curve for the assigned partition/leaf is returned.

Parameters:
  • criterion ({"wasserstein_distance","log_rank"}, default='log_rank') – The function to measure the quality of a split. The “log_rank” criterion tries to maximise the chi-squared metric of an approximation for the ‘two-sample log-rank test’, for the difference in survival between populations.The “wasserstein_distance” measures the distance between the Kaplan-Meier curves of possible splits.

  • splitter ({"best"}, default="best") – The strategy used to choose the split at each node. Currently ony the “best” strategy is available.

  • max_depth (int, default=None) – The maximum depth of the tree. If None, then nodes are expanded until all leaves are pure or until all leaves contain less than min_samples_split samples.

  • min_samples_split (int, default=2) – The minimum number of samples required to split an internal node.

  • min_samples_leaf (int, default=1) – The minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min_samples_leaf training samples in each of the left and right branches.

  • min_weight_fraction_leaf (float, default=0.0) – The minimum weighted fraction of the sum total of weights (of all the input samples) required to be at a leaf node. Samples have equal weight when sample_weight is not provided.

  • max_features (int, float or {"sqrt", "log2"}, default=None) –

    The number of features to consider when looking for the best split:

    • If int, then consider max_features features at each split.

    • If float, then max_features is a fraction and max(1, int(max_features * n_features_in_)) features are considered at each split.

    • If “sqrt”, then max_features=sqrt(n_features).

    • If “log2”, then max_features=log2(n_features).

    • If None, then max_features=n_features.

  • random_state (int or None, default=None) – Controls the randomness of the estimator. The features are always randomly permuted at each split, even if splitter is set to "best". When max_features < n_features, the algorithm will select max_features at random at each split before finding the best split among them. But the best found split may vary across different runs, even if max_features=n_features.

  • max_leaf_nodes (int, default=None) – Grow a tree with max_leaf_nodes in best-first fashion. Best nodes are defined as relative reduction in impurity. If None then unlimited number of leaf nodes.

  • min_impurity_decrease (float, default=0.0) – A node will be split if this split induces a decrease of the impurity greater than or equal to this value. Uses “integrated_brier_score_administrative” for each node.

  • ccp_alpha (non-negative float, default=0.0) – Complexity parameter used for Minimal Cost-Complexity Pruning. The subtree with the largest cost complexity that is smaller than ccp_alpha will be chosen. By default, no pruning is performed.

  • parallel_split_finding (bool, default=False) – If set to ‘True ’, parallelizes the “best” partition search across features. There is an overhead to parallelization, and it is advised to parallelize partition search when data is not small and only a single tree is being built at a time.

tree_

The underlying Tree object.

Type:

sklearn.tree._tree.Tree

See also

sklearn.tree.DecisionTreeClassifier

Scikit-learn equivalent for classification.

survivalpredict.estimators.KaplanMeierSurvivalEstimator

Underlying averaging strategy for nodes/parititons.

survivalpredict.estimators.RandomForestSurvival

Meta-estimator using trees.

survivalpredict.estimators.KNeighborsSurvival

Similar nonparametric estimator.

References

[1] Shimokawa A, Kawasaki Y, Miyaoka E. Comparison of splitting methods on survival tree. Int J Biostat. 2015 May;11(1):175-88. doi: 10.1515/ijb-2014-0029. PMID: 25849798.

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

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

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X[, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, max_time])

Build hazards on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

fit(X, times, events, check_input=True, times_start=None, sample_weight=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.

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

  • sample_weight (array-like of shape (n_samples), default=None) – Sample weights.

Returns:

Fitted Estimator.

Return type:

object

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X, max_time=None)

Build survival curves on an array of vectors X.

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

  • 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_hazard(X, max_time=None)

Build hazards on an array of vectors X.

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

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

Returns:

The estimated hazards, the left-most column is the hazards at time 1, and the right-most column ends at max_time.

Return type:

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

class survivalpredict.estimators.RandomForestSurvival(*, n_estimators=50, bootstrap=True, n_jobs=None, max_samples=None, criterion='log_rank', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='sqrt', random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0)

Random Forest for survival curves.

Meta estimator that fits a number of survival decision trees on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting. Trees in the forest use the best split strategy. The sub-sample size is controlled with the max_samples parameter if bootstrap=True (default), otherwise the whole dataset is used to build each tree. By default, the algorithm examines only a random subset of features to find the split; the max_features parameter can change this behaviour.

Parameters:
  • n_estimators (int, default=50) – The number of trees in the forest.

  • bootstrap (bool, default=True) – Whether bootstrap samples are used when building trees. If False, the whole dataset is used to build each tree.

  • n_jobs (int, default=None) – The number of jobs to run in parallel. fit(), predict(), and predict_hazard() are all parallelized over the trees. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.

  • max_samples (int or float, default=None) –

    If bootstrap is True, the number of samples to draw from X to train each base estimator.

    • If None (default), then draw X.shape[0] samples irrespective of sample_weight.

    • If int, then draw max_samples samples.

    • If float, then draw max_samples * X.shape[0] unweighted samples or max_samples * sample_weight.sum() weighted samples.

  • criterion ({"wasserstein_distance","log_rank"}, default='log_rank') – The function to measure the quality of a split. The “log_rank” criterion tries to maximise the chi-squared metric of an approximation for the ‘two-sample log-rank test’, for the difference in survival between populations.The “wasserstein_distance” measures the distance between the Kaplan-Meier curves of possible splits.

  • splitter ({"best"}, default="best") – The strategy used to choose the split at each node. Currently ony the “best” strategy is available.

  • max_depth (int, default=None) – The maximum depth of the tree. If None, then nodes are expanded until all leaves are pure or until all leaves contain less than min_samples_split samples.

  • min_samples_split (int, default=2) – The minimum number of samples required to split an internal node.

  • min_samples_leaf (int, default=1) – The minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min_samples_leaf training samples in each of the left and right branches.

  • min_weight_fraction_leaf (float, default=0.0) – The minimum weighted fraction of the sum total of weights (of all the input samples) required to be at a leaf node. Samples have equal weight when sample_weight is not provided.

  • max_features (int, float or {"sqrt", "log2"}, default="sqrt") –

    The number of features to consider when looking for the best split:

    • If int, then consider max_features features at each split.

    • If float, then max_features is a fraction and max(1, int(max_features * n_features_in_)) features are considered at each split.

    • If “sqrt”, then max_features=sqrt(n_features).

    • If “log2”, then max_features=log2(n_features).

    • If None, then max_features=n_features.

  • random_state (int or None, default=None) – Controls the randomness of the estimator. The features are always randomly permuted at each split, even if splitter is set to "best". When max_features < n_features, the algorithm will select max_features at random at each split before finding the best split among them. But the best found split may vary across different runs, even if max_features=n_features.

  • max_leaf_nodes (int, default=None) – Grow a tree with max_leaf_nodes in best-first fashion. Best nodes are defined as relative reduction in impurity. If None then unlimited number of leaf nodes.

  • min_impurity_decrease (float, default=0.0) – A node will be split if this split induces a decrease of the impurity greater than or equal to this value. Uses “integrated_brier_score_administrative” for each node.

  • ccp_alpha (non-negative float, default=0.0) – Complexity parameter used for Minimal Cost-Complexity Pruning. The subtree with the largest cost complexity that is smaller than ccp_alpha will be chosen. By default, no pruning is performed.

estimator_

The child estimator template used to create the collection of fitted sub-estimators.

Type:

DecisionTreeSurvival

estimators_

The collection of fitted sub-estimators.

Type:

list of DecisionTreeSurvival

See also

survivalpredict.estimators.DecisionTreeSurvival

Underlying estimator.

survivalpredict.estimators.KaplanMeierSurvivalEstimator

Underlying averaging strategy for nodes/parititons.

sklearn.ensemble.RandomForestClassifier

Scikit-learn equivalent for classification.

References

[1] Ishwaran, Hemant & Kogalur, Udaya & Blackstone, Eugene & Lauer, Michael. (2008). Random survival forests. The Annals of Applied Statistics. 2. 10.1214/08-AOAS169.

Methods

convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

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

Fit model.

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X[, max_time])

Build survival curves on an array of vectors X.

predict_hazard(X[, max_time])

Build hazards on an array of vectors X.

static convert_hazard_to_survival(hazards)

Convert hazards to survival curves.

Parameters:

hazards (array-like, dtype=np.float64) – Array of hazards.

Returns:

Survival curves generated from given hazards.

Return type:

ndarray, dtype=np.float64

fit(X, times, events, check_input=True, times_start=None, sample_weight=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.

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

  • sample_weight (array-like of shape (n_samples), default=None) – Sample weights.

Returns:

Fitted Estimator.

Return type:

object

fit_predict(*args, **kwargs)

Fit model and Build survival curves.

predict(X, max_time=None)

Build survival curves on an array of vectors X.

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

  • 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_hazard(X, max_time=None)

Build hazards on an array of vectors X.

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

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

Returns:

The estimated hazards, the left-most column is the hazards at time 1, and the right-most column ends at max_time.

Return type:

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