Install & Compatibility
Where this runs
tested against v0.30.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 3.600s · 405.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 18.3s · import 3.526s · 388MB
413MB installed
● package 413MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
KaplanMeierFitter
✓ from lifelines import KaplanMeierFitter
CoxPHFitter
✓ from lifelines import CoxPHFitter
WeibullFitter
✓ from lifelines import WeibullFitter
NelsonAalenFitter
✓ from lifelines import NelsonAalenFitter
This quickstart demonstrates fitting a Kaplan-Meier survival model and a Cox Proportional Hazards regression model. It generates synthetic duration and event data, then visualizes the Kaplan-Meier survival curve and prints a summary for the Cox model.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from lifelines import KaplanMeierFitter, CoxPHFitter
# --- Kaplan-Meier Fitter Example ---
np.random.seed(42)
num_samples = 100
T = np.random.exponential(scale=10, size=num_samples) # Durations
E = np.random.binomial(n=1, p=0.7, size=num_samples) # Events (0=censored, 1=event)
kmf = KaplanMeierFitter()
kmf.fit(T, event_observed=E, label="Sample Survival Function")
print("Kaplan-Meier Survival Function (first 5 rows):\n", kmf.survival_function_.head())
kmf.plot_survival_function()
plt.title("Kaplan-Meier Survival Estimate")
plt.xlabel("Time")
plt.ylabel("Survival Probability")
plt.grid(True)
plt.show()
# --- Cox Proportional Hazards Fitter Example ---
data = pd.DataFrame({
'T': T, # Duration
'E': E, # Event observed
'age': np.random.randint(20, 70, num_samples),
'sex': np.random.choice(, num_samples, p=[0.55, 0.45])
})
cph = CoxPHFitter()
cph.fit(data, duration_col='T', event_col='E', formula="age + sex")
print("\nCoxPHFitter Summary:\n")
cph.print_summary()
Debug
Known issues
breakingThe `sklean_adaptor` module was removed in version 0.28.0. There is no direct replacement, simplifying the library's API.fixRemove any dependencies on `sklean_adaptor`. If scikit-learn compatibility is needed, consider `scikit-survival` or manual integration.
affects: >=0.28.0
breakingMinimum Python version requirements have increased. Version 0.28.0 dropped support for Python < 3.9, and version 0.30.3 requires Python >= 3.11.fixEnsure your Python environment is running version 3.11 or higher to use the latest `lifelines` releases.
affects: >=0.28.0, >=0.30.3
deprecatedThe `initial_beta` parameter in `CoxPHFitter.fit()` was renamed to `initial_point` to align with a more general concept across models.fixUpdate calls from `initial_beta=...` to `initial_point=...` when fitting CoxPH models.
affects: >=0.27.8
deprecatedThe `plot_covariate_groups` method was renamed to `plot_partial_effects_on_outcome` and its behavior for transformed variables changed with the introduction of R-like formulas.fixUse `plot_partial_effects_on_outcome` instead. Review the documentation for its usage, especially with formula-based models, as its behavior for transformed variables is different.
affects: Prior to ~0.27.0
gotchaWhen using `CoxPHFitter`, avoid including a column of all 1s (an explicit intercept) in your DataFrame or formula. The Cox model implicitly handles a baseline, and an explicit intercept can lead to warnings or convergence errors.fixDo not manually add an intercept column. `lifelines` handles the baseline hazard implicitly. For example, if using R-like formulas, simply list covariates without adding a `1`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'lifelines'
The 'lifelines' library is not installed in the Python environment being used, or the environment in which it was installed is not active, particularly common in Jupyter notebooks with multiple kernels.
fixInstall the library using pip: `pip install lifelines` or `conda install -c conda-forge lifelines` if using Anaconda.
ValueError: This model does not allow for non-positive durations. Suggestion: add a small positive value to zero elements.
Survival analysis models in `lifelines` typically require positive durations, but the provided 'duration_col' contains zero or negative values.
fixEnsure all values in your duration column are strictly positive. If there are zeros, add a small positive value (e.g., a tiny epsilon) to them, or filter out non-positive durations if they are not meaningful for your analysis.
ConvergenceError: Convergence halted due to matrix inversion problems. Suspicion is high `collinearity`.
This error in `CoxPHFitter` indicates issues during the iterative optimization process (Newton-Raphson), often due to high collinearity among covariates in the dataset, perfectly separated data, or a small dataset size when using cross-validation.
fixTo fix this, identify and remove highly correlated features, ensure there isn't perfect separation in your data, try adding a penalizer to the model (e.g., `CoxPHFitter(penalizer=0.1)`), or if using cross-validation, increase the `cv` folds or ensure sufficient data in each fold.
KeyError: "None of [Index(['At risk', 'Censored', 'Events'], dtype='object')] are in the [index]"
This error typically occurs when using `lifelines.plotting.add_at_risk_counts()` with an incompatible version of the Pandas library, where column names or indexing behavior have changed.
fixUpgrade your Pandas library to a version compatible with your `lifelines` installation, or downgrade it if a specific older version of `lifelines` requires it. Checking the `lifelines` documentation for recommended Pandas versions is also helpful.
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
This Pandas-related `ValueError` happens when a `pandas.Series` object is used in a boolean context (e.g., in an `if` statement or as a direct argument) where a single boolean value or a scalar is expected, often when passing Series directly as arguments to `lifelines` fit methods without extracting their underlying values.
fixWhen passing duration or event columns to `lifelines` fitters, extract the underlying NumPy array using `.values` or convert to a list, e.g., `kmf.fit(T.values, event_observed=E.values)` instead of `kmf.fit(T, event_observed=E)`.
Upgrade
Version history
0.30.3latest on PyPI · released Mar 5, 2026
Audit
Dependencies
numpyrequiredFundamental for numerical operations and data handling.
pandasrequiredCore for data structures (DataFrames) used throughout the library.
scipyrequiredUsed for scientific computing, including statistical functions.
matplotlibrequiredEssential for built-in plotting functionalities.
autograd-gammarequiredUsed for automatic differentiation in some models.