scikit-survival
A comprehensive toolkit for survival analysis and time-to-event modeling in Python using scikit-survival; use it when you need to model censored time-to-event outcomes, fit Cox/RSF/GB models or Survival SVMs, evaluate with C-index/Brier score, or handle competing risks.
Best use case
scikit-survival is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
A comprehensive toolkit for survival analysis and time-to-event modeling in Python using scikit-survival; use it when you need to model censored time-to-event outcomes, fit Cox/RSF/GB models or Survival SVMs, evaluate with C-index/Brier score, or handle competing risks.
Teams using scikit-survival should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/scikit-survival/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How scikit-survival Compares
| Feature / Agent | scikit-survival | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
A comprehensive toolkit for survival analysis and time-to-event modeling in Python using scikit-survival; use it when you need to model censored time-to-event outcomes, fit Cox/RSF/GB models or Survival SVMs, evaluate with C-index/Brier score, or handle competing risks.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
## When to Use
Use this skill when you need to:
1. Model **time-to-event outcomes with censoring** (right/left/interval censored observations).
2. Fit and interpret **Cox Proportional Hazards** models (including **penalized** Cox for high-dimensional data).
3. Train **non-linear survival models** such as **Random Survival Forests** or **Gradient Boosting** survival models.
4. Use **Survival SVMs** for margin-based survival prediction (linear or kernel).
5. Evaluate survival predictions with **censoring-aware metrics** (Uno/Harrell C-index, time-dependent AUC, Brier/Integrated Brier Score) and/or perform **competing risks** analysis.
## Key Features
- **Survival target construction** via `sksurv.util.Surv` (arrays or DataFrame).
- **Model families**
- Cox models: `CoxPHSurvivalAnalysis`, `CoxnetSurvivalAnalysis`
- Ensembles: `RandomSurvivalForest`, `GradientBoostingSurvivalAnalysis`, `ExtraSurvivalTrees`
- SVM-based: `FastSurvivalSVM`, `FastKernelSurvivalSVM`
- **Non-parametric estimators**: Kaplan–Meier and Nelson–Aalen.
- **Competing risks**: cumulative incidence estimation.
- **scikit-learn compatibility**: pipelines, cross-validation, and `GridSearchCV` with survival scorers.
- **Evaluation utilities**: IPCW-based metrics (e.g., Uno’s C-index) and calibration-aware scores (IBS).
> Additional topic guides may exist under:
> - `references/cox-models.md`
> - `references/ensemble-models.md`
> - `references/svm-models.md`
> - `references/data-handling.md`
> - `references/evaluation-metrics.md`
> - `references/competing-risks.md`
## Dependencies
- `scikit-survival` (recommended: `>=0.22`)
- `scikit-learn` (recommended: `>=1.2`)
- `numpy` (recommended: `>=1.23`)
- `pandas` (recommended: `>=1.5`)
## Example Usage
A complete, runnable example using a scikit-survival built-in dataset, a scikit-learn pipeline, and Uno’s C-index (IPCW):
```python
import numpy as np
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sksurv.datasets import load_breast_cancer
from sksurv.linear_model import CoxPHSurvivalAnalysis
from sksurv.metrics import concordance_index_ipcw, as_concordance_index_ipcw_scorer
# 1) Load data (X: features, y: structured array with fields like ('event', 'time'))
X, y = load_breast_cancer()
# 2) Split (keep y_train for IPCW-based metrics)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
# 3) Build a pipeline (scaling is important for many survival models)
pipe = Pipeline([
("scaler", StandardScaler()),
("model", CoxPHSurvivalAnalysis()),
])
# 4) Optional: hyperparameter tuning (CoxPH has few knobs; shown for workflow completeness)
# If your version exposes regularization parameters, tune them here.
param_grid = {
# Example placeholder; remove if unsupported in your installed version:
# "model__alpha": [0.0, 1e-4, 1e-3]
}
if param_grid:
search = GridSearchCV(
pipe,
param_grid=param_grid,
scoring=as_concordance_index_ipcw_scorer(),
cv=5,
n_jobs=-1,
)
search.fit(X_train, y_train)
best = search.best_estimator_
else:
best = pipe.fit(X_train, y_train)
# 5) Predict risk scores (higher typically means higher risk / shorter survival)
risk_scores = best.predict(X_test)
# 6) Evaluate with Uno's C-index (IPCW)
c_uno = concordance_index_ipcw(y_train, y_test, risk_scores)[0]
print(f"Uno's C-index (IPCW): {c_uno:.3f}")
```
## Implementation Details
### 1) Survival Target Representation (`Surv`)
scikit-survival expects outcomes as a **structured array** with at least:
- an **event indicator** (boolean)
- a **time** value (float/int)
Common construction patterns:
```python
from sksurv.util import Surv
y = Surv.from_arrays(event=event_array, time=time_array)
# or
y = Surv.from_dataframe("event", "time", df)
```
### 2) Model Selection Heuristics
- **High-dimensional (p > n)**: prefer `CoxnetSurvivalAnalysis` (Elastic Net) for stability and feature selection.
- **Interpretability required**: prefer `CoxPHSurvivalAnalysis` (coefficients as log hazard ratios).
- **Strong non-linearities / interactions**: prefer `RandomSurvivalForest` or `GradientBoostingSurvivalAnalysis`.
- **Kernelized decision boundaries**: consider `FastKernelSurvivalSVM` (ensure scaling).
### 3) Preprocessing Requirements
- **Scaling**: strongly recommended for SVMs and often beneficial for penalized Cox models.
- **Categoricals**: encode (e.g., one-hot) before fitting most estimators.
- **Data validation**: ensure non-negative times; verify enough events relative to feature count.
### 4) Evaluation Under Censoring
- **Harrell’s C-index** (`concordance_index_censored`): common, but can be less robust with heavy censoring.
- **Uno’s C-index** (`concordance_index_ipcw`): uses **inverse probability of censoring weights** and requires `y_train` to estimate censoring distribution.
```python
from sksurv.metrics import concordance_index_censored, concordance_index_ipcw
c_harrell = concordance_index_censored(y_test["event"], y_test["time"], risk_scores)[0]
c_uno = concordance_index_ipcw(y_train, y_test, risk_scores)[0]
```
### 5) Time-dependent Metrics (AUC, Brier/IBS)
- **Time-dependent AUC** evaluates discrimination at specific time horizons.
- **Brier score / Integrated Brier Score (IBS)** evaluates calibration + discrimination over time and requires survival probabilities/functions.
```python
from sksurv.metrics import cumulative_dynamic_auc
times = np.array([365, 730, 1095]) # example horizons
auc, mean_auc = cumulative_dynamic_auc(y_train, y_test, risk_scores, times)
```
### 6) Competing Risks (Cumulative Incidence)
Use competing risks methods when multiple mutually exclusive event types exist and one event prevents the others.
```python
from sksurv.nonparametric import cumulative_incidence_competing_risks
# y must encode event types appropriately for competing risks workflows
time_points, cif1, cif2 = cumulative_incidence_competing_risks(y)
```Related Skills
survival-curve-risk-table
Analyze data with `survival-curve-risk-table` using a reproducible workflow, explicit validation, and structured outputs for review-ready interpretation.
survival-analysis-km
Kaplan-Meier survival analysis tool for clinical and biological research. Generates publication-ready survival curves with statistical tests.
scikit-bio
A Python bioinformatics toolkit for sequence, phylogeny, and microbiome/community-ecology analysis; use it when you need to compute diversity/ordination/statistics from biological data and standard formats (FASTA/FASTQ/Newick/BIOM).
skill-auditor
A comprehensive auditor for any agent skill — including Manus, OpenClaw/ClawHub, Claude, LobeHub, or custom SKILL.md-based skills. Use this skill whenever a user wants to evaluate, audit, review, score, or quality-check an agent skill before publishing, updating, or deploying. Covers two hard veto gates (structural redlines + research integrity redlines), static quality scoring across 25 criteria (ISO 25010 + OpenSSF + Agent), dynamic test input generation, multi-mode execution testing, multi-layer output evaluation with five specialized category rubrics (Evidence Insight / Protocol Design / Data Analysis / Academic Writing / Other), a Research Veto that applies to all four research categories, human eval viewer generation, actionable P0/P1/P2 optimization recommendations, and automatic skill improvement that outputs a polished, production-ready SKILL.md. Also use whenever a user says "audit my skill", "evaluate my skill", "improve my skill", or wants a corrected version after evaluation.
two-sample-mr-research-planner
Generates complete two-sample Mendelian randomization (MR) research designs from a user-provided research direction. Use when users want to design, plan, or build a study using two-sample MR to test causal relationships. Triggers:"design a two-sample MR study", "build a publishable MR paper", "test whether this biomarker causally affects this disease", "generate Lite/Standard/Advanced MR plans", "screen multiple exposures with MR", "bidirectional MR design", "causal inference using GWAS summary statistics", or "I want to study X and Y using MR". Always outputs four workload configurations (Lite / Standard / Advanced / Publication+) with a recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, and publication upgrade path.
research-proposal-generator
Generates a comprehensive research proposal design based on input literature, including hypothesis, mechanism verification, and budget. Use when the user wants to design a research project from a paper.
research-grants
Write competitive research proposals for NSF, NIH, DOE, DARPA, and Taiwan's NSTC when you need agency-compliant narratives, budgets, and review-criteria alignment for a specific solicitation/FOA/BAA.
protocol-standardization
Standardize fragmented experimental steps into reproducible protocol documents when you need method organization, lab SOP drafting, or cross-operator reproducibility; missing parameters must be explicitly marked as "To be supplemented/Not provided".
prospero-registration-helper
Assists researchers in generating PROSPERO registration content for meta-analyses from a title and optional protocol. Use when the user wants to draft a PROSPERO registration form.
non-tumor-ml-research-planner
Generates complete non-tumor biomedical machine learning research designs from a user-provided research direction. Always use this skill when users want to plan bioinformatics + ML papers for non-cancer diseases (metabolic, cardiovascular, kidney, inflammatory, autoimmune, infectious, neurological, endocrine, wound healing, chronic multifactor), design diagnostic biomarker studies, combine GEO datasets with feature selection and ML modeling, or generate Lite/Standard/Advanced/Publication+ workload plans. Trigger for:"non-tumor ML study", "bioinformatics paper outside oncology", "key genes and diagnostic model for a disease", "pyroptosis/ferroptosis/senescence/autophagy + disease", "GEO datasets + machine learning", "RF + LASSO diagnostic model", "DEG + feature selection + validation", "immune infiltration + biomarker", "non-cancer biomarker paper". Trigger even for casual phrasings like "I want to study X using machine learning", "help me design a non-tumor bioinformatics paper", or "how do I build a diagnostic model for disease Y".
network-tox-docking-research-planner
Generates complete network toxicology + molecular docking research designs from a user-provided toxicant and disease/phenotype. Always use this skill when users want to investigate how an environmental toxicant, endocrine disruptor, heavy metal, food contaminant, pharmaceutical residue, or consumer product chemical may contribute to a disease through shared molecular targets, hub genes, pathways, and docking evidence. Trigger for:"network toxicology study", "toxicology mechanism paper", "target prediction + PPI + docking", "environmental pollutant and disease mechanism", "hub genes and docking for toxicant", "Lite/Standard/Advanced toxicology plan", "CTD + SwissTargetPrediction + GeneCards + STRING", "CB-Dock2 docking study", "triclosan/BPA/cadmium/PFAS + disease". Also triggers for Chinese phrasings:"网络毒理学研究设计"、"毒物机制论文"、"靶点预测+PPI+对接"、"环境污染物与疾病机制". Trigger even for casual phrasings like "I want to study how chemical X affects disease Y" or "help me design a toxicology paper". Always output four workload configurations (Lite / Standard / Advanced / Publication+) with a recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, and publication upgrade path.
meta-protocol-writer
Generates a PROSPERO-compliant Meta-analysis protocol based on Title and PICOS. Use when the user wants to write a protocol for a systematic review or meta-analysis.