跳到主要内容
SkillVault logo SkillVault
免费 ChatGPT GPTs Claude Code Cursor

scikit-survival

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.

0 次下载 0 次浏览 更新于 Oct 31, 2026 v1.0.0
scikit-survival skill cover

下方技能配置(提示词、变量、安装步骤)保留英文原文。.aiskill 文件直接面向 AI 智能体,统一使用英文以确保跨平台行为一致。

概述

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.

Source: https://github.com/DenDen047/claude-scientific-skills · GPL-3.0 LICENSE · © 2025 K-Dense Inc.

系统提示词

定义智能体角色、规则与输出格式的指令块。

system-prompt.txt
# 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

## Core Capabilities

### 1. Model Types and Selection

scikit-survival provides multiple model families, each suited for different scenarios:

#### 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

**See**: `references/cox-models.md` for detailed guidance on Cox models, regularization, and interpretation

#### 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

**See**: `references/ensemble-models.md` for comprehensive guidance on ensemble methods, hyperparameter tuning, and when to use each model

#### 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

**See**: `references/svm-models.md` for detailed SVM guidance, kernel selection, and hyperparameter tuning

#### Model Selection Decision Tree

```
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
```

### 2. Data Preparation and Preprocessing

Before modeling, properly prepare survival data:

#### 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)
```

#### 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]
```

#### Time-Dependent AUC
Evaluate discrimination at specific time points:

```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:

```python
from sksurv.metrics import integrated_brier_score

ibs = integrated_brier_score(y_train, y_test, survival_functions, times)
```

**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)
```

**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

**See**: `references/competing-risks.md` for detailed competing risks methods, cause-specific hazard models, and interpretation

### 5. Non-parametric Estimation

Estimate survival functions without parametric assumptions:

#### Kaplan-Meier Estimator
```python
from sksurv.nonparametric import kaplan_meier_estimator

time, survival_prob = kaplan_meier_estimator(y['event'], y['time'])
```

#### Nelson-Aalen Estimator
```python
from sksurv.nonparametric import nelson_aalen_estimator

time, cumulative_hazard = nelson_aalen_estimator(y['event'], y['time'])
```

## 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)

# 4. Predict
risk_scores = estimator.predict(X_test_scaled)

# 5. Evaluate
c_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]
print(f"C-index: {c_index:.3f}")
```

### Workflow 2: High-Dimensional Data with Feature Selection

```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]
```

### 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)

# 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]
```

### Workflow 4: Comprehensive Model Comparison

```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}")

# Select best model
best_model_name = max(results, key=results.get)
print(f"\nBest model: {best_model_name}")
```

## 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

# Use pipelines
pipeline = Pipeline([
    ('scaler', StandardScaler()),
    ('model', CoxPHSurvivalAnalysis())
])

# Use cross-validation
scores = cross_val_score(pipeline, X, y, cv=5,
                         scoring=as_concordance_index_ipcw_scorer())

# Use grid search
param_grid = {'model__alpha': [0.1, 1.0, 10.0]}
cv = GridSearchCV(pipeline, param_grid, cv=5)
cv.fit(X, y)
```

## 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()

## Reference Files

This skill includes detailed reference files for specific topics:

- **`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

Load these reference files when detailed information is needed for specific tasks.

## Additional Resources

- **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

## Quick Reference: Key Imports

```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

# 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
)

# Non-parametric estimation
from sksurv.nonparametric import (
    kaplan_meier_estimator,
    nelson_aalen_estimator,
    cumulative_incidence_competing_risks
)

# 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

# Kernels
from sksurv.kernels import ClinicalKernelTransform
```

用户提示词模板

填充变量后发送,即可运行该技能: {{variables}}

user-template.txt

变量

名称 必填 说明 示例

完整技能配置

标准 .aiskill 文件,提供 JSON 与 YAML 两种格式。

scikit-survival.aiskill (JSON)
{
  "format": "aiskill/v1",
  "skill": {
    "name": "scikit-survival",
    "slug": "scikit-survival",
    "version": "1.0.0",
    "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.",
    "category": "Research",
    "tags": [
      "research-science",
      "python"
    ],
    "platforms": [
      "chatgpt",
      "claude-code",
      "cursor"
    ],
    "tested_environment": "Agent Skills convention (SKILL.md) — works with Claude Code, Cursor, ChatGPT/Codex and compatible agents",
    "license": "GPL-3.0 LICENSE"
  },
  "prompts": {
    "system": "# scikit-survival: Survival Analysis in Python\r\n\r\n## Overview\r\n\r\nscikit-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.\r\n\r\nSurvival 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).\r\n\r\n## When to Use This Skill\r\n\r\nUse this skill when:\r\n- Performing survival analysis or time-to-event modeling\r\n- Working with censored data (right-censored, left-censored, or interval-censored)\r\n- Fitting Cox proportional hazards models (standard or penalized)\r\n- Building ensemble survival models (Random Survival Forests, Gradient Boosting)\r\n- Training Survival Support Vector Machines\r\n- Evaluating survival model performance (concordance index, Brier score, time-dependent AUC)\r\n- Estimating Kaplan-Meier or Nelson-Aalen curves\r\n- Analyzing competing risks\r\n- Preprocessing survival data or handling missing values in survival datasets\r\n- Conducting any analysis using the scikit-survival library\r\n\r\n## Core Capabilities\r\n\r\n### 1. Model Types and Selection\r\n\r\nscikit-survival provides multiple model families, each suited for different scenarios:\r\n\r\n#### Cox Proportional Hazards Models\r\n**Use for**: Standard survival analysis with interpretable coefficients\r\n- `CoxPHSurvivalAnalysis`: Basic Cox model\r\n- `CoxnetSurvivalAnalysis`: Penalized Cox with elastic net for high-dimensional data\r\n- `IPCRidge`: Ridge regression for accelerated failure time models\r\n\r\n**See**: `references/cox-models.md` for detailed guidance on Cox models, regularization, and interpretation\r\n\r\n#### Ensemble Methods\r\n**Use for**: High predictive performance with complex non-linear relationships\r\n- `RandomSurvivalForest`: Robust, non-parametric ensemble method\r\n- `GradientBoostingSurvivalAnalysis`: Tree-based boosting for maximum performance\r\n- `ComponentwiseGradientBoostingSurvivalAnalysis`: Linear boosting with feature selection\r\n- `ExtraSurvivalTrees`: Extremely randomized trees for additional regularization\r\n\r\n**See**: `references/ensemble-models.md` for comprehensive guidance on ensemble methods, hyperparameter tuning, and when to use each model\r\n\r\n#### Survival Support Vector Machines\r\n**Use for**: Medium-sized datasets with margin-based learning\r\n- `FastSurvivalSVM`: Linear SVM optimized for speed\r\n- `FastKernelSurvivalSVM`: Kernel SVM for non-linear relationships\r\n- `HingeLossSurvivalSVM`: SVM with hinge loss\r\n- `ClinicalKernelTransform`: Specialized kernel for clinical + molecular data\r\n\r\n**See**: `references/svm-models.md` for detailed SVM guidance, kernel selection, and hyperparameter tuning\r\n\r\n#### Model Selection Decision Tree\r\n\r\n```\r\nStart\r\n├─ High-dimensional data (p > n)?\r\n│  ├─ Yes → CoxnetSurvivalAnalysis (elastic net)\r\n│  └─ No → Continue\r\n│\r\n├─ Need interpretable coefficients?\r\n│  ├─ Yes → CoxPHSurvivalAnalysis or ComponentwiseGradientBoostingSurvivalAnalysis\r\n│  └─ No → Continue\r\n│\r\n├─ Complex non-linear relationships expected?\r\n│  ├─ Yes\r\n│  │  ├─ Large dataset (n > 1000) → GradientBoostingSurvivalAnalysis\r\n│  │  ├─ Medium dataset → RandomSurvivalForest or FastKernelSurvivalSVM\r\n│  │  └─ Small dataset → RandomSurvivalForest\r\n│  └─ No → CoxPHSurvivalAnalysis or FastSurvivalSVM\r\n│\r\n└─ For maximum performance → Try multiple models and compare\r\n```\r\n\r\n### 2. Data Preparation and Preprocessing\r\n\r\nBefore modeling, properly prepare survival data:\r\n\r\n#### Creating Survival Outcomes\r\n```python\r\nfrom sksurv.util import Surv\r\n\r\n# From separate arrays\r\ny = Surv.from_arrays(event=event_array, time=time_array)\r\n\r\n# From DataFrame\r\ny = Surv.from_dataframe('event', 'time', df)\r\n```\r\n\r\n#### Essential Preprocessing Steps\r\n1. **Handle missing values**: Imputation strategies for features\r\n2. **Encode categorical variables**: One-hot encoding or label encoding\r\n3. **Standardize features**: Critical for SVMs and regularized Cox models\r\n4. **Validate data quality**: Check for negative times, sufficient events per feature\r\n5. **Train-test split**: Maintain similar censoring rates across splits\r\n\r\n**See**: `references/data-handling.md` for complete preprocessing workflows, data validation, and best practices\r\n\r\n### 3. Model Evaluation\r\n\r\nProper evaluation is critical for survival models. Use appropriate metrics that account for censoring:\r\n\r\n#### Concordance Index (C-index)\r\nPrimary metric for ranking/discrimination:\r\n- **Harrell's C-index**: Use for low censoring (<40%)\r\n- **Uno's C-index**: Use for moderate to high censoring (>40%) - more robust\r\n\r\n```python\r\nfrom sksurv.metrics import concordance_index_censored, concordance_index_ipcw\r\n\r\n# Harrell's C-index\r\nc_harrell = concordance_index_censored(y_test['event'], y_test['time'], risk_scores)[0]\r\n\r\n# Uno's C-index (recommended)\r\nc_uno = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\n```\r\n\r\n#### Time-Dependent AUC\r\nEvaluate discrimination at specific time points:\r\n\r\n```python\r\nfrom sksurv.metrics import cumulative_dynamic_auc\r\n\r\ntimes = [365, 730, 1095]  # 1, 2, 3 years\r\nauc, mean_auc = cumulative_dynamic_auc(y_train, y_test, risk_scores, times)\r\n```\r\n\r\n#### Brier Score\r\nAssess both discrimination and calibration:\r\n\r\n```python\r\nfrom sksurv.metrics import integrated_brier_score\r\n\r\nibs = integrated_brier_score(y_train, y_test, survival_functions, times)\r\n```\r\n\r\n**See**: `references/evaluation-metrics.md` for comprehensive evaluation guidance, metric selection, and using scorers with cross-validation\r\n\r\n### 4. Competing Risks Analysis\r\n\r\nHandle situations with multiple mutually exclusive event types:\r\n\r\n```python\r\nfrom sksurv.nonparametric import cumulative_incidence_competing_risks\r\n\r\n# Estimate cumulative incidence for each event type\r\ntime_points, cif_event1, cif_event2 = cumulative_incidence_competing_risks(y)\r\n```\r\n\r\n**Use competing risks when**:\r\n- Multiple mutually exclusive event types exist (e.g., death from different causes)\r\n- Occurrence of one event prevents others\r\n- Need probability estimates for specific event types\r\n\r\n**See**: `references/competing-risks.md` for detailed competing risks methods, cause-specific hazard models, and interpretation\r\n\r\n### 5. Non-parametric Estimation\r\n\r\nEstimate survival functions without parametric assumptions:\r\n\r\n#### Kaplan-Meier Estimator\r\n```python\r\nfrom sksurv.nonparametric import kaplan_meier_estimator\r\n\r\ntime, survival_prob = kaplan_meier_estimator(y['event'], y['time'])\r\n```\r\n\r\n#### Nelson-Aalen Estimator\r\n```python\r\nfrom sksurv.nonparametric import nelson_aalen_estimator\r\n\r\ntime, cumulative_hazard = nelson_aalen_estimator(y['event'], y['time'])\r\n```\r\n\r\n## Typical Workflows\r\n\r\n### Workflow 1: Standard Survival Analysis\r\n\r\n```python\r\nfrom sksurv.datasets import load_breast_cancer\r\nfrom sksurv.linear_model import CoxPHSurvivalAnalysis\r\nfrom sksurv.metrics import concordance_index_ipcw\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.preprocessing import StandardScaler\r\n\r\n# 1. Load and prepare data\r\nX, y = load_breast_cancer()\r\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\r\n\r\n# 2. Preprocess\r\nscaler = StandardScaler()\r\nX_train_scaled = scaler.fit_transform(X_train)\r\nX_test_scaled = scaler.transform(X_test)\r\n\r\n# 3. Fit model\r\nestimator = CoxPHSurvivalAnalysis()\r\nestimator.fit(X_train_scaled, y_train)\r\n\r\n# 4. Predict\r\nrisk_scores = estimator.predict(X_test_scaled)\r\n\r\n# 5. Evaluate\r\nc_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\nprint(f\"C-index: {c_index:.3f}\")\r\n```\r\n\r\n### Workflow 2: High-Dimensional Data with Feature Selection\r\n\r\n```python\r\nfrom sksurv.linear_model import CoxnetSurvivalAnalysis\r\nfrom sklearn.model_selection import GridSearchCV\r\nfrom sksurv.metrics import as_concordance_index_ipcw_scorer\r\n\r\n# 1. Use penalized Cox for feature selection\r\nestimator = CoxnetSurvivalAnalysis(l1_ratio=0.9)  # Lasso-like\r\n\r\n# 2. Tune regularization with cross-validation\r\nparam_grid = {'alpha_min_ratio': [0.01, 0.001]}\r\ncv = GridSearchCV(estimator, param_grid,\r\n                  scoring=as_concordance_index_ipcw_scorer(), cv=5)\r\ncv.fit(X, y)\r\n\r\n# 3. Identify selected features\r\nbest_model = cv.best_estimator_\r\nselected_features = np.where(best_model.coef_ != 0)[0]\r\n```\r\n\r\n### Workflow 3: Ensemble Method for Maximum Performance\r\n\r\n```python\r\nfrom sksurv.ensemble import GradientBoostingSurvivalAnalysis\r\nfrom sklearn.model_selection import GridSearchCV\r\n\r\n# 1. Define parameter grid\r\nparam_grid = {\r\n    'learning_rate': [0.01, 0.05, 0.1],\r\n    'n_estimators': [100, 200, 300],\r\n    'max_depth': [3, 5, 7]\r\n}\r\n\r\n# 2. Grid search\r\ngbs = GradientBoostingSurvivalAnalysis()\r\ncv = GridSearchCV(gbs, param_grid, cv=5,\r\n                  scoring=as_concordance_index_ipcw_scorer(), n_jobs=-1)\r\ncv.fit(X_train, y_train)\r\n\r\n# 3. Evaluate best model\r\nbest_model = cv.best_estimator_\r\nrisk_scores = best_model.predict(X_test)\r\nc_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\n```\r\n\r\n### Workflow 4: Comprehensive Model Comparison\r\n\r\n```python\r\nfrom sksurv.linear_model import CoxPHSurvivalAnalysis\r\nfrom sksurv.ensemble import RandomSurvivalForest, GradientBoostingSurvivalAnalysis\r\nfrom sksurv.svm import FastSurvivalSVM\r\nfrom sksurv.metrics import concordance_index_ipcw, integrated_brier_score\r\n\r\n# Define models\r\nmodels = {\r\n    'Cox': CoxPHSurvivalAnalysis(),\r\n    'RSF': RandomSurvivalForest(n_estimators=100, random_state=42),\r\n    'GBS': GradientBoostingSurvivalAnalysis(random_state=42),\r\n    'SVM': FastSurvivalSVM(random_state=42)\r\n}\r\n\r\n# Evaluate each model\r\nresults = {}\r\nfor name, model in models.items():\r\n    model.fit(X_train_scaled, y_train)\r\n    risk_scores = model.predict(X_test_scaled)\r\n    c_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\n    results[name] = c_index\r\n    print(f\"{name}: C-index = {c_index:.3f}\")\r\n\r\n# Select best model\r\nbest_model_name = max(results, key=results.get)\r\nprint(f\"\\nBest model: {best_model_name}\")\r\n```\r\n\r\n## Integration with scikit-learn\r\n\r\nscikit-survival fully integrates with scikit-learn's ecosystem:\r\n\r\n```python\r\nfrom sklearn.pipeline import Pipeline\r\nfrom sklearn.preprocessing import StandardScaler\r\nfrom sklearn.model_selection import cross_val_score, GridSearchCV\r\n\r\n# Use pipelines\r\npipeline = Pipeline([\r\n    ('scaler', StandardScaler()),\r\n    ('model', CoxPHSurvivalAnalysis())\r\n])\r\n\r\n# Use cross-validation\r\nscores = cross_val_score(pipeline, X, y, cv=5,\r\n                         scoring=as_concordance_index_ipcw_scorer())\r\n\r\n# Use grid search\r\nparam_grid = {'model__alpha': [0.1, 1.0, 10.0]}\r\ncv = GridSearchCV(pipeline, param_grid, cv=5)\r\ncv.fit(X, y)\r\n```\r\n\r\n## Best Practices\r\n\r\n1. **Always standardize features** for SVMs and regularized Cox models\r\n2. **Use Uno's C-index** instead of Harrell's when censoring > 40%\r\n3. **Report multiple evaluation metrics** (C-index, integrated Brier score, time-dependent AUC)\r\n4. **Check proportional hazards assumption** for Cox models\r\n5. **Use cross-validation** for hyperparameter tuning with appropriate scorers\r\n6. **Validate data quality** before modeling (check for negative times, sufficient events per feature)\r\n7. **Compare multiple model types** to find best performance\r\n8. **Use permutation importance** for Random Survival Forests (not built-in importance)\r\n9. **Consider competing risks** when multiple event types exist\r\n10. **Document censoring mechanism** and rates in analysis\r\n\r\n## Common Pitfalls to Avoid\r\n\r\n1. **Using Harrell's C-index with high censoring** → Use Uno's C-index\r\n2. **Not standardizing features for SVMs** → Always standardize\r\n3. **Forgetting to pass y_train to concordance_index_ipcw** → Required for IPCW calculation\r\n4. **Treating competing events as censored** → Use competing risks methods\r\n5. **Not checking for sufficient events per feature** → Rule of thumb: 10+ events per feature\r\n6. **Using built-in feature importance for RSF** → Use permutation importance\r\n7. **Ignoring proportional hazards assumption** → Validate or use alternative models\r\n8. **Not using appropriate scorers in cross-validation** → Use as_concordance_index_ipcw_scorer()\r\n\r\n## Reference Files\r\n\r\nThis skill includes detailed reference files for specific topics:\r\n\r\n- **`references/cox-models.md`**: Complete guide to Cox proportional hazards models, penalized Cox (CoxNet), IPCRidge, regularization strategies, and interpretation\r\n- **`references/ensemble-models.md`**: Random Survival Forests, Gradient Boosting, hyperparameter tuning, feature importance, and model selection\r\n- **`references/evaluation-metrics.md`**: Concordance index (Harrell's vs Uno's), time-dependent AUC, Brier score, comprehensive evaluation pipelines\r\n- **`references/data-handling.md`**: Data loading, preprocessing workflows, handling missing data, feature encoding, validation checks\r\n- **`references/svm-models.md`**: Survival Support Vector Machines, kernel selection, clinical kernel transform, hyperparameter tuning\r\n- **`references/competing-risks.md`**: Competing risks analysis, cumulative incidence functions, cause-specific hazard models\r\n\r\nLoad these reference files when detailed information is needed for specific tasks.\r\n\r\n## Additional Resources\r\n\r\n- **Official Documentation**: https://scikit-survival.readthedocs.io/\r\n- **GitHub Repository**: https://github.com/sebp/scikit-survival\r\n- **Built-in Datasets**: Use `sksurv.datasets` for practice datasets (GBSG2, WHAS500, veterans lung cancer, etc.)\r\n- **API Reference**: Complete list of classes and functions at https://scikit-survival.readthedocs.io/en/stable/api/index.html\r\n\r\n## Quick Reference: Key Imports\r\n\r\n```python\r\n# Models\r\nfrom sksurv.linear_model import CoxPHSurvivalAnalysis, CoxnetSurvivalAnalysis, IPCRidge\r\nfrom sksurv.ensemble import RandomSurvivalForest, GradientBoostingSurvivalAnalysis\r\nfrom sksurv.svm import FastSurvivalSVM, FastKernelSurvivalSVM\r\nfrom sksurv.tree import SurvivalTree\r\n\r\n# Evaluation metrics\r\nfrom sksurv.metrics import (\r\n    concordance_index_censored,\r\n    concordance_index_ipcw,\r\n    cumulative_dynamic_auc,\r\n    brier_score,\r\n    integrated_brier_score,\r\n    as_concordance_index_ipcw_scorer,\r\n    as_integrated_brier_score_scorer\r\n)\r\n\r\n# Non-parametric estimation\r\nfrom sksurv.nonparametric import (\r\n    kaplan_meier_estimator,\r\n    nelson_aalen_estimator,\r\n    cumulative_incidence_competing_risks\r\n)\r\n\r\n# Data handling\r\nfrom sksurv.util import Surv\r\nfrom sksurv.preprocessing import OneHotEncoder, encode_categorical\r\nfrom sksurv.datasets import load_gbsg2, load_breast_cancer, load_veterans_lung_cancer\r\n\r\n# Kernels\r\nfrom sksurv.kernels import ClinicalKernelTransform\r\n```",
    "user_template": ""
  },
  "variables": [],
  "install": {
    "steps": [
      {
        "title": "Download & unzip",
        "detail": "Download the .zip package from SkillVault and unzip it. The scikit-survival/ folder contains SKILL.md plus any companion scripts, references and assets."
      },
      {
        "title": "Copy into your agent skills directory",
        "detail": "Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code), .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or reload the session."
      },
      {
        "title": "Use it",
        "detail": "Describe the task in natural language; the agent loads the skill automatically when the request matches the skill description."
      }
    ]
  },
  "usage": {
    "steps": []
  },
  "metadata": {
    "author": "SkillVault",
    "source": "https://skillvault.top/skills/scikit-survival",
    "exported_at": "2026-11-03T07:44:00.486Z"
  }
}
scikit-survival.aiskill (YAML)
format: aiskill/v1
skill:
  name: scikit-survival
  slug: scikit-survival
  version: 1.0.0
  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.
  category: Research
  tags:
    - research-science
    - python
  platforms:
    - chatgpt
    - claude-code
    - cursor
  tested_environment: >-
    Agent Skills convention (SKILL.md) — works with Claude Code, Cursor, ChatGPT/Codex and
    compatible agents
  license: GPL-3.0 LICENSE
prompts:
  system: "# scikit-survival: Survival Analysis in Python\r\n\r\n## Overview\r\n\r\nscikit-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.\r\n\r\nSurvival 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).\r\n\r\n## When to Use This Skill\r\n\r\nUse this skill when:\r\n- Performing survival analysis or time-to-event modeling\r\n- Working with censored data (right-censored, left-censored, or interval-censored)\r\n- Fitting Cox proportional hazards models (standard or penalized)\r\n- Building ensemble survival models (Random Survival Forests, Gradient Boosting)\r\n- Training Survival Support Vector Machines\r\n- Evaluating survival model performance (concordance index, Brier score, time-dependent AUC)\r\n- Estimating Kaplan-Meier or Nelson-Aalen curves\r\n- Analyzing competing risks\r\n- Preprocessing survival data or handling missing values in survival datasets\r\n- Conducting any analysis using the scikit-survival library\r\n\r\n## Core Capabilities\r\n\r\n### 1. Model Types and Selection\r\n\r\nscikit-survival provides multiple model families, each suited for different scenarios:\r\n\r\n#### Cox Proportional Hazards Models\r\n**Use for**: Standard survival analysis with interpretable coefficients\r\n- `CoxPHSurvivalAnalysis`: Basic Cox model\r\n- `CoxnetSurvivalAnalysis`: Penalized Cox with elastic net for high-dimensional data\r\n- `IPCRidge`: Ridge regression for accelerated failure time models\r\n\r\n**See**: `references/cox-models.md` for detailed guidance on Cox models, regularization, and interpretation\r\n\r\n#### Ensemble Methods\r\n**Use for**: High predictive performance with complex non-linear relationships\r\n- `RandomSurvivalForest`: Robust, non-parametric ensemble method\r\n- `GradientBoostingSurvivalAnalysis`: Tree-based boosting for maximum performance\r\n- `ComponentwiseGradientBoostingSurvivalAnalysis`: Linear boosting with feature selection\r\n- `ExtraSurvivalTrees`: Extremely randomized trees for additional regularization\r\n\r\n**See**: `references/ensemble-models.md` for comprehensive guidance on ensemble methods, hyperparameter tuning, and when to use each model\r\n\r\n#### Survival Support Vector Machines\r\n**Use for**: Medium-sized datasets with margin-based learning\r\n- `FastSurvivalSVM`: Linear SVM optimized for speed\r\n- `FastKernelSurvivalSVM`: Kernel SVM for non-linear relationships\r\n- `HingeLossSurvivalSVM`: SVM with hinge loss\r\n- `ClinicalKernelTransform`: Specialized kernel for clinical + molecular data\r\n\r\n**See**: `references/svm-models.md` for detailed SVM guidance, kernel selection, and hyperparameter tuning\r\n\r\n#### Model Selection Decision Tree\r\n\r\n```\r\nStart\r\n├─ High-dimensional data (p > n)?\r\n│  ├─ Yes → CoxnetSurvivalAnalysis (elastic net)\r\n│  └─ No → Continue\r\n│\r\n├─ Need interpretable coefficients?\r\n│  ├─ Yes → CoxPHSurvivalAnalysis or ComponentwiseGradientBoostingSurvivalAnalysis\r\n│  └─ No → Continue\r\n│\r\n├─ Complex non-linear relationships expected?\r\n│  ├─ Yes\r\n│  │  ├─ Large dataset (n > 1000) → GradientBoostingSurvivalAnalysis\r\n│  │  ├─ Medium dataset → RandomSurvivalForest or FastKernelSurvivalSVM\r\n│  │  └─ Small dataset → RandomSurvivalForest\r\n│  └─ No → CoxPHSurvivalAnalysis or FastSurvivalSVM\r\n│\r\n└─ For maximum performance → Try multiple models and compare\r\n```\r\n\r\n### 2. Data Preparation and Preprocessing\r\n\r\nBefore modeling, properly prepare survival data:\r\n\r\n#### Creating Survival Outcomes\r\n```python\r\nfrom sksurv.util import Surv\r\n\r\n# From separate arrays\r\ny = Surv.from_arrays(event=event_array, time=time_array)\r\n\r\n# From DataFrame\r\ny = Surv.from_dataframe('event', 'time', df)\r\n```\r\n\r\n#### Essential Preprocessing Steps\r\n1. **Handle missing values**: Imputation strategies for features\r\n2. **Encode categorical variables**: One-hot encoding or label encoding\r\n3. **Standardize features**: Critical for SVMs and regularized Cox models\r\n4. **Validate data quality**: Check for negative times, sufficient events per feature\r\n5. **Train-test split**: Maintain similar censoring rates across splits\r\n\r\n**See**: `references/data-handling.md` for complete preprocessing workflows, data validation, and best practices\r\n\r\n### 3. Model Evaluation\r\n\r\nProper evaluation is critical for survival models. Use appropriate metrics that account for censoring:\r\n\r\n#### Concordance Index (C-index)\r\nPrimary metric for ranking/discrimination:\r\n- **Harrell's C-index**: Use for low censoring (<40%)\r\n- **Uno's C-index**: Use for moderate to high censoring (>40%) - more robust\r\n\r\n```python\r\nfrom sksurv.metrics import concordance_index_censored, concordance_index_ipcw\r\n\r\n# Harrell's C-index\r\nc_harrell = concordance_index_censored(y_test['event'], y_test['time'], risk_scores)[0]\r\n\r\n# Uno's C-index (recommended)\r\nc_uno = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\n```\r\n\r\n#### Time-Dependent AUC\r\nEvaluate discrimination at specific time points:\r\n\r\n```python\r\nfrom sksurv.metrics import cumulative_dynamic_auc\r\n\r\ntimes = [365, 730, 1095]  # 1, 2, 3 years\r\nauc, mean_auc = cumulative_dynamic_auc(y_train, y_test, risk_scores, times)\r\n```\r\n\r\n#### Brier Score\r\nAssess both discrimination and calibration:\r\n\r\n```python\r\nfrom sksurv.metrics import integrated_brier_score\r\n\r\nibs = integrated_brier_score(y_train, y_test, survival_functions, times)\r\n```\r\n\r\n**See**: `references/evaluation-metrics.md` for comprehensive evaluation guidance, metric selection, and using scorers with cross-validation\r\n\r\n### 4. Competing Risks Analysis\r\n\r\nHandle situations with multiple mutually exclusive event types:\r\n\r\n```python\r\nfrom sksurv.nonparametric import cumulative_incidence_competing_risks\r\n\r\n# Estimate cumulative incidence for each event type\r\ntime_points, cif_event1, cif_event2 = cumulative_incidence_competing_risks(y)\r\n```\r\n\r\n**Use competing risks when**:\r\n- Multiple mutually exclusive event types exist (e.g., death from different causes)\r\n- Occurrence of one event prevents others\r\n- Need probability estimates for specific event types\r\n\r\n**See**: `references/competing-risks.md` for detailed competing risks methods, cause-specific hazard models, and interpretation\r\n\r\n### 5. Non-parametric Estimation\r\n\r\nEstimate survival functions without parametric assumptions:\r\n\r\n#### Kaplan-Meier Estimator\r\n```python\r\nfrom sksurv.nonparametric import kaplan_meier_estimator\r\n\r\ntime, survival_prob = kaplan_meier_estimator(y['event'], y['time'])\r\n```\r\n\r\n#### Nelson-Aalen Estimator\r\n```python\r\nfrom sksurv.nonparametric import nelson_aalen_estimator\r\n\r\ntime, cumulative_hazard = nelson_aalen_estimator(y['event'], y['time'])\r\n```\r\n\r\n## Typical Workflows\r\n\r\n### Workflow 1: Standard Survival Analysis\r\n\r\n```python\r\nfrom sksurv.datasets import load_breast_cancer\r\nfrom sksurv.linear_model import CoxPHSurvivalAnalysis\r\nfrom sksurv.metrics import concordance_index_ipcw\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.preprocessing import StandardScaler\r\n\r\n# 1. Load and prepare data\r\nX, y = load_breast_cancer()\r\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\r\n\r\n# 2. Preprocess\r\nscaler = StandardScaler()\r\nX_train_scaled = scaler.fit_transform(X_train)\r\nX_test_scaled = scaler.transform(X_test)\r\n\r\n# 3. Fit model\r\nestimator = CoxPHSurvivalAnalysis()\r\nestimator.fit(X_train_scaled, y_train)\r\n\r\n# 4. Predict\r\nrisk_scores = estimator.predict(X_test_scaled)\r\n\r\n# 5. Evaluate\r\nc_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\nprint(f\"C-index: {c_index:.3f}\")\r\n```\r\n\r\n### Workflow 2: High-Dimensional Data with Feature Selection\r\n\r\n```python\r\nfrom sksurv.linear_model import CoxnetSurvivalAnalysis\r\nfrom sklearn.model_selection import GridSearchCV\r\nfrom sksurv.metrics import as_concordance_index_ipcw_scorer\r\n\r\n# 1. Use penalized Cox for feature selection\r\nestimator = CoxnetSurvivalAnalysis(l1_ratio=0.9)  # Lasso-like\r\n\r\n# 2. Tune regularization with cross-validation\r\nparam_grid = {'alpha_min_ratio': [0.01, 0.001]}\r\ncv = GridSearchCV(estimator, param_grid,\r\n                  scoring=as_concordance_index_ipcw_scorer(), cv=5)\r\ncv.fit(X, y)\r\n\r\n# 3. Identify selected features\r\nbest_model = cv.best_estimator_\r\nselected_features = np.where(best_model.coef_ != 0)[0]\r\n```\r\n\r\n### Workflow 3: Ensemble Method for Maximum Performance\r\n\r\n```python\r\nfrom sksurv.ensemble import GradientBoostingSurvivalAnalysis\r\nfrom sklearn.model_selection import GridSearchCV\r\n\r\n# 1. Define parameter grid\r\nparam_grid = {\r\n    'learning_rate': [0.01, 0.05, 0.1],\r\n    'n_estimators': [100, 200, 300],\r\n    'max_depth': [3, 5, 7]\r\n}\r\n\r\n# 2. Grid search\r\ngbs = GradientBoostingSurvivalAnalysis()\r\ncv = GridSearchCV(gbs, param_grid, cv=5,\r\n                  scoring=as_concordance_index_ipcw_scorer(), n_jobs=-1)\r\ncv.fit(X_train, y_train)\r\n\r\n# 3. Evaluate best model\r\nbest_model = cv.best_estimator_\r\nrisk_scores = best_model.predict(X_test)\r\nc_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\n```\r\n\r\n### Workflow 4: Comprehensive Model Comparison\r\n\r\n```python\r\nfrom sksurv.linear_model import CoxPHSurvivalAnalysis\r\nfrom sksurv.ensemble import RandomSurvivalForest, GradientBoostingSurvivalAnalysis\r\nfrom sksurv.svm import FastSurvivalSVM\r\nfrom sksurv.metrics import concordance_index_ipcw, integrated_brier_score\r\n\r\n# Define models\r\nmodels = {\r\n    'Cox': CoxPHSurvivalAnalysis(),\r\n    'RSF': RandomSurvivalForest(n_estimators=100, random_state=42),\r\n    'GBS': GradientBoostingSurvivalAnalysis(random_state=42),\r\n    'SVM': FastSurvivalSVM(random_state=42)\r\n}\r\n\r\n# Evaluate each model\r\nresults = {}\r\nfor name, model in models.items():\r\n    model.fit(X_train_scaled, y_train)\r\n    risk_scores = model.predict(X_test_scaled)\r\n    c_index = concordance_index_ipcw(y_train, y_test, risk_scores)[0]\r\n    results[name] = c_index\r\n    print(f\"{name}: C-index = {c_index:.3f}\")\r\n\r\n# Select best model\r\nbest_model_name = max(results, key=results.get)\r\nprint(f\"\\nBest model: {best_model_name}\")\r\n```\r\n\r\n## Integration with scikit-learn\r\n\r\nscikit-survival fully integrates with scikit-learn's ecosystem:\r\n\r\n```python\r\nfrom sklearn.pipeline import Pipeline\r\nfrom sklearn.preprocessing import StandardScaler\r\nfrom sklearn.model_selection import cross_val_score, GridSearchCV\r\n\r\n# Use pipelines\r\npipeline = Pipeline([\r\n    ('scaler', StandardScaler()),\r\n    ('model', CoxPHSurvivalAnalysis())\r\n])\r\n\r\n# Use cross-validation\r\nscores = cross_val_score(pipeline, X, y, cv=5,\r\n                         scoring=as_concordance_index_ipcw_scorer())\r\n\r\n# Use grid search\r\nparam_grid = {'model__alpha': [0.1, 1.0, 10.0]}\r\ncv = GridSearchCV(pipeline, param_grid, cv=5)\r\ncv.fit(X, y)\r\n```\r\n\r\n## Best Practices\r\n\r\n1. **Always standardize features** for SVMs and regularized Cox models\r\n2. **Use Uno's C-index** instead of Harrell's when censoring > 40%\r\n3. **Report multiple evaluation metrics** (C-index, integrated Brier score, time-dependent AUC)\r\n4. **Check proportional hazards assumption** for Cox models\r\n5. **Use cross-validation** for hyperparameter tuning with appropriate scorers\r\n6. **Validate data quality** before modeling (check for negative times, sufficient events per feature)\r\n7. **Compare multiple model types** to find best performance\r\n8. **Use permutation importance** for Random Survival Forests (not built-in importance)\r\n9. **Consider competing risks** when multiple event types exist\r\n10. **Document censoring mechanism** and rates in analysis\r\n\r\n## Common Pitfalls to Avoid\r\n\r\n1. **Using Harrell's C-index with high censoring** → Use Uno's C-index\r\n2. **Not standardizing features for SVMs** → Always standardize\r\n3. **Forgetting to pass y_train to concordance_index_ipcw** → Required for IPCW calculation\r\n4. **Treating competing events as censored** → Use competing risks methods\r\n5. **Not checking for sufficient events per feature** → Rule of thumb: 10+ events per feature\r\n6. **Using built-in feature importance for RSF** → Use permutation importance\r\n7. **Ignoring proportional hazards assumption** → Validate or use alternative models\r\n8. **Not using appropriate scorers in cross-validation** → Use as_concordance_index_ipcw_scorer()\r\n\r\n## Reference Files\r\n\r\nThis skill includes detailed reference files for specific topics:\r\n\r\n- **`references/cox-models.md`**: Complete guide to Cox proportional hazards models, penalized Cox (CoxNet), IPCRidge, regularization strategies, and interpretation\r\n- **`references/ensemble-models.md`**: Random Survival Forests, Gradient Boosting, hyperparameter tuning, feature importance, and model selection\r\n- **`references/evaluation-metrics.md`**: Concordance index (Harrell's vs Uno's), time-dependent AUC, Brier score, comprehensive evaluation pipelines\r\n- **`references/data-handling.md`**: Data loading, preprocessing workflows, handling missing data, feature encoding, validation checks\r\n- **`references/svm-models.md`**: Survival Support Vector Machines, kernel selection, clinical kernel transform, hyperparameter tuning\r\n- **`references/competing-risks.md`**: Competing risks analysis, cumulative incidence functions, cause-specific hazard models\r\n\r\nLoad these reference files when detailed information is needed for specific tasks.\r\n\r\n## Additional Resources\r\n\r\n- **Official Documentation**: https://scikit-survival.readthedocs.io/\r\n- **GitHub Repository**: https://github.com/sebp/scikit-survival\r\n- **Built-in Datasets**: Use `sksurv.datasets` for practice datasets (GBSG2, WHAS500, veterans lung cancer, etc.)\r\n- **API Reference**: Complete list of classes and functions at https://scikit-survival.readthedocs.io/en/stable/api/index.html\r\n\r\n## Quick Reference: Key Imports\r\n\r\n```python\r\n# Models\r\nfrom sksurv.linear_model import CoxPHSurvivalAnalysis, CoxnetSurvivalAnalysis, IPCRidge\r\nfrom sksurv.ensemble import RandomSurvivalForest, GradientBoostingSurvivalAnalysis\r\nfrom sksurv.svm import FastSurvivalSVM, FastKernelSurvivalSVM\r\nfrom sksurv.tree import SurvivalTree\r\n\r\n# Evaluation metrics\r\nfrom sksurv.metrics import (\r\n    concordance_index_censored,\r\n    concordance_index_ipcw,\r\n    cumulative_dynamic_auc,\r\n    brier_score,\r\n    integrated_brier_score,\r\n    as_concordance_index_ipcw_scorer,\r\n    as_integrated_brier_score_scorer\r\n)\r\n\r\n# Non-parametric estimation\r\nfrom sksurv.nonparametric import (\r\n    kaplan_meier_estimator,\r\n    nelson_aalen_estimator,\r\n    cumulative_incidence_competing_risks\r\n)\r\n\r\n# Data handling\r\nfrom sksurv.util import Surv\r\nfrom sksurv.preprocessing import OneHotEncoder, encode_categorical\r\nfrom sksurv.datasets import load_gbsg2, load_breast_cancer, load_veterans_lung_cancer\r\n\r\n# Kernels\r\nfrom sksurv.kernels import ClinicalKernelTransform\r\n```"
  user_template: ""
variables: []
install:
  steps:
    - title: Download & unzip
      detail: >-
        Download the .zip package from SkillVault and unzip it. The scikit-survival/ folder contains
        SKILL.md plus any companion scripts, references and assets.
    - title: Copy into your agent skills directory
      detail: >-
        Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code),
        .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or
        reload the session.
    - title: Use it
      detail: >-
        Describe the task in natural language; the agent loads the skill automatically when the
        request matches the skill description.
usage:
  steps: []
metadata:
  author: SkillVault
  source: https://skillvault.top/skills/scikit-survival
  exported_at: "2026-11-03T07:44:00.486Z"

安装指南

  1. 1

    Download & unzip

    Download the .zip package from SkillVault and unzip it. The scikit-survival/ folder contains SKILL.md plus any companion scripts, references and assets.

  2. 2

    Copy into your agent skills directory

    Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code), .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or reload the session.

  3. 3

    Use it

    Describe the task in natural language; the agent loads the skill automatically when the request matches the skill description.

使用方法

平台兼容性

ChatGPT GPTs

OpenAI

将系统提示词粘贴到 GPT 的「Instructions」字段,并把用户模板作为起始消息使用。

官方文档

Claude Code

Anthropic

将导出的 .aiskill JSON 保存为项目中的技能文件,或将系统提示词粘贴进 CLAUDE.md / 斜杠命令 Markdown 文件。

官方文档

Cursor

Anysphere

将系统提示词复制到 .cursor/rules/*.mdc(或设置中的 Project Rules),并在智能体提示词中引用用户模板。

官方文档

相关技能

astropy AI agent skill cover
免费
ChatGPT GPTs Claude Code Cursor

astropy

Comprehensive Python library for astronomy and astrophysics. This skill should be used when working with astronomical data including celestial coordinates, physical units, FITS files, cosmological calculations, time systems, tables, world coordinate systems (WCS), and astronomical data analysis. Use when tasks involve coordinate transformations, unit conversions, FITS file manipulation, cosmological distance calculations, time scale conversions, or astronomical data processing.

#research-science#python
0 0 v1.0.0
fluidsim AI agent skill cover
免费
ChatGPT GPTs Claude Code Cursor

fluidsim

Framework for computational fluid dynamics simulations using Python. Use when running fluid dynamics simulations including Navier-Stokes equations (2D/3D), shallow water equations, stratified flows, or when analyzing turbulence, vortex dynamics, or geophysical flows. Provides pseudospectral methods with FFT, HPC support, and comprehensive output analysis.

#research-science#python
0 0 v1.0.0
geomaster AI agent skill cover
免费
ChatGPT GPTs Claude Code Cursor

geomaster

Comprehensive geospatial science skill covering remote sensing, GIS, spatial analysis, machine learning for earth observation, and 30+ scientific domains. Supports satellite imagery processing (Sentinel, Landsat, MODIS, SAR, hyperspectral), vector and raster data operations, spatial statistics, point cloud processing, network analysis, cloud-native workflows (STAC, COG, Planetary Computer), and 8 programming languages (Python, R, Julia, JavaScript, C++, Java, Go, Rust) with 500+ code examples. Use for remote sensing workflows, GIS analysis, spatial ML, Earth observation data processing, terrain analysis, hydrological modeling, marine spatial analysis, atmospheric science, and any geospatial computation task.

#research-science#infrastructure#python
0 0 v1.0.0