Cox proportional_hazards model with partial-likelihood estimation.
Classes
Cox proportional_hazards model.
The semiparametric workhorse of survival analysis. It models the hazard of subject i as
where h_0(t) is an unspecified baseline hazard and \beta are covariate effects. A positive coefficient means the covariate raises the hazard and therefore shortens expected survival.
__init__( self, penalty: Optional[str] = 'l2', alpha: float = 0.0, tol: float = 1e-06, max_iter: int = 100, )
Overview
- Order subjects by observed time, descending.
- Maximise the partial likelihood in \beta with Newton-Raphson
- Estimate the baseline hazard via the Breslow estimator and expose the
Theory
For right-censored data the partial log-likelihood is
whose gradient and Hessian are accumulated over risk sets R(t_i) = \{j : t_j \geq t_i\}:
With L2 regularisation, \ell(\beta) - \frac{\alpha}{2}\|\beta\|^2 is maximised, which shrinks coefficients toward zero. The baseline hazard is
and \hat{S}_0(t) = \exp\!\left(-\sum_{t_j \leq t} \hat{h}_0(t_j)\right).
Parameters
penalty
"l2" adds a ridge penalty; None fits the unpenalised partial likelihood.
alpha
penalty="l2").
tol
max_iter
Attributes
coefficients_
baseline_times_
baseline_hazard_
baseline_cumulative_hazard_
baseline_survival_
n_features_in_
fit().
Notes
Complexity:
- Fitting: O(I \cdot (n p + n p^2)) for I iterations,
- Prediction: O(p) per sample.
- When the proportional_hazards assumption is reasonable.
- When you need interpretable coefficients rather than pure predictive power.
References
>>> from tuiml.algorithms.survival import CoxPHSurvival
>>> import numpy as np
>>> # A single binary covariate: group 1 always fails first.
>>> X = np.array([[1.], [1.], [1.], [0.], [0.], [0.]])
>>> time = np.array([1., 2., 3., 4., 5., 6.])
>>> event = np.ones(6)
>>> cox = CoxPHSurvival().fit(X, time, event)
>>> bool(cox.coefficients_[0] > 0)
True
Methods
fit
(self, X, time, event) -> 'CoxPHSurvival'
fit
(self, X, time, event) -> 'CoxPHSurvival'
Fit the model by maximising the (penalised) partial likelihood.
Parameters
X
time
event
Returns
self
predict_cumulative_hazard
(self, X, times=None) -> np.ndarray
predict_cumulative_hazard
(self, X, times=None) -> np.ndarray
Return the predicted cumulative hazard for each sample.
Parameters
X
times
baseline_times_.
Returns
H
predict_survival_function
(self, X, times=None) -> np.ndarray
predict_survival_function
(self, X, times=None) -> np.ndarray
Return the predicted survival function for each sample.
Parameters
X
times
baseline_times_.
Returns
S