Upgrading survival models with CARE
Project description
care-survival
Upgrading survival models with CARE.
This repository contains a Python implementation of the methodology proposed by Underwood, Reeve, Feng, Lambert, Mukherjee and Samworth, 2025.
Building the Python package
This project uses
uv
to manage Python dependencies.
To build the Python package, run uv build.
To update the lockfile, use uv lock.
Running the simulation scripts
For running scripts,
just
and parallel
should be installed.
To execute all of the simulations and generate the plots,
run just.
The recipes can be found in the
justfile.
The scripts to run the SCORE2 data analysis are also available in the bin directory, but require access to UK Biobank data.
Example usage
import numpy as np
import care_survival
# generate some sample data
n = 60
d = 2
X = np.random.random((n, d))
T = X.sum(axis=1) + 1 + np.random.random(n)
I = (np.random.random(n) > 0.8) * 1
f = (-X.sum(axis=1) / 2 + np.random.random(n)).reshape(-1, 1)
# split data into training and validation sets
n_train = int(np.ceil(n / 2))
X_train = X[0:n_train]
T_train = T[0:n_train]
I_train = I[0:n_train]
f_train = f[0:n_train]
X_valid = X[n_train:n]
T_valid = T[n_train:n]
I_valid = I[n_train:n]
f_valid = f[n_train:n]
# define a kernel and use the feature map optimisation method
a = 1
p = 2
kernel = care_survival.PolynomialKernel(a, p)
method = "feature_map"
# set up the kernel tuning parameters
n_gammas = 20
gamma_min = 1e-6
gamma_max = 1e1
# set up the simplex tuning parameters
simplex_resolution = 0.05
# compute concordance score on all data
with_concordance = ["train", "valid"]
# fit CARE
care = care_survival.care(
X_train,
T_train,
I_train,
f_train,
X_valid,
T_valid,
I_valid,
f_valid,
kernel,
method,
n_gammas,
gamma_min,
gamma_max,
simplex_resolution,
with_concordance,
)
# view diagnostics
best = care.best["aggregated"]["ln"]["valid"]
print("best theta value:", best.theta)
print("best gamma value:", best.gamma)
print("concordance index:", best.score["concordance"]["valid"])
Publishing to PyPI
First build the package with
uv build
To publish to TestPyPI with an API token, run
uv publish --index testpypi --token <token>
To publish to PyPI with an API token, run
uv publish --token <token>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file care_survival-0.1.2.tar.gz.
File metadata
- Download URL: care_survival-0.1.2.tar.gz
- Upload date:
- Size: 71.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1af8012c0a8f2e390c5a00c1487fab33d1114c7c7b91e7278554237ed91f526b
|
|
| MD5 |
48348d8f02360c13864854a953927560
|
|
| BLAKE2b-256 |
595ad152d516c5782a00f399c91c1291e9be678c752d8763a0fb4bf7ce225c53
|
File details
Details for the file care_survival-0.1.2-py3-none-any.whl.
File metadata
- Download URL: care_survival-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04c65e2cb70c3dea8ee4b1fc259b033e3134acf90ee1e8200b77ac9193e92778
|
|
| MD5 |
befd6f18d00a0d7bddc590175d465e8a
|
|
| BLAKE2b-256 |
bf51de326141f5b0787ac5370f0b6a18a3457ddc8a8be52b42bf226023485780
|