{"id":2568,"library":"lifelines","title":"lifelines","description":"lifelines is a comprehensive Python library for survival analysis, offering implementations of various models including Kaplan-Meier, Nelson-Aalen, and Cox proportional hazards regression. It is actively maintained with regular releases, providing tools for handling right, left, and interval censored data, and includes internal plotting methods for easy visualization. The current version is 0.30.3.","status":"active","version":"0.30.3","language":"en","source_language":"en","source_url":"https://github.com/CamDavidsonPilon/lifelines","tags":["survival analysis","statistics","time-to-event","kaplan-meier","cox-regression"],"install":[{"cmd":"pip install lifelines","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Fundamental for numerical operations and data handling.","package":"numpy"},{"reason":"Core for data structures (DataFrames) used throughout the library.","package":"pandas"},{"reason":"Used for scientific computing, including statistical functions.","package":"scipy"},{"reason":"Essential for built-in plotting functionalities.","package":"matplotlib"},{"reason":"Used for automatic differentiation in some models.","package":"autograd-gamma"}],"imports":[{"symbol":"KaplanMeierFitter","correct":"from lifelines import KaplanMeierFitter"},{"symbol":"CoxPHFitter","correct":"from lifelines import CoxPHFitter"},{"symbol":"WeibullFitter","correct":"from lifelines import WeibullFitter"},{"symbol":"NelsonAalenFitter","correct":"from lifelines import NelsonAalenFitter"}],"quickstart":{"code":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom lifelines import KaplanMeierFitter, CoxPHFitter\n\n# --- Kaplan-Meier Fitter Example ---\nnp.random.seed(42)\nnum_samples = 100\nT = np.random.exponential(scale=10, size=num_samples) # Durations\nE = np.random.binomial(n=1, p=0.7, size=num_samples)  # Events (0=censored, 1=event)\n\nkmf = KaplanMeierFitter()\nkmf.fit(T, event_observed=E, label=\"Sample Survival Function\")\n\nprint(\"Kaplan-Meier Survival Function (first 5 rows):\\n\", kmf.survival_function_.head())\nkmf.plot_survival_function()\nplt.title(\"Kaplan-Meier Survival Estimate\")\nplt.xlabel(\"Time\")\nplt.ylabel(\"Survival Probability\")\nplt.grid(True)\nplt.show()\n\n# --- Cox Proportional Hazards Fitter Example ---\ndata = pd.DataFrame({\n    'T': T, # Duration\n    'E': E, # Event observed\n    'age': np.random.randint(20, 70, num_samples),\n    'sex': np.random.choice(, num_samples, p=[0.55, 0.45])\n})\n\ncph = CoxPHFitter()\ncph.fit(data, duration_col='T', event_col='E', formula=\"age + sex\")\n\nprint(\"\\nCoxPHFitter Summary:\\n\")\ncph.print_summary()","lang":"python","description":"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."},"warnings":[{"fix":"Remove any dependencies on `sklean_adaptor`. If scikit-learn compatibility is needed, consider `scikit-survival` or manual integration.","message":"The `sklean_adaptor` module was removed in version 0.28.0. There is no direct replacement, simplifying the library's API.","severity":"breaking","affected_versions":">=0.28.0"},{"fix":"Ensure your Python environment is running version 3.11 or higher to use the latest `lifelines` releases.","message":"Minimum Python version requirements have increased. Version 0.28.0 dropped support for Python < 3.9, and version 0.30.3 requires Python >= 3.11.","severity":"breaking","affected_versions":">=0.28.0, >=0.30.3"},{"fix":"Update calls from `initial_beta=...` to `initial_point=...` when fitting CoxPH models.","message":"The `initial_beta` parameter in `CoxPHFitter.fit()` was renamed to `initial_point` to align with a more general concept across models.","severity":"deprecated","affected_versions":">=0.27.8"},{"fix":"Use `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.","message":"The `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.","severity":"deprecated","affected_versions":"Prior to ~0.27.0"},{"fix":"Do 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`.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}