Commit abd9f6f
Keep permutation importance when coefficients fail; add importance_max_samples
Permutation importance came back empty for coxph, coxnet, fssvm, and
weibull_aft whenever the pipeline's selector step exposed no
selected_features_ (a chained feature_selector=[...] wraps a nested
Pipeline, and third-party selectors do not have the attribute at all). sklearn's
permutation_importance actually succeeded every time; the ValueError came
from the coefficient step that ran right after it inside the same try, and
the handler threw the computed importance away. Only those four models were
affected because they are the only wrappers that override
get_coefficients(); every other model short-circuits to a correct-length
NaN list and never reaches the bad path.
Splitting the work into two phases fixes that: a permutation failure still
returns the empty sentinel, but a coefficient problem now degrades only the
coefficient column to NaN. _get_coefficients is total, so it cannot hand a
wrong-length list to the DataFrame builder, and _get_selected_features
resolves names through a nested selector Pipeline and through
get_feature_names_out().
The same work turned up a silent wrong answer. _align_coefficients keyed
values positionally by the selector's order, but lifelines sorts Weibull-AFT
covariates, so on the ordinary feature_selector='topk' path every
weibull_aft coefficient landed on the wrong feature, sign flips included, in
both the report and the eval_importance sheet. Coefficients are now keyed by
the model's own index, which is what evaluation/_coefficients.py already
did, so the two surfaces agree.
Failures that remain are visible. log_metric_failure was resolving to
InternalWarning, which configure_default_filters ignores by default, so the
user saw a bare "failed (2.3s)." and nothing else. It now raises a
MetricFailureWarning naming the model and the exception type, and the
progress line carries the type too.
Also adds importance_max_samples, an opt-in cap on the test rows used for
permutation importance. The C-index term is superlinear in n_test, so on
large cohorts importance can out-cost model fitting. Default None keeps
every existing run byte-for-byte identical; the draw is seeded from
random_state so models stay comparable, and an unseeded draw warns. Threaded
through evaluate(), run(), tune(), and importance().
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent fe6e58b commit abd9f6f
12 files changed
Lines changed: 1265 additions & 94 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
38 | 55 | | |
39 | 56 | | |
40 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
84 | 100 | | |
85 | 101 | | |
86 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
| |||
318 | 319 | | |
319 | 320 | | |
320 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
321 | 328 | | |
322 | 329 | | |
323 | 330 | | |
| |||
456 | 463 | | |
457 | 464 | | |
458 | 465 | | |
| 466 | + | |
459 | 467 | | |
460 | 468 | | |
461 | 469 | | |
| |||
514 | 522 | | |
515 | 523 | | |
516 | 524 | | |
| 525 | + | |
517 | 526 | | |
518 | 527 | | |
519 | 528 | | |
| |||
551 | 560 | | |
552 | 561 | | |
553 | 562 | | |
| 563 | + | |
554 | 564 | | |
555 | 565 | | |
556 | 566 | | |
| |||
662 | 672 | | |
663 | 673 | | |
664 | 674 | | |
| 675 | + | |
665 | 676 | | |
666 | 677 | | |
667 | 678 | | |
| |||
861 | 872 | | |
862 | 873 | | |
863 | 874 | | |
| 875 | + | |
864 | 876 | | |
865 | 877 | | |
866 | 878 | | |
| |||
1695 | 1707 | | |
1696 | 1708 | | |
1697 | 1709 | | |
| 1710 | + | |
1698 | 1711 | | |
1699 | 1712 | | |
1700 | 1713 | | |
| |||
1821 | 1834 | | |
1822 | 1835 | | |
1823 | 1836 | | |
| 1837 | + | |
1824 | 1838 | | |
1825 | 1839 | | |
1826 | 1840 | | |
| |||
0 commit comments