Lifelines

From mkurman/zorai · View interactive version

Lifelines is an AI agent skill from the GitHub repository mkurman/zorai. Survival analysis in Python: Kaplan-Meier, Cox proportional hazard, Aalen additive, parametric models, and competing risks. Censored data handling for churn, clinical, and actuarial applications.

How to use this skill

Skill file

Overview

Lifelines is a survival analysis library for Python. It implements Kaplan-Meier, Cox Proportional Hazard, parametric models (Weibull, Log-Normal), and Aalen's additive model. Use it for time-to-event data in clinical trials, churn analysis, reliability engineering, and customer retention studies.

Installation

uv pip install lifelines

Kaplan-Meier Estimate

from lifelines import KaplanMeierFitter
import pandas as pd

T = pd.Series([5, 10, 15, 20, 25, 30])  # durations
E = pd.Series([1, 1, 0, 1, 0, 0])       # event observed?

kmf = KaplanMeierFitter()
kmf.fit(T, E)
kmf.plot_survival_function()
print(kmf.median_survival_time_)

Cox Proportional Hazard

from lifelines import CoxPHFitter

df = pd.DataFrame({
    "duration": [5, 10, 15, 20, 25, 30],
    "event": [1, 1, 0, 1, 0, 0],
    "age": [45, 60, 55, 70, 50, 65],
    "treatment": [1, 0, 1, 0, 1, 0],
})

cph = CoxPHFitter()
cph.fit(df, duration_col="duration", event_col="event")
cph.print_summary()
cph.plot_partial_effects_on_outcome("treatment", [0, 1])

Weibull Parametric Model

from lifelines import WeibullAFTFitter

wbf = WeibullAFTFitter()
wbf.fit(df, duration_col="duration", event_col="event")
wbf.print_summary()

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.