scientific-skills/Data Analysis/scikit-survival/SKILL.md
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.
npx skillsauth add aipoch/medical-research-skills scikit-survivalInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when you need to:
sksurv.util.Surv (arrays or DataFrame).CoxPHSurvivalAnalysis, CoxnetSurvivalAnalysisRandomSurvivalForest, GradientBoostingSurvivalAnalysis, ExtraSurvivalTreesFastSurvivalSVM, FastKernelSurvivalSVMGridSearchCV with survival scorers.Additional topic guides may exist under:
references/cox-models.mdreferences/ensemble-models.mdreferences/svm-models.mdreferences/data-handling.mdreferences/evaluation-metrics.mdreferences/competing-risks.md
scikit-survival (recommended: >=0.22)scikit-learn (recommended: >=1.2)numpy (recommended: >=1.23)pandas (recommended: >=1.5)A complete, runnable example using a scikit-survival built-in dataset, a scikit-learn pipeline, and Uno’s C-index (IPCW):
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}")
Surv)scikit-survival expects outcomes as a structured array with at least:
Common construction patterns:
from sksurv.util import Surv
y = Surv.from_arrays(event=event_array, time=time_array)
# or
y = Surv.from_dataframe("event", "time", df)
CoxnetSurvivalAnalysis (Elastic Net) for stability and feature selection.CoxPHSurvivalAnalysis (coefficients as log hazard ratios).RandomSurvivalForest or GradientBoostingSurvivalAnalysis.FastKernelSurvivalSVM (ensure scaling).concordance_index_censored): common, but can be less robust with heavy censoring.concordance_index_ipcw): uses inverse probability of censoring weights and requires y_train to estimate censoring distribution.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]
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)
Use competing risks methods when multiple mutually exclusive event types exist and one event prevents the others.
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)
tools
Generates complete conventional oncology bulk-transcriptome biomarker and hub-gene research designs from a user-provided cancer type and study direction. Always use this skill whenever a user wants to design, plan, or build a tumor bioinformatics study centered on differential expression, prognostic filtering or risk modeling, PPI-based hub-gene prioritization, diagnostic/prognostic evaluation, clinical association, immune infiltration context, methylation context, and optional tissue or cell validation. Covers five study patterns (signature-first prognostic workflow, hub-gene-first biomarker workflow, hybrid signature-to-hub workflow, immune-context biomarker workflow, translational validation workflow) and always outputs four workload configs (Lite / Standard / Advanced / Publication+) with recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, publication upgrade path...
development
Generates complete conventional non-oncology bioinformatics research designs from a user-provided disease context, process-related gene family or biological theme, and validation direction. Use when a study centers on multi-dataset bulk transcriptome integration, DEG analysis, process-gene intersection, enrichment analysis, GSEA, PPI hub-gene prioritization, TF/miRNA regulatory networks, ROC-based biomarker evaluation, and immune infiltration analysis. Covers five study patterns (process-DEG discovery, enrichment/GSEA interpretation, hub-gene prioritization, regulatory-network and immune interpretation, multi-layer public validation) and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.
tools
Plans confounder control, variable adjustment logic, and bias mitigation strategies at the protocol stage for clinical, epidemiologic, translational, observational, and biomarker studies. Always use this skill when a user needs to identify major confounders, decide which variables should or should not be adjusted for, compare matching/stratification/weighting approaches, anticipate selection or measurement bias, or pressure-test a study design before execution. Focus on bias sensing, causal structure awareness, variable-role classification, and critical design review rather than generic statistical advice.
testing
Generates complete comparative network-toxicology research designs from a user-provided exposure pair, shared toxic phenotype, and validation direction. Use when a study centers on two related exposures under one outcome and needs target collection, shared-vs-specific target decomposition, enrichment, PPI hub prioritization, docking, optional transcriptomic cross-checks, and conservative mechanistic synthesis. Covers five study patterns and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.