Metadata-Version: 2.4
Name: rsf-grid-search
Version: 0.1.0
Summary: Grid search over RandomSurvivalForest hyperparameters (min_samples_leaf, max_features, max_depth), scored by held-out Harrell's C-index.
Author: Kaylee
License-Expression: MIT
Project-URL: Homepage, https://pypi.org/project/rsf-grid-search/
Keywords: survival-analysis,random-survival-forest,hyperparameter-tuning,grid-search,concordance-index
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Intended Audience :: Science/Research
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.23
Requires-Dist: pandas>=1.5
Requires-Dist: scikit-learn>=1.1
Requires-Dist: scikit-survival>=0.19
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Dynamic: license-file

# rsf-grid-search

A small grid search over `RandomSurvivalForest` hyperparameters
(`min_samples_leaf`, `max_features`, `max_depth`), scored by Harrell's
concordance index on a held-out validation split.

Random survival forests have no closed-form regularization path the way a
penalized Cox model does, so their main regularization knobs are tuned by
grid search instead. `events_per_leaf` is reported alongside the C-index for
each combination as a rough diagnostic: a leaf with too few events gives an
unstable local Kaplan-Meier estimate, the survival-forest analogue of too
few events per parameter in a Cox model.

## Install

```bash
pip install rsf-grid-search
```

## Usage

```python
from rsf_grid_search import grid_rsf

results = grid_rsf(X, y, n_sub=30000, n_trees=300, seed=1)
print(results.head())
```

`X` is a `pandas.DataFrame` design matrix and `y` is a survival target in
scikit-survival's structured-array format (fields `"event"`, `"time"`, e.g.
built with `sksurv.util.Surv.from_arrays`).

If the training split is larger than `n_sub`, it is subsampled (stratified
on the event indicator) before the grid search, to keep each fit's runtime
bounded. The result is a `DataFrame`, one row per grid point, sorted by
descending validation C-index, with columns `leaf`, `max_features`, `depth`,
`events_per_leaf`, `c_index`, `secs`.

The default grid is `min_samples_leaf` in `(30, 60, 100, 150, 250)`,
`max_features` in `("sqrt", 0.2, 0.35, 0.6)`, and `max_depth` in
`(None, 10)`. Override any of them:

```python
results = grid_rsf(
    X, y,
    leaf_grid=(20, 50, 100),
    max_features_grid=("sqrt", 0.5),
    depth_grid=(None,),
)
```

## License

MIT
