Registry / ai-ml / scikit-survival

scikit-survival

JSON →
library0.27.0pypypi✓ verified 84d ago

Scikit-survival is a Python library for survival analysis built on top of scikit-learn. It provides various survival models like Cox proportional hazards, random survival forests, and gradient boosting, along with utility functions for data preparation and evaluation. The current version is 0.27.0, and it follows an active release cadence, frequently updating to support newer versions of scikit-learn, NumPy, and pandas.

pip install scikit-survival
INSTALL
IMPORT
SIG · SCIKIT-SURVIVAL
S
scikit-survival
ai-mlpythonv0.27.0
Install
14.4s avg
Import
4254ms
Disk
374MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.25.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
musl
glibc
py 3.10
✕ build_error
✓ 13.63s
py 3.11
✕ build_error
✓ 13.28s
py 3.12
✕ build_error
✓ 14.4s
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 16.2s
374MB installed
● package 374MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RandomSurvivalForest
from sksurv.ensemble import RandomSurvivalForest
CoxPHSurvivalAnalysis
from sksurv.linear_model import CoxPHSurvivalAnalysis
load_whas500
from sksurv.datasets import load_whas500
concordance_index_censored
from sksurv.metrics import concordance_index_censored

This quickstart loads the WHAS500 dataset, prepares it for survival analysis, trains a RandomSurvivalForest model, and demonstrates prediction of survival functions and calculation of the concordance index. Note the use of a structured NumPy array for the `y` target, which is characteristic of survival analysis in scikit-survival.

import numpy as np from sksurv.datasets import load_whas500 from sksurv.ensemble import RandomSurvivalForest X, y = load_whas500() # Split data (simple for quickstart) X_train, X_test = X.iloc[:300], X.iloc[300:] y_train, y_test = y[:300], y[300:] # Initialize and fit a Random Survival Forest model rsf = RandomSurvivalForest( n_estimators=100, min_samples_leaf=20, random_state=42 ) rsf.fit(X_train, y_train) # Predict survival functions and calculate concordance index surv_fns = rsf.predict_survival_function(X_test, return_array=True) preds = rsf.predict(X_test) from sksurv.metrics import concordance_index_censored c_index = concordance_index_censored(y_test['fstat'], y_test['lenfol'], preds)[0] print(f"Predicted survival for first test sample: {surv_fns[0, :5].round(2)}") print(f"Concordance Index (C-index): {c_index:.3f}")
Debug
Known issues
breakingScikit-survival frequently updates its minimum required versions for core dependencies like scikit-learn, pandas, numpy, and python. Using an older `sksurv` version with a newer dependency (or vice-versa) can lead to `ImportError`, `AttributeError`, or `TypeError` due to API mismatches.
fix
Always check the release notes for the `sksurv` version you are using or planning to use. Ensure all your dependencies (`scikit-learn`, `pandas`, `numpy`, `scipy`, `python`) meet the minimum requirements for your `sksurv` version. Upgrading `sksurv` often requires upgrading its dependencies simultaneously.
affects: All versions, specifically when updating adjacent libraries.
gotchaThe target variable `y` in scikit-survival models must be a structured NumPy array (or pandas DataFrame with matching dtypes) containing two fields: one boolean for the 'event' (e.g., 'fstat') and one float for the 'time' (e.g., 'lenfol'). Passing a simple NumPy array or pandas Series will raise a `TypeError`.
fix
Ensure `y` is a structured array, typically created from event/time columns. Example: `y = np.array([(e, t) for e, t in zip(events, times)], dtype=[('fstat', 'bool'), ('lenfol', 'float')])` or loading from a dataset like `sksurv.datasets.load_whas500()` which provides it in the correct format.
affects: All versions
breakingVersion 0.24.1 restricted the `osqp` dependency to versions less than 1.0.0 (`osqp<1.0.0`). However, subsequent versions (e.g., 0.26.0 and later) explicitly support and require `osqp>=1.0.2`. Installing `osqp` with the wrong version for your `sksurv` release can lead to runtime errors when using models that rely on it.
fix
For `sksurv>=0.26.0`, ensure `osqp>=1.0.2` is installed. If using `sksurv=0.24.1`, ensure `osqp<1.0.0`. It's best to let `pip` resolve dependencies or explicitly install compatible versions: `pip install 'osqp>=1.0.2'` for current `sksurv`.
affects: Versions 0.24.1, 0.26.0, 0.27.0 (and potentially others around this range).
gotchaSome models, particularly tree-based ones like `SurvivalTree` or `RandomSurvivalForest`, gained missing value support in recent `sksurv` releases (e.g., v0.22.0 for `SurvivalTree`, v0.23.0 for `RandomSurvivalForest`) due to underlying scikit-learn updates. Older `sksurv` versions or incompatible scikit-learn versions might not handle `np.nan` values correctly.
fix
If working with missing values in `X`, ensure you are using `sksurv>=0.23.0` (with compatible `scikit-learn`) for robust support across tree-based models. Otherwise, explicitly handle missing values (imputation, dropping rows) before passing `X` to the model.
affects: Prior to v0.23.0 for `RandomSurvivalForest`, prior to v0.22.0 for `SurvivalTree`.
Errors
Common errors & fixes
TypeError: A structured array must be used to define the response. Found array of dtype <class 'numpy.int64'>
The target variable `y` was passed as a simple NumPy array or pandas Series, instead of the required structured array format (e.g., `dtype=[('fstat', 'bool'), ('lenfol', 'float')])`).
fix
Convert your event and time data into a structured NumPy array. Example: `y_structured = np.array(list(zip(events, times)), dtype=[('event', 'bool'), ('time', 'float')])`.
ModuleNotFoundError: No module named 'sksurv'
The `scikit-survival` package is not installed in the current Python environment, or the environment is not active.
fix
Install the package using pip: `pip install scikit-survival`. If using a virtual environment, ensure it is activated.
ImportError: cannot import name '...' from 'sklearn.tree._criterion'
This usually indicates an incompatibility between your `scikit-survival` version and your installed `scikit-learn` version. `sksurv` relies heavily on scikit-learn's internal APIs, which can change between major versions.
fix
Check the `scikit-survival` release notes for the exact `scikit-learn` version range it supports. Upgrade or downgrade `scikit-learn` (and potentially `sksurv`) to a compatible version. For example, `pip install 'scikit-learn>=1.8.0,<1.9.0' scikit-survival` for v0.27.0.
OSError: scikit-survival failed to load its C++ extension module.
This error occurs when the underlying C++/Cython extensions of `scikit-survival` could not be built or loaded correctly. This can happen due to missing build tools (e.g., C++ compiler), incompatible Python versions, or corrupted installations.
fix
Ensure you have a C++ compiler installed (e.g., Build Tools for Visual Studio on Windows, `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS). Reinstall `scikit-survival` with `pip install --no-cache-dir --force-reinstall scikit-survival` in a clean environment.
Upgrade
Version history
0.27.0latest on PyPI · released Feb 2, 2026
Audit
Dependencies
scikit-learnrequiredCore dependency, providing base estimators and utilities.
pandasrequiredUsed for data handling and structured array creation.
numpyrequiredFundamental package for numerical computing.
scipyrequiredUsed for scientific computing, particularly optimization and statistics.
osqprequiredRequired by some models for quadratic programming (e.g., Coxnet).
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources