octopus.predict
Octopus predict package — standalone prediction and analysis from saved studies.
TaskPredictor
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_path
|
Path to the study directory. |
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
tp = TaskPredictor("studies/my_study", task_id=0) predictions = tp.predict(new_data, df=True)
Source code in octopus/predict/task_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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
classes_
property
Class labels from the first model (classification only).
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the model does not have a classes_ attribute. |
config
property
Full study configuration dictionary.
Note
After TaskPredictor.load(), this returns an empty dict
because the full config is not serialized — only the metadata
fields needed for prediction are saved.
feature_cols
property
Input feature column names from study config.
feature_cols_per_split
property
Input feature columns per outersplit (loaded from disk).
feature_groups_per_split
property
Feature groups per outersplit (loaded from disk).
ml_type
property
Machine learning type (classification, regression, timetoevent).
n_outersplits
property
Number of loaded outersplits.
outersplits
property
List of loaded outersplit IDs.
positive_class
property
Positive class label for classification.
row_id_col
property
Row ID column name.
target_assignments
property
Target column assignments from prepared config.
target_col
property
Target column name from config.
target_metric
property
Target metric name.
__attrs_post_init__()
Load config, validate, and load artifacts from the study directory.
Source code in octopus/predict/task_predictor.py
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/predict/task_predictor.py
get_model(outersplit_id)
Get the fitted model for an outersplit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outersplit_id
|
int
|
Outer split index. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The fitted model object. |
get_selected_features(outersplit_id)
Get selected features for an outersplit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outersplit_id
|
int
|
Outer split index. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of selected feature names. |
Source code in octopus/predict/task_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 |
|---|---|
TaskPredictor
|
A new TaskPredictor instance that can predict without the |
TaskPredictor
|
original study directory. |
Source code in octopus/predict/task_predictor.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
performance(data, metrics=None, threshold=0.5)
Compute performance scores on provided data for each outer split.
Each outer-split model is scored independently on the same data. Scores are computed fresh — never read from disk.
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, uses the study target metric. |
None
|
threshold
|
float
|
Classification threshold for threshold-dependent metrics. |
0.5
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: outersplit, metric, score. |
Source code in octopus/predict/task_predictor.py
predict(data, df=False)
Predict on new data using all outer-split models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame containing feature columns. |
required |
df
|
bool
|
If True, return a DataFrame with per-outersplit predictions
and ensemble (averaged) predictions, with columns
|
False
|
Returns:
| Type | Description |
|---|---|
ndarray | DataFrame
|
Ensemble-averaged predictions as ndarray, or a DataFrame with |
ndarray | DataFrame
|
per-split and ensemble rows when |
Source code in octopus/predict/task_predictor.py
predict_proba(data, df=False)
Predict probabilities on new data (classification/multiclass only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame containing feature columns. |
required |
df
|
bool
|
If True, return a DataFrame with per-outersplit probabilities
and ensemble (averaged) probabilities, with columns
|
False
|
Returns:
| Type | Description |
|---|---|
ndarray | DataFrame
|
Ensemble-averaged probabilities as ndarray, or a DataFrame with |
ndarray | DataFrame
|
per-split and ensemble rows when |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ml_type is not classification or multiclass. |
Source code in octopus/predict/task_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/predict/task_predictor.py
TaskPredictorTest
Bases: TaskPredictor
Predictor for analysing study results on held-out test data.
Inherits from TaskPredictor and additionally stores test and train
data. Overrides predict, predict_proba, performance, and
calculate_fi to 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_path
|
Path to the study directory. |
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
tp = TaskPredictorTest("studies/my_study", task_id=0) scores = tp.performance(metrics=["AUCROC", "ACC"])
Source code in octopus/predict/task_predictor_test.py
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 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 | |
__attrs_post_init__()
Load base artifacts via parent, then additionally load test/train data.
Source code in octopus/predict/task_predictor_test.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 TaskPredictor)
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/predict/task_predictor_test.py
load(path)
classmethod
Not supported for TaskPredictorTest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | UPath
|
Ignored — not used. |
required |
Returns:
| Type | Description |
|---|---|
TaskPredictorTest
|
Never returns — always raises. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. Use TaskPredictor.load() for loading saved predictors. |
Source code in octopus/predict/task_predictor_test.py
performance(metrics=None, threshold=0.5)
Compute performance scores on stored test data.
Each outer-split model is scored only on its own test data. Scores are computed fresh — never read from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
list[str] | None
|
List of metric names to compute. If None, uses the study target metric. |
None
|
threshold
|
float
|
Classification threshold for threshold-dependent metrics. |
0.5
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: outersplit, metric, score. |
Source code in octopus/predict/task_predictor_test.py
predict(df=False)
Predict on stored test data. Each model predicts only on its own test data.
No ensemble averaging — results are collected per split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
bool
|
If True, return a DataFrame with outersplit, row_id, prediction,
and target columns. For T2E tasks the target columns are
|
False
|
Returns:
| Type | Description |
|---|---|
ndarray | DataFrame
|
Per-split predictions as ndarray or DataFrame. |
Source code in octopus/predict/task_predictor_test.py
predict_proba(df=False)
Predict probabilities on stored test data (classification/multiclass only).
Each model predicts only on its own test data. No averaging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
bool
|
If True, return a DataFrame with outersplit, row_id, probability columns per class, and target column(s). If False (default), return concatenated ndarray. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | DataFrame
|
Per-split probabilities as ndarray or DataFrame. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ml_type is not classification or multiclass. |
Source code in octopus/predict/task_predictor_test.py
save(path)
Not supported for TaskPredictorTest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | UPath
|
Ignored — not used. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. The study directory is the persistent artifact for test predictors. |