Survival Analysis for Machine Learning
The question survival analysis actually answers
Most classifiers answer "will this happen?" Survival analysis answers a more useful question: "when will this happen, and how confident are we?" It was originally developed in medicine to study time until death or relapse — hence the name — but the same math is now core infrastructure for churn prediction, equipment failure forecasting, and customer lifetime value modeling.
The key object of study is time-to-event data: for each subject, you observe a duration and whether the event of interest occurred during that duration. A customer might churn at month 7, or they might still be active at the end of your observation window — in which case you don't know when (or if) they'll churn, only that they survived at least that long.
Censoring: the problem that makes this hard
Censoring is the defining challenge of survival analysis. A subject is right-censored when the event hasn't occurred by the end of observation — you know they survived at least until time $t$, but not what happens after. This is extremely common: a 2-year retention study captures customers who joined last month and are still active; you can't label them as "non-churned" because that implies they'll never churn, and you can't drop them because that throws away valid partial information.
Treating censored subjects as simple binary labels (0 = didn't churn) biases every downstream estimate — it systematically overstates survival because many censored subjects would eventually experience the event, just after the observation window closed. Survival models are built specifically to use the partial information in censored observations correctly instead of discarding it or mislabeling it.
Note
The survival and hazard functions
Two functions anchor the whole field:
Survival function $S(t) = P(T > t)$ — the probability that the event hasn't happened by time $t$. It starts at $S(0) = 1$ and decreases monotonically toward 0 (or some floor, if some subjects never experience the event at all).
Hazard function $h(t)$ — the instantaneous risk of the event happening at time $t$, given survival up to that point. It's the rate, not the cumulative probability: $h(t) = \lim_{\Delta t \to 0} \frac{P(t \le T < t + \Delta t \mid T \ge t)}{\Delta t}$.
The two are related: $S(t) = \exp\left(-\int_0^t h(u)\, du\right)$. A rising hazard means risk increases with time (e.g., mechanical parts wearing out); a falling hazard means early periods are riskiest (e.g., new subscribers churning in the first week, then stabilizing).
Kaplan-Meier: estimating survival without assumptions
The Kaplan-Meier estimator computes $S(t)$ directly from data with no assumption about the shape of the underlying distribution. At each time an event occurs, it updates the running survival estimate by the fraction of at-risk subjects who survived that step:
$$\hat{S}(t) = \prod_{t_i \le t} \left(1 - \frac{d_i}{n_i}\right)$$
where $n_i$ is the number of subjects still at risk just before time $t_i$, and $d_i$ is the number of events at $t_i$. The result is a step function that drops at each observed event and stays flat between events. Plotted, it gives an immediately interpretable curve: read off any time $t$ on the x-axis and get the estimated fraction still "surviving" (e.g., still subscribed) at that point.
Cox proportional hazards: adding covariates
Kaplan-Meier describes a single population's survival curve, but it can't tell you how features (plan type, usage frequency, support tickets filed) change an individual's risk. The Cox proportional hazards model extends survival analysis to covariates by modeling the hazard as a baseline hazard multiplied by an exponential function of the features:
$$h(t \mid x) = h_0(t) \cdot \exp(\beta_1 x_1 + \beta_2 x_2 + \cdots + \beta_k x_k)$$
The baseline hazard $h_0(t)$ captures how risk changes over time for a hypothetical "average" subject, while each $\beta_i$ tells you the multiplicative effect of a feature on hazard — a coefficient of $\beta = 0.5$ means a one-unit increase in that feature multiplies hazard by $e^{0.5} \approx 1.65$. This is the "proportional hazards" assumption: features scale the hazard up or down, but the baseline shape over time stays the same for everyone.
Choosing a survival modeling approach
| Approach | Handles covariates? | Assumes a hazard shape? | Typical use |
|---|---|---|---|
| Kaplan-Meier | No (population-level only) | No — fully nonparametric | Describing overall retention/survival curve |
| Cox proportional hazards | Yes, many features | No shape for baseline, but assumes proportionality | Ranking risk factors, estimating relative risk |
| Parametric (Weibull, exponential) | Yes | Yes — fixed functional form | When you need a fully specified distribution for simulation |
| Random survival forests / gradient boosted survival | Yes, nonlinear interactions | No | Large datasets with complex feature interactions |
Note
What's next
Survival analysis is one example of how getting the right statistical framing — not just throwing a generic model at the data — changes what questions you can answer. The next lesson on statistical hypothesis testing for ML model comparison covers a related discipline: rigorously testing whether one model actually beats another, instead of trusting a single accuracy number.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.