Post Study
Octopus post-study package — prediction and analysis from saved studies.
Top-level imports provide the core prediction interface. Analysis functions (tables, plots, notebook wrappers) are available via submodule imports::
from octopus.poststudy import OctoPredictor, OctoTestEvaluator
from octopus.poststudy.analysis.tables import get_performance
from octopus.poststudy.analysis.plots import dev_performance_plot, performance_plot
from octopus.poststudy.analysis.notebook import display_study_overview
OctoPredictor
Bases: _PredictorBase
Ensemble model for predicting on new, unseen data.
Wraps the fitted models from a single task across all outer splits. All methods require explicit data — no test/train data is stored. All results are computed fresh from loaded models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_info
|
|
required | |
task_id
|
Concrete workflow task index (must be >= 0). |
required | |
result_type
|
Result type for filtering results (default: 'best'). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If task_id is negative, out of range, or no models found. |
FileNotFoundError
|
If expected study artifacts are missing. |
Example
info = load_study_information("studies/my_study") tp = OctoPredictor(study_info=info, task_id=0) predictions = tp.predict(new_data)
Source code in octopus/poststudy/predict/predictor.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 73 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
calculate_fi(data, fi_type=FIType.PERMUTATION, *, n_repeats=10, feature_groups=None, random_state=42, **kwargs)
Calculate feature importance on provided data across all outer splits.
Computes FI fresh from loaded models, providing p-values, confidence intervals, and group permutation support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to compute FI on (must contain features + target). |
required |
fi_type
|
FIType
|
Type of feature importance. One of:
- |
PERMUTATION
|
n_repeats
|
int
|
Number of permutation repeats (for permutation FI). |
10
|
feature_groups
|
dict[str, list[str]] | None
|
Dict mapping group names to feature lists
(for group_permutation). If None and fi_type is
|
None
|
random_state
|
int
|
Random seed. |
42
|
**kwargs
|
Any
|
Additional keyword arguments passed to the FI function.
For |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with feature importance results including a |
DataFrame
|
column and per-split + ensemble rows. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fi_type is unknown. |
Source code in octopus/poststudy/predict/predictor.py
load(path)
classmethod
Load a previously saved predictor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | UPath
|
Directory path containing the saved predictor. |
required |
Returns:
| Type | Description |
|---|---|
OctoPredictor
|
A new OctoPredictor instance that can predict without the |
OctoPredictor
|
original study directory. |
Source code in octopus/poststudy/predict/predictor.py
performance(data, metrics=None, threshold=0.5)
Compute performance on provided data per outersplit with Mean and Ensemble.
Each outer-split model is scored independently on the same data.
The Mean row averages per-split scores. The Ensemble row
scores the ensemble-averaged predictions against ground truth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to score on; must contain feature columns + target column. |
required |
metrics
|
list[str] | None
|
List of metric names to compute. If None, auto-detected from the ML type. |
None
|
threshold
|
float
|
Classification threshold for threshold-dependent metrics. |
0.5
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Wide DataFrame with outersplit IDs as index (plus |
DataFrame
|
|
Source code in octopus/poststudy/predict/predictor.py
predict(data)
Predict on new data using all outer-split models.
Return a wide-format DataFrame with one row per sample.
Columns: row_id, split_0, split_1, ..., ensemble.
For regression and time-to-event, the ensemble column is the
arithmetic mean of per-split predictions. For classification, it
contains class labels derived from the argmax of ensemble-averaged
probabilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame containing feature columns. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Wide-format DataFrame with per-split and ensemble predictions. |
Source code in octopus/poststudy/predict/predictor.py
predict_proba(data)
Predict probabilities on new data (classification/multiclass only).
Return a wide-format DataFrame with one row per sample.
Columns: row_id, one column per class label (ensemble-averaged),
then <class>_split_0, <class>_split_1, ... for per-split detail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame containing feature columns. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Wide-format DataFrame with ensemble and per-split probabilities. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ml_type is not classification or multiclass. |
Source code in octopus/poststudy/predict/predictor.py
save(path)
Save the predictor for standalone deployment.
Writes a self-contained directory with models + metadata only (no data). The saved predictor can be loaded later without the original study directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | UPath
|
Directory path to save to. Created if it doesn't exist. |
required |
Source code in octopus/poststudy/predict/predictor.py
OctoTestEvaluator
Bases: _PredictorBase
Predictor for analysing study results on held-out test data.
Stores test and train data per outer split. Methods use stored test data implicitly — the caller never needs to pass data.
Each outer-split model predicts only on its corresponding test data. No averaging across splits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_info
|
|
required | |
task_id
|
Concrete workflow task index (must be >= 0). |
required | |
result_type
|
Result type for filtering results (default: 'best'). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If task_id is negative, out of range, or no models found. |
FileNotFoundError
|
If expected study artifacts are missing. |
Example
info = load_study_information("studies/my_study") tp = OctoTestEvaluator(study_info=info, task_id=0) scores = tp.performance(metrics=["AUCROC", "ACC"])
Source code in octopus/poststudy/analysis/evaluator.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 73 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
__attrs_post_init__()
Load base artifacts via parent, then additionally load test/train data.
Source code in octopus/poststudy/analysis/evaluator.py
calculate_fi(fi_type=FIType.PERMUTATION, *, n_repeats=10, feature_groups=None, random_state=42, **kwargs)
Calculate feature importance using stored test data and models.
Each split's model permutes features only in its own test data.
Delegates to _dispatch_fi() (inherited from _PredictorBase)
with stored per-split test and train data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fi_type
|
FIType
|
Type of feature importance. One of:
- |
PERMUTATION
|
n_repeats
|
int
|
Number of permutation repeats. |
10
|
feature_groups
|
dict[str, list[str]] | None
|
Dict mapping group names to feature lists.
If None and fi_type is |
None
|
random_state
|
int
|
Random seed. |
42
|
**kwargs
|
Any
|
Additional keyword arguments passed to the FI function.
For |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with feature importance results including a |
DataFrame
|
column and per-split + ensemble rows. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fi_type is unknown. |
Source code in octopus/poststudy/analysis/evaluator.py
performance(metrics=None, threshold=0.5)
Compute performance on stored test data per outersplit with Mean and Merged.
Each outer-split model is scored only on its own test data.
The Mean row averages per-split scores. The Merged row
pools all test predictions and scores them as one set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
list[str] | None
|
List of metric names to compute. If None, auto-detected from the ML type. |
None
|
threshold
|
float
|
Classification threshold for threshold-dependent metrics. |
0.5
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Wide DataFrame with outersplit IDs as index (plus |
DataFrame
|
|
Source code in octopus/poststudy/analysis/evaluator.py
predict()
Predict on stored test data. Each model predicts only on its own test data.
No ensemble averaging — results are collected per split.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: |
DataFrame
|
and target column(s). For T2E tasks the target columns are |
DataFrame
|
|
Source code in octopus/poststudy/analysis/evaluator.py
predict_proba()
Predict probabilities on stored test data (classification/multiclass only).
Each model predicts only on its own test data. No averaging.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: |
DataFrame
|
column per class label, and target column(s). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ml_type is not classification or multiclass. |
Source code in octopus/poststudy/analysis/evaluator.py
StudyInfo
Validated, immutable view of a completed study directory.
Returned by load_study_information(). Accepted by both analysis
functions and predictor constructors. Does NOT store the raw config
dict — all values are typed extractions.
Source code in octopus/poststudy/study_io.py
n_outersplits
property
Number of outer splits.
outersplits
property
Outersplit IDs.
Resolution order:
1. Explicit outersplit_ids (set by OctoPredictor.load()).
2. Derived from outersplit_dirs (normal study path).
3. range(n_outer_splits) (last resort).
load_study_information(study_directory)
Load and validate a study directory.
Reads study_config.json, discovers outersplit directories,
validates structure, and extracts typed metadata into a frozen
StudyInfo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_directory
|
str | UPath
|
Path to the study directory. |
required |
Returns:
| Type | Description |
|---|---|
StudyInfo
|
Frozen |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no outersplit directories are found. |
FileNotFoundError
|
If the study directory or config does not exist. |