Skip to content

feat(resampling): add auc_ci, delta_auc_ci, bootstrap_ci - #66

Open
ywatanabe1989 wants to merge 3 commits into
developfrom
claude/agent-a8fb04472d12974ef
Open

feat(resampling): add auc_ci, delta_auc_ci, bootstrap_ci#66
ywatanabe1989 wants to merge 3 commits into
developfrom
claude/agent-a8fb04472d12974ef

Conversation

@ywatanabe1989

Copy link
Copy Markdown
Collaborator

Summary

  • Add auc_ci — DeLong (Sun & Xu 2014 fast midrank) or percentile-bootstrap 95% CI for a single ROC-AUC, no sklearn/raw-scipy exposure.
  • Add delta_auc_ci — DeLong paired test (full 2x2 covariance matrix, accounts for correlation between two classifiers scored on the same samples) or paired bootstrap CI for the difference of two AUCs, plus a two-sided p-value.
  • Add bootstrap_ci — generic percentile bootstrap CI for any metric function over one or more equal-length, paired-resampled arrays.
  • New resampling submodule + internal _delong.py shared math; wired into the __init__.py PEP 562 lazy loader (_LAZY_ATTRS / __all__).

Test plan

  • tests/scitex_stats/resampling/test__delong.py — midrank correctness, AUC=1.0 (perfect separation) / AUC=0.5 (complete overlap), valid covariance matrix entries.
  • tests/scitex_stats/resampling/test__auc_ci.py — delong + bootstrap point estimates, CI ordering, bootstrap reproducibility, all-same-class raises ValueError, small n_boot doesn't crash.
  • tests/scitex_stats/resampling/test__delta_auc_ci.py — delta correctness, CI ordering, the core DeLong covariance-awareness property (correlated scores give a narrower CI than a naive independent-variance sum), p-value sanity (near 0 for very different scores, large for identical scores), all-same-class raises, bootstrap variant.
  • tests/scitex_stats/resampling/test__bootstrap_ci.py — estimate/CI correctness, reproducibility, paired-resampling (shared indices across arrays) verified via an a==b identity-preserving fn.
  • All 30 new tests pass (/opt/venv-sac/bin/python3 -m pytest tests/scitex_stats/resampling/ -v).
  • Smoke-tested ss.auc_ci / ss.delta_auc_ci / ss.bootstrap_ci resolve via the lazy loader and return sane result dicts.
  • tests/scitex_stats/test__dispatch.py still passes (8/10; the 2 pre-existing failures are unrelated missing-figrecipe optional-dependency errors, not caused by this PR).

Add a new resampling submodule providing publication-ready confidence
intervals for ROC-AUC without any raw scipy/sklearn exposure:

- auc_ci: analytic DeLong (Sun and Xu 2014 fast midrank) or percentile
  bootstrap CI for a single AUC.
- delta_auc_ci: DeLong paired test / bootstrap CI for the difference
  of two correlated AUCs on the same samples, using the full DeLong
  covariance matrix (accounts for correlation between classifiers
  rather than naively summing independent variances).
- bootstrap_ci: generic paired percentile bootstrap CI for any metric
  function over one or more equal-length arrays.

Wired into the __init__.py lazy loader (_LAZY_ATTRS / __all__).
CI's audit-all flagged 18 STX-TQ002/TQ007 test-quality violations in
the new resampling test files (missing AAA marker comments and/or
more than one assertion per test). Split every multi-assert test into
separate single-assertion tests with descriptive names, and added the
literal `# Arrange` / `# Act` / `# Assert` marker comments (in order,
not combined) to every test body, matching the convention already
used elsewhere in this repo (e.g. tests/scitex_stats/descriptive/test__ci.py).

Verified locally: `scitex-dev linter check-files tests/scitex_stats/`
reports zero STX-TQ violations, and all 58 resampling tests still pass.
…mmend_tests

Dogfood follow-up (neurovista friction report):

- effect_sizes.effect_size_from_ci(estimate, ci_lower, ci_upper, ci=95):
  standardized effect size for metrics with only a point estimate + CI
  (bootstrap/analytic), back-deriving SE via the normal quantile so it
  generalizes to any confidence level. interpret_effect_size_from_ci
  reuses the existing Cohen's d interpretation thresholds.
- resampling.paired_auc_effect_size(y_true, score_a, score_b): matched-
  classifier effect size (delta_auc / SE) for two AUCs on the same
  samples, reusing delta_auc_ci's DeLong covariance machinery
  (_delong_two_auc_covar) rather than re-deriving it.
- auto.recommend_tests now also accepts two raw arrays + `paired`
  (recommend_tests(x, y, paired=True)) as a convenience overload,
  auto-building the StatContext internally. Implemented as a thin
  wrapper (_recommend_overload.py) that delegates to the existing
  context-based recommend_tests in _selector.py — no duplicated
  recommendation logic, and avoids growing _selector.py past the
  repo's 512-line file-size gate (it's already at the limit).

All new tests follow the one-assert-per-test + AAA marker-comment
convention; `scitex-dev linter check-files tests/` reports zero
STX-TQ violations across the whole tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant