Skip to main content

Random Survival Forest

DOI

The Random Survival Forest package provides a python implementation of the survival prediction method originally published by Ishwaran et al. (2008).

Reference: Ishwaran, H., Kogalur, U. B., Blackstone, E. H., & Lauer, M. S. (2008). Random survival forests. The annals of applied statistics, 2(3), 841-860.

Requirements

Python >= 3.13.

Installation

pip install random-survival-forest

Contribute

Development

Dependencies and environment are managed with uv:

uv sync --group dev     # install the package and dev dependencies
uv run pytest           # run the test suite
uv run ruff check .     # lint
uv run pip-audit        # check dependencies for known vulnerabilities

Performance

The log-rank split search is vectorized with numpy, so training scales well with sample size and number of trees. For very large datasets, n_jobs lets you parallelize tree construction across cores.

Getting Started

import time

from lifelines import datasets
from sklearn.model_selection import train_test_split

from random_survival_forest.models import RandomSurvivalForest
from random_survival_forest.scoring import concordance_index

# Rossi recidivism dataset: "arrest" (1 = rearrested, 0 = censored), "week" = time in weeks.
rossi = datasets.load_rossi()
# y needs the event column first, then time: event before duration.
y = rossi.loc[:, ["arrest", "week"]]
X = rossi.drop(["arrest", "week"], axis=1)
X, X_test, y, y_test = train_test_split(X, y, test_size=0.33, random_state=10)

print("Start training...")
start_time = time.time()
# n_jobs=-1 uses all CPU cores, random_state makes the run reproducible.
rsf = RandomSurvivalForest(n_estimators=50, n_jobs=-1, random_state=42)
rsf = rsf.fit(X, y)
print(f'--- {round(time.time() - start_time, 3)} seconds ---')

# Predicted cumulative hazard function per test sample.
y_pred = rsf.predict(X_test)

# C-index: fraction of comparable pairs ranked correctly (0.5 random, 1.0 perfect).
c_val = concordance_index(y_time=y_test["week"], y_pred=y_pred, y_event=y_test["arrest"])
print(f'C-index {round(c_val, 3)}')

Feedback

If you are having issues or feedback, please let me know. I am happy to fix some bug or implement feature requests.

spaethju@posteo.de

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

random_survival_forest-1.0.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

random_survival_forest-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file random_survival_forest-1.0.0.tar.gz.

File metadata

  • Download URL: random_survival_forest-1.0.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for random_survival_forest-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e0bea209a9b01ef2172e368d529d643c48cbd7641542356bacaca510da6a03aa
MD5 a09a23cb113e6a6fcfe69ba51c252e4c
BLAKE2b-256 f68c9cbecf24f9ee09efe4a27932c13b4393a93427ac9bafcda7d7e66118e890

See more details on using hashes here.

File details

Details for the file random_survival_forest-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: random_survival_forest-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for random_survival_forest-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fc2243b00a0adfb4ccc5772ffb73afb8d9d60a7a2914390fbc656d737103f44
MD5 7452a65c6ebfa05d36a54c6c5d1ad446
BLAKE2b-256 30bbe6f23655947f88e297c8787886d7601c57ad5c38f95e02f6e3dbe6529c67

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.2

2 files

0.7.1

2 files

0.7

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.1

1 file

0.5

2 files

0.4.2

1 file

0.4.1

1 file

0.4

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page