Interoperability¶
Writing datasets to disk and handing them to other libraries. See Exporting data and Fitting models to the data.
Export¶
export
¶
Data export utilities for gen_surv.
This module provides helper functions to save generated survival datasets in various formats.
export_dataset
¶
Save a DataFrame to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing survival data. |
required |
path
|
str
|
File path to write to. The extension is used to infer the format
when |
required |
fmt
|
('csv', 'json', 'feather', 'rds')
|
Format to use. If omitted, inferred from |
"csv"
|
Raises:
| Type | Description |
|---|---|
ChoiceError
|
If the format is not one of the supported types. |
Source code in gen_surv/export.py
scikit-survival¶
integration
¶
Integration utilities for interfacing with scikit-survival.
to_sksurv
¶
Convert a pandas DataFrame to a scikit-survival structured array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing survival data |
required |
time_col
|
str
|
Name of the column containing survival times |
"time"
|
event_col
|
str
|
Name of the column containing event indicators (0/1 or boolean) |
"status"
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
structured array
|
Structured array suitable for scikit-survival functions |
Raises:
| Type | Description |
|---|---|
ImportError
|
If scikit-survival is not installed |
ValueError
|
If the DataFrame is empty or columns are missing |
Source code in gen_surv/integration.py
from_sksurv
¶
Convert a scikit-survival structured array to a pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
structured array
|
Structured array from scikit-survival |
required |
time_col
|
str
|
Name for the time column in the resulting DataFrame |
"time"
|
event_col
|
str
|
Name for the event column in the resulting DataFrame |
"status"
|
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
DataFrame with time and event columns |
Source code in gen_surv/integration.py
scikit-learn¶
sklearn_adapter
¶
BaseEstimatorProto
¶
Bases: Protocol
Protocol capturing the minimal scikit-learn estimator interface.
GenSurvDataGenerator
¶
Bases: SklearnBase, BaseEstimatorProto
Scikit-learn compatible wrapper around :func:gen_surv.generate.
Source code in gen_surv/sklearn_adapter.py
get_params
¶
Return every parameter, including the ones forwarded to the model.
scikit-learn builds this by introspecting __init__, which cannot see
through **kwargs. Without the override, clone -- and therefore
every pipeline, GridSearchCV and cross_val_score -- would drop
the model's parameters and produce an estimator that fails on use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deep
|
bool
|
Accepted for interface compatibility. There are no nested estimators, so it makes no difference. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
|
Source code in gen_surv/sklearn_adapter.py
set_params
¶
Set parameters, whether they belong to the wrapper or the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**params
|
object
|
Any of |
{}
|
Returns:
| Type | Description |
|---|---|
GenSurvDataGenerator
|
|