Functional
jarvais.utils.functional
auprc(y_true, y_scores)
Calculate the Area Under the Precision-Recall Curve (AUPRC).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true
|
ndarray
|
True binary labels. Shape (n_samples,). |
required |
y_scores
|
ndarray
|
Predicted scores or probabilities. Shape (n_samples,). |
required |
Returns:
Name | Type | Description |
---|---|---|
auprc_score |
float
|
The AUPRC value. |
Source code in src/jarvais/utils/functional.py
9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
ci_wrapper(y_true, y_pred)
Wrapper for sksurv.metrics.concordance_index_censored
to ensure compatibility
with bootstrap_metric
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true
|
ndarray
|
A 2D NumPy array of shape (n_samples, 2), where:
- |
required |
y_pred
|
ndarray
|
A 1D NumPy array of predicted risk scores or survival times. Higher scores typically indicate higher risk. |
required |
Returns:
Name | Type | Description |
---|---|---|
concordance_index |
float
|
The concordance index. |
Source code in src/jarvais/utils/functional.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
bootstrap_metric(y_true, y_pred, metric_func, nsamples=100)
Compute a metric using bootstrapping to estimate its variability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true
|
ndarray
|
True labels. Shape (n_samples,). |
required |
y_pred
|
ndarray
|
Predicted values. Shape (n_samples,). |
required |
metric_func
|
Callable[[ndarray, ndarray], float]
|
A function that calculates the metric. |
required |
nsamples
|
int
|
The number of bootstrap samples. Defaults to 100. |
100
|
Returns:
Name | Type | Description |
---|---|---|
bootstrapped_values |
List[float]
|
A list of metric values computed on each bootstrap sample. |
Source code in src/jarvais/utils/functional.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
undummify(df, prefix_sep='_')
Undummifies a DataFrame by collapsing dummy/one-hot encoded columns back into their original categorical column.
Found here: https://stackoverflow.com/a/62085741
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing dummy/one-hot encoded columns. |
required |
prefix_sep
|
str
|
The separator used to distinguish between the prefix (category) and the column name in the dummy columns. Defaults to "_". |
'_'
|
Returns:
Name | Type | Description |
---|---|---|
undummified_df |
DataFrame
|
A new DataFrame with the undummified (reconstructed) categorical columns. |
Source code in src/jarvais/utils/functional.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
process_RADCURE_clinical(df)
Processes RADCURE clinical data.
Raw data found here: https://www.cancerimagingarchive.net/collection/radcure/
Source code in src/jarvais/utils/functional.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|