scikit-survival · diff
git:20260611.1b8fae3 to v1.1
238 added, 321 removed. Audit A to A.
---
name: scikit-survival
- description: Comprehensive toolkit for survival analysis and time-to-event modeling in Python using scikit-survival. Use this skill when working with censored survival data, performing time-to-event analysis, fitting Cox models, Random Survival Forests, Gradient Boosting models, or Survival SVMs, evaluating survival predictions with concordance index or Brier score, handling competing risks, or implementing any survival analysis workflow with the scikit-survival library.
- license: GPL-3.0 license
- metadata: {"version": "1.0", "skill-author": "K-Dense Inc."}
+ description: Build, evaluate, and audit right-censored or competing-risk survival workflows with scikit-survival, including leakage-safe preprocessing, model selection, probability prediction, and censoring-aware metrics.
+ license: MIT
+ compatibility: Requires Python 3.11+, uv, and the pinned scikit-survival 0.28.0 stack for executable examples. Bundled CLIs are local and network-free by default.
+ allowed-tools: Read, Write, Edit, Bash
+ metadata:
+ version: "1.1"
+ skill-author: K-Dense Inc.
---
- # scikit-survival: Survival Analysis in Python
-
- ## Overview
-
- scikit-survival is a Python library for survival analysis built on top of scikit-learn. It provides specialized tools for time-to-event analysis, handling the unique challenge of censored data where some observations are only partially known.
-
- Survival analysis aims to establish connections between covariates and the time of an event, accounting for censored records (particularly right-censored data from studies where participants don't experience events during observation periods).
-
- ## When to Use This Skill
-
- Use this skill when:
- - Performing survival analysis or time-to-event modeling
- - Working with censored data (right-censored, left-censored, or interval-censored)
- - Fitting Cox proportional hazards models (standard or penalized)
- - Building ensemble survival models (Random Survival Forests, Gradient Boosting)
- - Training Survival Support Vector Machines
- - Evaluating survival model performance (concordance index, Brier score, time-dependent AUC)
- - Estimating Kaplan-Meier or Nelson-Aalen curves
- - Analyzing competing risks
- - Preprocessing survival data or handling missing values in survival datasets
- - Conducting any analysis using the scikit-survival library
+ # scikit-survival
- ## Core Capabilities
+ ## Scope
- ### 1. Model Types and Selection
+ Use this skill for scikit-survival 0.28.0 workflows involving:
- scikit-survival provides multiple model families, each suited for different scenarios:
+ - right-censored structured outcomes;
+ - Cox PH, Coxnet, IPC ridge, survival trees, forests, boosting, and SVMs;
+ - discrimination, prediction error, calibration-oriented checks, and time-dependent prediction;
+ - nonparametric cumulative incidence with competing risks;
+ - scikit-learn pipelines, nested model selection, and reproducible reports.
- #### Cox Proportional Hazards Models
- **Use for**: Standard survival analysis with interpretable coefficients
- - `CoxPHSurvivalAnalysis`: Basic Cox model
- - `CoxnetSurvivalAnalysis`: Penalized Cox with elastic net for high-dimensional data
- - `IPCRidge`: Ridge regression for accelerated failure time models
+ scikit-survival primarily models right-censored outcomes. Its built-in competing-risk
+ support is nonparametric cumulative incidence; it does not provide Fine-Gray regression.
+ Do not present model output as clinical advice, causal evidence, or proof of clinical
+ utility.
- **See**: `references/cox-models.md` for detailed guidance on Cox models, regularization, and interpretation
+ ## Current release and installation
- #### Ensemble Methods
- **Use for**: High predictive performance with complex non-linear relationships
- - `RandomSurvivalForest`: Robust, non-parametric ensemble method
- - `GradientBoostingSurvivalAnalysis`: Tree-based boosting for maximum performance
- - `ComponentwiseGradientBoostingSurvivalAnalysis`: Linear boosting with feature selection
- - `ExtraSurvivalTrees`: Extremely randomized trees for additional regularization
+ Verified 2026-07-23:
- **See**: `references/ensemble-models.md` for comprehensive guidance on ensemble methods, hyperparameter tuning, and when to use each model
+ - Latest stable: **scikit-survival 0.28.0**, released 2026-07-05.
+ - Python: **3.11 or later**; PyPI wheels cover CPython 3.11-3.14 on Linux
+ x86-64, macOS x86-64/ARM64, and Windows x86-64.
+ - Runtime bounds: NumPy >=2.0.0, pandas >=2.2.0, SciPy >=1.13.0,
+ scikit-learn >=1.9.0,<1.10, OSQP >=1.0.2, narwhals >=2.0.1.
+ - 0.28 adds pandas/Polars estimator support through narwhals and removes
+ `criterion` from `GradientBoostingSurvivalAnalysis`.
- #### Survival Support Vector Machines
- **Use for**: Medium-sized datasets with margin-based learning
- - `FastSurvivalSVM`: Linear SVM optimized for speed
- - `FastKernelSurvivalSVM`: Kernel SVM for non-linear relationships
- - `HingeLossSurvivalSVM`: SVM with hinge loss
- - `ClinicalKernelTransform`: Specialized kernel for clinical + molecular data
+ Create an isolated environment and install the tested snapshot:
- **See**: `references/svm-models.md` for detailed SVM guidance, kernel selection, and hyperparameter tuning
+ ```bash
+ uv venv --python 3.11
+ source .venv/bin/activate
+ uv pip install \
+ "scikit-survival==0.28.0" \
+ "scikit-learn==1.9.0" \
+ "numpy==2.4.6" \
+ "pandas==3.0.5" \
+ "scipy==1.17.1" \
+ "ecos==2.0.14" \
+ "osqp==1.1.3" \
+ "joblib==1.5.3" \
+ "numexpr==2.14.2" \
+ "narwhals==2.24.0"
+ ```
- #### Model Selection Decision Tree
+ Binary wheels are preferred. A source build requires a C/C++ compiler; OSQP may
+ also require CMake. This skill is MIT-licensed; the upstream scikit-survival package
+ is GPL-3.0-or-later, so review upstream licensing before redistribution.
- ```
- Start
- ├─ High-dimensional data (p > n)?
- │ ├─ Yes → CoxnetSurvivalAnalysis (elastic net)
- │ └─ No → Continue
- │
- ├─ Need interpretable coefficients?
- │ ├─ Yes → CoxPHSurvivalAnalysis or ComponentwiseGradientBoostingSurvivalAnalysis
- │ └─ No → Continue
- │
- ├─ Complex non-linear relationships expected?
- │ ├─ Yes
- │ │ ├─ Large dataset (n > 1000) → GradientBoostingSurvivalAnalysis
- │ │ ├─ Medium dataset → RandomSurvivalForest or FastKernelSurvivalSVM
- │ │ └─ Small dataset → RandomSurvivalForest
- │ └─ No → CoxPHSurvivalAnalysis or FastSurvivalSVM
- │
- └─ For maximum performance → Try multiple models and compare
- ```
+ ## Non-negotiable workflow
- ### 2. Data Preparation and Preprocessing
+ 1. **Define the estimand and event coding.** Decide whether the target is
+ all-event survival, cause-specific hazard, or cause-specific cumulative incidence.
+ 2. **Validate outcomes.** Standard estimators need a two-field structured array:
+ boolean event first, observed time second. Competing-risk CIF instead needs a
+ separate integer event vector: 0=censored, 1..K=causes.
+ 3. **Split before learned preprocessing.** Never fit imputers, encoders, scalers,
+ feature selectors, or alpha choices on all rows before splitting.
+ 4. **Fit preprocessing inside a pipeline.** Unknown categories and missingness must
+ be handled using training-fold state only.
+ 5. **Tune without reusing evaluation data.** Use nested CV when reporting
+ cross-validated tuned performance, or reserve a truly untouched final holdout.
+ 6. **Fit censoring distributions on training data.** IPCW concordance, dynamic AUC,
+ and Brier metrics receive `survival_train`, never a pooled train+test outcome.
+ 7. **Restrict evaluation times.** Use a strictly increasing grid inside test
+ follow-up and below the end of training support where the estimated censoring
+ survival remains positive.
+ 8. **Match predictions to metrics.** Concordance/dynamic AUC consume higher-is-riskier
+ scores. Brier metrics consume survival probabilities with shape
+ `(n_test, n_times)`, not risk scores or unevaluated step functions.
+ 9. **Handle competing causes explicitly.** Standard survival probabilities and CIFs
+ answer different questions. Never estimate event-specific probability with
+ `1 - Kaplan-Meier` while censoring competing events.
+ 10. **Report limits.** Separate discrimination, calibration, prediction error,
+ and cumulative incidence. None alone establishes decision or clinical utility.
- Before modeling, properly prepare survival data:
+ ## Outcome construction
- #### Creating Survival Outcomes
```python
from sksurv.util import Surv
- # From separate arrays
- y = Surv.from_arrays(event=event_array, time=time_array)
-
- # From DataFrame
- y = Surv.from_dataframe('event', 'time', df)
+ y = Surv.from_arrays(event=event_bool, time=observed_time)
+ # Equivalent for pandas or Polars:
+ y = Surv.from_dataframe("event", "time", frame)
```
- #### Essential Preprocessing Steps
- 1. **Handle missing values**: Imputation strategies for features
- 2. **Encode categorical variables**: One-hot encoding or label encoding
- 3. **Standardize features**: Critical for SVMs and regularized Cox models
- 4. **Validate data quality**: Check for negative times, sufficient events per feature
- 5. **Train-test split**: Maintain similar censoring rates across splits
-
- **See**: `references/data-handling.md` for complete preprocessing workflows, data validation, and best practices
-
- ### 3. Model Evaluation
-
- Proper evaluation is critical for survival models. Use appropriate metrics that account for censoring:
-
- #### Concordance Index (C-index)
- Primary metric for ranking/discrimination:
- - **Harrell's C-index**: Use for low censoring (<40%)
- - **Uno's C-index**: Use for moderate to high censoring (>40%) - more robust
-
- ```python
- from sksurv.metrics import concordance_index_censored, concordance_index_ipcw
-
- # Harrell's C-index
- c_harrell = concordance_index_censored(y_test['event'], y_test['time'], risk_scores)[0]
-
- # Uno's C-index (recommended)
- c_uno = concordance_index_ipcw(y_train, y_test, risk_scores)[0]
- ```
+ The first field is boolean (`True`=event, `False`=right-censored); the second is
+ floating-point time. Field names may vary, but field order and meaning may not.
+ Use `references/data-handling.md` before loading custom or competing-risk data.
- #### Time-Dependent AUC
- Evaluate discrimination at specific time points:
+ ## Leakage-safe pipeline
```python
- from sksurv.metrics import cumulative_dynamic_auc
-
- times = [365, 730, 1095] # 1, 2, 3 years
- auc, mean_auc = cumulative_dynamic_auc(y_train, y_test, risk_scores, times)
- ```
-
- #### Brier Score
- Assess both discrimination and calibration:
+ from sklearn.compose import ColumnTransformer
+ from sklearn.impute import SimpleImputer
+ from sklearn.model_selection import train_test_split
+ from sklearn.pipeline import make_pipeline
+ from sklearn.preprocessing import OneHotEncoder, StandardScaler
+ from sksurv.linear_model import CoxPHSurvivalAnalysis
- ```python
- from sksurv.metrics import integrated_brier_score
+ X_train, X_test, y_train, y_test = train_test_split(
+ X, y, test_size=0.25, stratify=y["event"], random_state=20260723
+ )
- ibs = integrated_brier_score(y_train, y_test, survival_functions, times)
+ preprocess = ColumnTransformer(
+ [
+ ("num", make_pipeline(SimpleImputer(strategy="median"), StandardScaler()), numeric),
+ (
+ "cat",
+ make_pipeline(
+ SimpleImputer(strategy="most_frequent"),
+ OneHotEncoder(handle_unknown="ignore", drop="first", sparse_output=False),
+ ),
+ categorical,
+ ),
+ ],
+ sparse_threshold=0.0,
+ )
+ model = make_pipeline(preprocess, CoxPHSurvivalAnalysis(alpha=0.1, ties="efron"))
+ model.fit(X_train, y_train)
+ risk = model.predict(X_test)
```
- **See**: `references/evaluation-metrics.md` for comprehensive evaluation guidance, metric selection, and using scorers with cross-validation
-
- ### 4. Competing Risks Analysis
-
- Handle situations with multiple mutually exclusive event types:
-
- ```python
- from sksurv.nonparametric import cumulative_incidence_competing_risks
-
- # Estimate cumulative incidence for each event type
- time_points, cif_event1, cif_event2 = cumulative_incidence_competing_risks(y)
- ```
+ The split precedes every learned transformation. For repeated or grouped records,
+ use a group-aware split; for temporal deployment, use a time-respecting split.
- **Use competing risks when**:
- - Multiple mutually exclusive event types exist (e.g., death from different causes)
- - Occurrence of one event prevents others
- - Need probability estimates for specific event types
+ ## Model choice
- **See**: `references/competing-risks.md` for detailed competing risks methods, cause-specific hazard models, and interpretation
+ - `CoxPHSurvivalAnalysis`: interpretable log-hazard coefficients under proportional
+ hazards; `alpha` is ridge shrinkage and `ties` is `"breslow"` or `"efron"`.
+ - `CoxnetSurvivalAnalysis`: LASSO/elastic-net path for high-dimensional data.
+ `l1_ratio` is in `(0, 1]`; use `fit_baseline_model=True` before requesting
+ survival or cumulative-hazard functions.
+ - `IPCRidge`: IPC-weighted ridge AFT model; prediction is on a time/log-time scale,
+ not a Cox risk score.
+ - `RandomSurvivalForest` / `ExtraSurvivalTrees`: nonlinear survival and cumulative
+ hazard predictions; use permutation importance, not impurity importance.
+ - `GradientBoostingSurvivalAnalysis`: tree boosting with `"coxph"`, `"squared"`,
+ or `"ipcwls"` loss. `criterion` was removed in 0.28.
+ - `ComponentwiseGradientBoostingSurvivalAnalysis`: sparse linear componentwise
+ boosting.
+ - `FastSurvivalSVM` / `FastKernelSurvivalSVM`: ranking or regression objectives.
+ Only `rank_ratio=1` directly returns higher-is-riskier scores; SVMs do not yield
+ survival probabilities for Brier metrics.
- ### 5. Non-parametric Estimation
+ Read the model-specific reference before interpreting coefficients or predictions:
+ `references/cox-models.md`, `references/ensemble-models.md`, or
+ `references/svm-models.md`.
- Estimate survival functions without parametric assumptions:
+ ## Prediction and metric contracts
- #### Kaplan-Meier Estimator
```python
- from sksurv.nonparametric import kaplan_meier_estimator
-
- time, survival_prob = kaplan_meier_estimator(y['event'], y['time'])
- ```
+ import numpy as np
+ from sksurv.metrics import (
+ brier_score,
+ concordance_index_ipcw,
+ cumulative_dynamic_auc,
+ integrated_brier_score,
+ )
- #### Nelson-Aalen Estimator
- ```python
- from sksurv.nonparametric import nelson_aalen_estimator
+ risk = model.predict(X_test) # (n_test,), higher means higher event risk
+ uno_c = concordance_index_ipcw(y_train, y_test, risk, tau=times[-1])[0]
+ auc_t, mean_auc = cumulative_dynamic_auc(y_train, y_test, risk, times)
- time, cumulative_hazard = nelson_aalen_estimator(y['event'], y['time'])
+ surv_fns = model.predict_survival_function(X_test)
+ surv_prob = np.vstack([fn(times) for fn in surv_fns]) # (n_test, n_times)
+ _, brier_t = brier_score(y_train, y_test, surv_prob, times)
+ ibs = integrated_brier_score(y_train, y_test, surv_prob, times)
```
- ## Typical Workflows
-
- ### Workflow 1: Standard Survival Analysis
-
- ```python
- from sksurv.datasets import load_breast_cancer
- from sksurv.linear_model import CoxPHSurvivalAnalysis
- from sksurv.metrics import concordance_index_ipcw
- from sklearn.model_selection import train_test_split
- from sklearn.preprocessing import StandardScaler
-
- # 1. Load and prepare data
- X, y = load_breast_cancer()
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
-
- # 2. Preprocess
- scaler = StandardScaler()
- X_train_scaled = scaler.fit_transform(X_train)
- X_test_scaled = scaler.transform(X_test)
-
- # 3. Fit model
- estimator = CoxPHSurvivalAnalysis()
- estimator.fit(X_train_scaled, y_train)
+ - Harrell C and Uno C measure rank discrimination, not calibration.
+ - Cumulative/dynamic AUC measures discrimination at selected horizons and accepts
+ 1D or time-dependent 2D risk scores; it rejects survival probabilities.
+ - Brier score is censoring-weighted probability error and reflects both
+ discrimination and calibration. It is not a standalone calibration curve.
+ - Calibration requires horizon-specific predicted-versus-observed checks on
+ independent data. scikit-survival 0.28 has no dedicated calibration-curve API.
- # 4. Predict
- risk_scores = estimator.predict(X_test_scaled)
+ See `references/evaluation-metrics.md` for assumptions, primary literature, safe
+ time-grid construction, and scorer wrappers.
- # 5. Evaluate
- c_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]
- print(f"C-index: {c_index:.3f}")
- ```
+ ## Pipelines, metadata routing, and tuning
- ### Workflow 2: High-Dimensional Data with Feature Selection
+ Ordinary `Pipeline.fit(X, y)` needs no metadata-routing setup. Metric wrappers such
+ as `as_concordance_index_ipcw_scorer` are estimator wrappers, not `scoring=`
+ callables:
```python
- from sksurv.linear_model import CoxnetSurvivalAnalysis
from sklearn.model_selection import GridSearchCV
from sksurv.metrics import as_concordance_index_ipcw_scorer
- # 1. Use penalized Cox for feature selection
- estimator = CoxnetSurvivalAnalysis(l1_ratio=0.9) # Lasso-like
-
- # 2. Tune regularization with cross-validation
- param_grid = {'alpha_min_ratio': [0.01, 0.001]}
- cv = GridSearchCV(estimator, param_grid,
- scoring=as_concordance_index_ipcw_scorer(), cv=5)
- cv.fit(X, y)
-
- # 3. Identify selected features
- best_model = cv.best_estimator_
- selected_features = np.where(best_model.coef_ != 0)[0]
+ wrapped = as_concordance_index_ipcw_scorer(model, tau=tau)
+ search = GridSearchCV(
+ wrapped,
+ {"estimator__coxphsurvivalanalysis__alpha": [0.01, 0.1, 1.0]},
+ cv=inner_splits,
+ )
```
- ### Workflow 3: Ensemble Method for Maximum Performance
-
- ```python
- from sksurv.ensemble import GradientBoostingSurvivalAnalysis
- from sklearn.model_selection import GridSearchCV
-
- # 1. Define parameter grid
- param_grid = {
- 'learning_rate': [0.01, 0.05, 0.1],
- 'n_estimators': [100, 200, 300],
- 'max_depth': [3, 5, 7]
- }
-
- # 2. Grid search
- gbs = GradientBoostingSurvivalAnalysis()
- cv = GridSearchCV(gbs, param_grid, cv=5,
- scoring=as_concordance_index_ipcw_scorer(), n_jobs=-1)
- cv.fit(X_train, y_train)
+ The wrapper learns the censoring distribution from each fit fold. Prefix wrapped
+ parameters with `estimator__`. Enable scikit-learn metadata routing only when
+ passing extra metadata through a meta-estimator. For example, Coxnet's
+ `set_predict_request(alpha=True)` matters only when routing the `alpha` prediction
+ argument with `sklearn.set_config(enable_metadata_routing=True)`.
- # 3. Evaluate best model
- best_model = cv.best_estimator_
- risk_scores = best_model.predict(X_test)
- c_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]
- ```
+ Use an outer CV loop for an unbiased CV performance estimate after inner tuning.
+ Do not select parameters and report performance from the same folds as if external.
- ### Workflow 4: Comprehensive Model Comparison
+ ## Competing risks
```python
- from sksurv.linear_model import CoxPHSurvivalAnalysis
- from sksurv.ensemble import RandomSurvivalForest, GradientBoostingSurvivalAnalysis
- from sksurv.svm import FastSurvivalSVM
- from sksurv.metrics import concordance_index_ipcw, integrated_brier_score
-
- # Define models
- models = {
- 'Cox': CoxPHSurvivalAnalysis(),
- 'RSF': RandomSurvivalForest(n_estimators=100, random_state=42),
- 'GBS': GradientBoostingSurvivalAnalysis(random_state=42),
- 'SVM': FastSurvivalSVM(random_state=42)
- }
-
- # Evaluate each model
- results = {}
- for name, model in models.items():
- model.fit(X_train_scaled, y_train)
- risk_scores = model.predict(X_test_scaled)
- c_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]
- results[name] = c_index
- print(f"{name}: C-index = {c_index:.3f}")
+ from sksurv.nonparametric import cumulative_incidence_competing_risks
- # Select best model
- best_model_name = max(results, key=results.get)
- print(f"\nBest model: {best_model_name}")
+ # status: integer array, 0=censored, 1..K=mutually exclusive causes
+ time, cif = cumulative_incidence_competing_risks(status, observed_time)
+ total_cif = cif[0]
+ cause_1_cif = cif[1]
```
- ## Integration with scikit-learn
-
- scikit-survival fully integrates with scikit-learn's ecosystem:
-
- ```python
- from sklearn.pipeline import Pipeline
- from sklearn.preprocessing import StandardScaler
- from sklearn.model_selection import cross_val_score, GridSearchCV
+ `cif` has shape `(K + 1, n_times)`; row 0 is total risk and rows 1..K are
+ cause-specific cumulative incidence. Cause-specific Cox models treat other causes
+ as censored to estimate cause-specific hazards, but one such model's
+ `1 - survival` is not the cause-specific CIF. See `references/competing-risks.md`.
- # Use pipelines
- pipeline = Pipeline([
- ('scaler', StandardScaler()),
- ('model', CoxPHSurvivalAnalysis())
- ])
+ ## Bundled local CLIs
- # Use cross-validation
- scores = cross_val_score(pipeline, X, y, cv=5,
- scoring=as_concordance_index_ipcw_scorer())
+ All helpers use deterministic synthetic data when no input is given. They make no
+ network calls, reject URLs and symlinks, bound files/rows/features, avoid unsafe
+ pickle loading, and lazily import scientific packages.
- # Use grid search
- param_grid = {'model__alpha': [0.1, 1.0, 10.0]}
- cv = GridSearchCV(pipeline, param_grid, cv=5)
- cv.fit(X, y)
+ ```bash
+ python skills/scikit-survival/scripts/validate_survival_csv.py --help
+ python skills/scikit-survival/scripts/train_survival_model.py --help
+ python skills/scikit-survival/scripts/evaluate_survival_metrics.py --help
+ python skills/scikit-survival/scripts/competing_risk_cif.py --help
+ python skills/scikit-survival/scripts/model_report.py --help
```
- ## Best Practices
-
- 1. **Always standardize features** for SVMs and regularized Cox models
- 2. **Use Uno's C-index** instead of Harrell's when censoring > 40%
- 3. **Report multiple evaluation metrics** (C-index, integrated Brier score, time-dependent AUC)
- 4. **Check proportional hazards assumption** for Cox models
- 5. **Use cross-validation** for hyperparameter tuning with appropriate scorers
- 6. **Validate data quality** before modeling (check for negative times, sufficient events per feature)
- 7. **Compare multiple model types** to find best performance
- 8. **Use permutation importance** for Random Survival Forests (not built-in importance)
- 9. **Consider competing risks** when multiple event types exist
- 10. **Document censoring mechanism** and rates in analysis
-
- ## Common Pitfalls to Avoid
-
- 1. **Using Harrell's C-index with high censoring** → Use Uno's C-index
- 2. **Not standardizing features for SVMs** → Always standardize
- 3. **Forgetting to pass y_train to concordance_index_ipcw** → Required for IPCW calculation
- 4. **Treating competing events as censored** → Use competing risks methods
- 5. **Not checking for sufficient events per feature** → Rule of thumb: 10+ events per feature
- 6. **Using built-in feature importance for RSF** → Use permutation importance
- 7. **Ignoring proportional hazards assumption** → Validate or use alternative models
- 8. **Not using appropriate scorers in cross-validation** → Use as_concordance_index_ipcw_scorer()
+ Typical local flow:
- ## Reference Files
+ ```bash
+ python skills/scikit-survival/scripts/validate_survival_csv.py \
+ --input data.csv --event-column event --time-column time \
+ --feature-columns age,group,measurement --structured-output outcome.npy
- This skill includes detailed reference files for specific topics:
+ python skills/scikit-survival/scripts/train_survival_model.py \
+ --input data.csv --event-column event --time-column time \
+ --numeric-columns age,measurement --categorical-columns group \
+ --model coxph --tune --prediction-output predictions.npz \
+ --output training-summary.json
- - **`references/cox-models.md`**: Complete guide to Cox proportional hazards models, penalized Cox (CoxNet), IPCRidge, regularization strategies, and interpretation
- - **`references/ensemble-models.md`**: Random Survival Forests, Gradient Boosting, hyperparameter tuning, feature importance, and model selection
- - **`references/evaluation-metrics.md`**: Concordance index (Harrell's vs Uno's), time-dependent AUC, Brier score, comprehensive evaluation pipelines
- - **`references/data-handling.md`**: Data loading, preprocessing workflows, handling missing data, feature encoding, validation checks
- - **`references/svm-models.md`**: Survival Support Vector Machines, kernel selection, clinical kernel transform, hyperparameter tuning
- - **`references/competing-risks.md`**: Competing risks analysis, cumulative incidence functions, cause-specific hazard models
+ python skills/scikit-survival/scripts/evaluate_survival_metrics.py \
+ --input predictions.npz --output metrics-summary.json
- Load these reference files when detailed information is needed for specific tasks.
+ python skills/scikit-survival/scripts/model_report.py \
+ --training-summary training-summary.json \
+ --metrics-summary metrics-summary.json --output model-report.md
+ ```
- ## Additional Resources
+ Use only de-identified, authorized local data. The bundled tests contain synthetic
+ records only and no patient data or PHI.
- - **Official Documentation**: https://scikit-survival.readthedocs.io/
- - **GitHub Repository**: https://github.com/sebp/scikit-survival
- - **Built-in Datasets**: Use `sksurv.datasets` for practice datasets (GBSG2, WHAS500, veterans lung cancer, etc.)
- - **API Reference**: Complete list of classes and functions at https://scikit-survival.readthedocs.io/en/stable/api/index.html
+ ## Security triage
- ## Quick Reference: Key Imports
+ `SECURITY.md` previously claimed this skill bundled package-shadowing files named
+ `sklearn.py` and `sksurv.py`. The 2026-07-23 inventory confirmed those files did
+ not exist; the claim was a phantom analyzer finding. This refresh adds only
+ descriptively named helpers and no shadow modules, environment reads, or network
+ calls.
- ```python
- # Models
- from sksurv.linear_model import CoxPHSurvivalAnalysis, CoxnetSurvivalAnalysis, IPCRidge
- from sksurv.ensemble import RandomSurvivalForest, GradientBoostingSurvivalAnalysis
- from sksurv.svm import FastSurvivalSVM, FastKernelSurvivalSVM
- from sksurv.tree import SurvivalTree
+ Never name a project script after an imported package (including `sklearn.py`,
+ `sksurv.py`, `numpy.py`, or `pandas.py`), because Python may import the local file
+ instead of the installed library. Inspect the working directory before executing
+ examples copied from untrusted sources.
- # Evaluation metrics
- from sksurv.metrics import (
- concordance_index_censored,
- concordance_index_ipcw,
- cumulative_dynamic_auc,
- brier_score,
- integrated_brier_score,
- as_concordance_index_ipcw_scorer,
- as_integrated_brier_score_scorer
- )
+ ## Reference files
- # Non-parametric estimation
- from sksurv.nonparametric import (
- kaplan_meier_estimator,
- nelson_aalen_estimator,
- cumulative_incidence_competing_risks
- )
+ - `references/data-handling.md` — structured arrays, datasets, schema validation,
+ pandas/Polars preprocessing, and leakage-safe splitting.
+ - `references/cox-models.md` — Cox PH, Coxnet, IPCRidge, assumptions, and tuning.
+ - `references/ensemble-models.md` — forests, trees, boosting, predictions, and
+ permutation importance.
+ - `references/svm-models.md` — SVM objectives, prediction direction, scaling,
+ kernels, and limitations.
+ - `references/evaluation-metrics.md` — metric inputs, censoring assumptions,
+ time grids, calibration, nested CV, and primary literature.
+ - `references/competing-risks.md` — integer event coding, CIF API, built-in
+ datasets, cause-specific hazards, and unsupported Fine-Gray regression.
- # Data handling
- from sksurv.util import Surv
- from sksurv.preprocessing import OneHotEncoder, encode_categorical
- from sksurv.datasets import load_gbsg2, load_breast_cancer, load_veterans_lung_cancer
+ ## Dated sources
- # Kernels
- from sksurv.kernels import ClinicalKernelTransform
- ```
+ Official API and compatibility sources, checked 2026-07-23:
+ - [PyPI 0.28.0](https://pypi.org/project/scikit-survival/) — released 2026-07-05.
+ - [GitHub v0.28.0 release](https://github.com/sebp/scikit-survival/releases/tag/v0.28.0)
+ — published 2026-07-05.
+ - [0.28 release notes](https://scikit-survival.readthedocs.io/en/stable/release_notes/v0.28.html).
+ - [Installation guide](https://scikit-survival.readthedocs.io/en/stable/install.html).
+ - [Stable user guide](https://scikit-survival.readthedocs.io/en/stable/user_guide/index.html).
+ - [Stable API reference](https://scikit-survival.readthedocs.io/en/stable/api/index.html).