evalsuite-python 1.1.2__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/CHANGELOG.md +43 -0
  2. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/PKG-INFO +115 -7
  3. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/README.md +110 -6
  4. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/pyproject.toml +3 -0
  5. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/Cargo.lock +6 -6
  6. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/Cargo.toml +1 -1
  7. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/__init__.py +51 -0
  8. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/_evalci.py +140 -0
  9. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/api.py +5 -0
  10. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/cli/main.py +40 -1
  11. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/result.py +17 -7
  12. evalsuite_python-1.2.0/src/evalsuite/fairness.py +382 -0
  13. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/harness.py +35 -2
  14. evalsuite_python-1.2.0/src/evalsuite/html_report.py +150 -0
  15. evalsuite_python-1.2.0/src/evalsuite/judging.py +500 -0
  16. evalsuite_python-1.2.0/src/evalsuite/llm_benchmarks.py +193 -0
  17. evalsuite_python-1.2.0/src/evalsuite/rag_report.py +240 -0
  18. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/intervals.py +114 -0
  19. evalsuite_python-1.2.0/src/evalsuite/stats/planning.py +338 -0
  20. evalsuite_python-1.2.0/src/evalsuite/survival.py +354 -0
  21. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/version.py +1 -1
  22. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/integration/test_readme_examples.py +1 -0
  23. evalsuite_python-1.2.0/tests/test_v12.py +325 -0
  24. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/CONTRIBUTING.md +0 -0
  25. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/LICENSE +0 -0
  26. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/LICENSE-APACHE +0 -0
  27. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/Cargo.toml +0 -0
  28. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/README.md +0 -0
  29. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/agreement.rs +0 -0
  30. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/coco.rs +0 -0
  31. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/curve.rs +0 -0
  32. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/groups.rs +0 -0
  33. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/hash.rs +0 -0
  34. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/lib.rs +0 -0
  35. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/meteor.rs +0 -0
  36. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/permutation.rs +0 -0
  37. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/qa.rs +0 -0
  38. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/ranks.rs +0 -0
  39. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/resample.rs +0 -0
  40. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/surface.rs +0 -0
  41. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/ter.rs +0 -0
  42. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-core/src/text.rs +0 -0
  43. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-py/Cargo.toml +0 -0
  44. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/rust/evalsuite-py/src/lib.rs +0 -0
  45. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/__main__.py +0 -0
  46. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/_bench_metrics.py +0 -0
  47. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/_lazy.py +0 -0
  48. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/_native.py +0 -0
  49. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/_update.py +0 -0
  50. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/benchmarks.py +0 -0
  51. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/calibration.py +0 -0
  52. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/cards.py +0 -0
  53. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/classification/__init__.py +0 -0
  54. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/classification/_common.py +0 -0
  55. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/classification/metrics.py +0 -0
  56. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/cli/__init__.py +0 -0
  57. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/clinical/__init__.py +0 -0
  58. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/clinical/metrics.py +0 -0
  59. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/clinical/report.py +0 -0
  60. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/__init__.py +0 -0
  61. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/context.py +0 -0
  62. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/exceptions.py +0 -0
  63. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/export.py +0 -0
  64. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/registry.py +0 -0
  65. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/types.py +0 -0
  66. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/core/validation.py +0 -0
  67. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/integrations.py +0 -0
  68. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/__init__.py +0 -0
  69. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/_common.py +0 -0
  70. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/agents.py +0 -0
  71. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/code.py +0 -0
  72. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/efficiency.py +0 -0
  73. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/longcontext.py +0 -0
  74. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/multilingual.py +0 -0
  75. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/robustness.py +0 -0
  76. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/safety.py +0 -0
  77. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/llmsys/uncertainty.py +0 -0
  78. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/monitor.py +0 -0
  79. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/plot.py +0 -0
  80. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/py.typed +0 -0
  81. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/regression/__init__.py +0 -0
  82. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/regression/metrics.py +0 -0
  83. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/reporting.py +0 -0
  84. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/__init__.py +0 -0
  85. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/_resolve.py +0 -0
  86. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/compare.py +0 -0
  87. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/effect.py +0 -0
  88. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/hypothesis.py +0 -0
  89. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/paired.py +0 -0
  90. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/stats/results.py +0 -0
  91. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/__init__.py +0 -0
  92. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/_common.py +0 -0
  93. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/factuality.py +0 -0
  94. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/generation.py +0 -0
  95. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/judge.py +0 -0
  96. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/qa.py +0 -0
  97. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/rag.py +0 -0
  98. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/reasoning.py +0 -0
  99. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/report.py +0 -0
  100. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/retrieval.py +0 -0
  101. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/semantic.py +0 -0
  102. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/spice.py +0 -0
  103. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/text/structured.py +0 -0
  104. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/vision/__init__.py +0 -0
  105. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/vision/detection.py +0 -0
  106. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/src/evalsuite/vision/segmentation.py +0 -0
  107. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/__init__.py +0 -0
  108. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/classification/__init__.py +0 -0
  109. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/classification/test_against_sklearn.py +0 -0
  110. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/clinical/__init__.py +0 -0
  111. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/clinical/test_outputs.py +0 -0
  112. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/clinical/test_v020.py +0 -0
  113. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/conftest.py +0 -0
  114. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/integration/__init__.py +0 -0
  115. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/integration/test_qa.py +0 -0
  116. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/integration/test_repo_hygiene.py +0 -0
  117. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/llmsys/__init__.py +0 -0
  118. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/llmsys/test_code_longcontext_efficiency.py +0 -0
  119. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/llmsys/test_edges.py +0 -0
  120. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/llmsys/test_fast_text.py +0 -0
  121. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/llmsys/test_hardening.py +0 -0
  122. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/llmsys/test_safety_robustness.py +0 -0
  123. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/llmsys/test_uncertainty_agents_multilingual.py +0 -0
  124. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/output/__init__.py +0 -0
  125. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/output/test_benchmarks.py +0 -0
  126. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/output/test_cli.py +0 -0
  127. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/output/test_plot.py +0 -0
  128. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/output/test_reporting.py +0 -0
  129. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/regression/__init__.py +0 -0
  130. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/regression/test_against_sklearn.py +0 -0
  131. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/stats/__init__.py +0 -0
  132. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/stats/test_branches.py +0 -0
  133. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/stats/test_compare.py +0 -0
  134. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/stats/test_fast_paths.py +0 -0
  135. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/stats/test_reference.py +0 -0
  136. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/test_cards.py +0 -0
  137. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/test_harness.py +0 -0
  138. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/test_integrations.py +0 -0
  139. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/test_monitor.py +0 -0
  140. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/test_native.py +0 -0
  141. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/test_update.py +0 -0
  142. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/test_v111_fixes.py +0 -0
  143. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/text/__init__.py +0 -0
  144. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/text/test_against_references.py +0 -0
  145. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/text/test_text_edges.py +0 -0
  146. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/text/test_v040.py +0 -0
  147. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/unit/__init__.py +0 -0
  148. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/unit/test_core.py +0 -0
  149. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/unit/test_edges.py +0 -0
  150. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/vision/__init__.py +0 -0
  151. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/vision/test_detection.py +0 -0
  152. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/vision/test_edges.py +0 -0
  153. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/vision/test_outputs.py +0 -0
  154. {evalsuite_python-1.1.2 → evalsuite_python-1.2.0}/tests/vision/test_segmentation.py +0 -0
@@ -6,6 +6,49 @@ All notable changes to this project are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2026-11-26
10
+
11
+ EvalSuite for LLM evaluation and research-grade statistics.
12
+
13
+ ### Added
14
+ - **LLM benchmark presets**: `es.leaderboard(..., benchmark="gsm8k" | "mmlu" | "arc" | "arc-easy" |
15
+ "truthfulqa" | "humaneval")` sets the scorer; `es.load_benchmark(name)` returns prompts, gold answers and
16
+ categories (MMLU subjects) from the Hugging Face Hub (`[benchmarks]` extra); `es.format_multiple_choice`.
17
+ HumanEval records carry `passed` or `n_samples` / `n_correct` from your own sandbox (EvalSuite never runs
18
+ model-generated code). `evalsuite leaderboard --benchmark`.
19
+ - **`es.judge_report`**: win rates (Wilson) and Bradley–Terry ratings (bootstrap) from pairwise verdicts, with
20
+ position consistency and first-position preference, length bias, self-preference and agreement with human
21
+ verdicts (Cohen's kappa with a bootstrap interval); each bias tested and flagged only when significant.
22
+ **`es.rubric_report`**: rubric means with t intervals, inter-rater Krippendorff's alpha, Spearman
23
+ correlation with human scores.
24
+ - **`es.rag_report`**: hit rate / recall / MRR at k, exact match, token F1 and grounded rate with intervals, and
25
+ every question classified as correct, retrieval failure, generation failure, unsupported-but-correct or
26
+ unknown cause, with the biggest problem named.
27
+ - **`es.html_report`**: one self-contained HTML file (no scripts, no external requests) from any EvalSuite
28
+ results, Matplotlib figures and Markdown text, with a provenance footer.
29
+ - **Planning**: `sample_size_proportion`, `sample_size_two_proportions` (paired McNemar, Connor 1987;
30
+ unpaired, Fleiss et al.), `sample_size_auc` (Hanley & McNeil; Obuchowski), `sample_size_mean_difference`, and
31
+ `power_*` counterparts; checked against statsmodels and by simulation.
32
+ - **Clustered intervals**: `bootstrap_ci(..., clusters=)` and `evaluate(..., clusters=)` resample whole clusters
33
+ (patients, documents, sites) for every interval and paired baseline test; in a simulation with 60 patients
34
+ of 10 scans, 95% intervals covered the truth 93% of the time against 77% for ordinary intervals.
35
+ - **`es.fairness_report`**: per-group selection rate, TPR, FPR, PPV, accuracy (Wilson), ROC AUC (DeLong) and
36
+ calibration-in-the-large; demographic parity difference / ratio, equalized odds, equal opportunity and
37
+ predictive parity gaps with bootstrap intervals; intersectional groups; Fisher tests against a reference
38
+ group, Holm-adjusted. Gap values identical to Fairlearn's.
39
+ - **Survival metrics**: `concordance_index` (Harrell; Uno's IPCW with `ipcw=True`, optional bootstrap
40
+ interval), `time_dependent_auc`, `brier_score_survival`, `integrated_brier_score`, `kaplan_meier`;
41
+ identical to scikit-survival (to 1e-15), Harrell's C 17× faster on 100,000 subjects.
42
+ - **GitHub Action** (`uses: mkcs28/evalsuite-python@v1.2.0`): evaluates a predictions file on every pull
43
+ request, comments metrics with intervals and paired tests (updating its own comment), writes the job summary
44
+ and can fail on a significant regression. The CLI gains `evaluate --baseline-pred/--baseline-prob
45
+ --clusters --ci --fail-on-regression`.
46
+ - CI builds and tests the R package on Windows; an upgrade banner in the README for users of older versions.
47
+
48
+ ### Changed
49
+ - `EvaluationResult.to_html()` shows intervals and baseline tests, like the Markdown and LaTeX exports.
50
+ - Per-metric benchmark table (all registered metrics) re-run on 1.2.0.
51
+
9
52
  ## [1.1.2] - 2026-11-26
10
53
 
11
54
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evalsuite-python
3
- Version: 1.1.2
3
+ Version: 1.2.0
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Intended Audience :: Science/Research
6
6
  Classifier: Intended Audience :: Healthcare Industry
@@ -26,11 +26,14 @@ Requires-Dist: pandas>=1.4
26
26
  Requires-Dist: matplotlib>=3.5 ; extra == 'all'
27
27
  Requires-Dist: pillow>=9 ; extra == 'all'
28
28
  Requires-Dist: nltk>=3.8 ; extra == 'all'
29
+ Requires-Dist: datasets>=2.14 ; extra == 'benchmarks'
29
30
  Requires-Dist: pytest>=7 ; extra == 'dev'
30
31
  Requires-Dist: pytest-cov>=4 ; extra == 'dev'
31
32
  Requires-Dist: hypothesis>=6.80 ; extra == 'dev'
32
33
  Requires-Dist: scikit-learn>=1.4 ; extra == 'dev'
33
34
  Requires-Dist: statsmodels>=0.13 ; extra == 'dev'
35
+ Requires-Dist: scikit-survival>=0.22 ; python_full_version >= '3.10' and extra == 'dev'
36
+ Requires-Dist: fairlearn>=0.10 ; extra == 'dev'
34
37
  Requires-Dist: matplotlib>=3.5 ; extra == 'dev'
35
38
  Requires-Dist: pillow>=9 ; extra == 'dev'
36
39
  Requires-Dist: pycocotools>=2.0.7 ; extra == 'dev'
@@ -60,6 +63,7 @@ Requires-Dist: scikit-learn>=1.2 ; extra == 'sklearn'
60
63
  Requires-Dist: pillow>=9 ; extra == 'vision'
61
64
  Requires-Dist: wandb>=0.16 ; extra == 'wandb'
62
65
  Provides-Extra: all
66
+ Provides-Extra: benchmarks
63
67
  Provides-Extra: dev
64
68
  Provides-Extra: docx
65
69
  Provides-Extra: keras
@@ -97,11 +101,20 @@ Project-URL: Source, https://github.com/mkcs28/evalsuite-python
97
101
  EvalSuite brings classification, regression, clinical, statistical, segmentation and object-detection
98
102
  evaluation into one consistent, validated, documented framework.
99
103
 
100
- > **Status: stable (1.1.2).** [Example notebooks](notebooks/README.md) (Colab) ·
104
+ > **On an older version? Upgrade once:** `pip install -U evalsuite-python`. From 1.1.2 on, EvalSuite tells you
105
+ > when a newer release is out (`evalsuite upgrade`).
106
+
107
+ > **Status: stable (1.2.0).** [Example notebooks](notebooks/README.md) (Colab) ·
101
108
  > [in-browser tools](https://evalsuite-nine.vercel.app/tools) · [changelog](CHANGELOG.md)
102
109
 
103
110
  **What's new**
104
111
 
112
+ - **1.2** — LLM evaluation and research-grade statistics: benchmark presets (GSM8K, MMLU, ARC, TruthfulQA,
113
+ HumanEval) for the leaderboard, a judge report (win rates, position / length / self-preference bias, agreement
114
+ with humans), rubric reports, an end-to-end RAG report that blames each failure on retrieval or generation, a
115
+ single-file HTML report; sample-size and power planning, cluster-bootstrap intervals (`clusters=`), a fairness
116
+ report (gaps with intervals, intersectional groups) and survival metrics (C-index, time-dependent AUC,
117
+ integrated Brier score); a GitHub Action that comments results on pull requests.
105
118
  - **1.1.2** — a once-a-day notice when a newer release exists, and a one-command upgrade (`evalsuite upgrade`
106
119
  or `es.upgrade()`); every README refreshed with current benchmark numbers.
107
120
  - **1.1.1** — hardening: every engine metric fuzzed (no crashes on malformed input), NaN / Infinity preserved in
@@ -436,6 +449,101 @@ ei.log_mlflow(result)
436
449
  ei.log_wandb(result)
437
450
  ```
438
451
 
452
+ ## Planning a test set
453
+
454
+ ```python
455
+ es.sample_size_two_proportions(0.80, 0.83, discordance=0.10) # items to detect +3 points between two models
456
+ es.sample_size_proportion(0.9, 0.02) # items for accuracy ± 2 points
457
+ es.sample_size_auc(0.85, prevalence=0.2, half_width=0.03) # positives and negatives for an AUC interval
458
+ es.power_two_proportions(500, 0.80, 0.83, discordance=0.10) # power with the items you have
459
+ ```
460
+
461
+ ## Clustered data
462
+
463
+ Several scans per patient, several questions per document or several sites make ordinary intervals too narrow.
464
+ Pass the cluster of each row and every interval and baseline test resamples whole clusters:
465
+
466
+ ```python
467
+ patient = np.repeat(np.arange(40), 5) # 200 rows, 5 per patient
468
+ result = es.evaluate(y_true, y_pred, clusters=patient)
469
+ es.bootstrap_ci("roc_auc", y_true, y_prob=y_prob, clusters=patient)
470
+ ```
471
+
472
+ ## Fairness
473
+
474
+ ```python
475
+ group = np.where(np.arange(200) % 3 == 0, "A", "B")
476
+ report = es.fairness_report(y_true, y_pred, y_prob, groups={"group": group})
477
+ print(report.summary()) # per-group rates with CIs, parity / equalized-odds gaps with CIs, Holm-adjusted tests
478
+ ```
479
+
480
+ Several attributes give intersectional groups (`groups={"sex": sex, "age": age}`); gap definitions match
481
+ Fairlearn's.
482
+
483
+ ## Survival analysis
484
+
485
+ ```python
486
+ time = np.arange(1, 201) * 0.5
487
+ event = np.arange(200) % 4 != 0
488
+ risk = -time + np.sin(np.arange(200))
489
+ es.concordance_index(time, event, risk) # Harrell's C (ipcw=True: Uno's C)
490
+ es.time_dependent_auc(time, event, risk, [20, 40, 60]) # cumulative/dynamic AUC
491
+ ```
492
+
493
+ `brier_score_survival` and `integrated_brier_score` take predicted survival probabilities. All agree with
494
+ scikit-survival to 1e-15 (Harrell's C is about 17× faster).
495
+
496
+ ## LLM judges, rubrics and RAG
497
+
498
+ ```python
499
+ judgements = [
500
+ {"model_a": "m1", "model_b": "m2", "verdict": "A", "verdict_swapped": "A", "length_a": 120, "length_b": 80},
501
+ {"model_a": "m2", "model_b": "m1", "verdict": "B", "verdict_swapped": "tie", "length_a": 60, "length_b": 150},
502
+ {"model_a": "m1", "model_b": "m2", "verdict": "tie", "verdict_swapped": "tie", "length_a": 90, "length_b": 95},
503
+ ]
504
+ print(es.judge_report(judgements, n_resamples=200).summary())
505
+ # win rates, Bradley–Terry, position consistency, length bias, self-preference, agreement with humans
506
+
507
+ rag = es.rag_report(
508
+ [
509
+ {"retrieved": ["d1", "d7"], "relevant": ["d1"], "answer": "Paris", "reference": "Paris"},
510
+ {"retrieved": ["d3"], "relevant": ["d2"], "answer": "Rome", "reference": "Oslo"},
511
+ ]
512
+ )
513
+ print(rag.summary()) # retrieval / grounding / answer metrics, and each failure blamed on a stage
514
+ ```
515
+
516
+ Leaderboards know common benchmarks: `es.leaderboard(runs, benchmark="gsm8k", references=es.load_benchmark("gsm8k"))`
517
+ (also `mmlu`, `arc`, `truthfulqa`, `humaneval`; datasets via `pip install "evalsuite-python[benchmarks]"`).
518
+
519
+ ## One HTML report
520
+
521
+ ```python
522
+ page = es.html_report(
523
+ {"Test set": es.evaluate(y_true, y_pred, y_prob=y_prob), "Notes": "Model v3."},
524
+ title="Model evaluation",
525
+ path="report.html",
526
+ )
527
+ ```
528
+
529
+ Any EvalSuite result, Matplotlib figure or Markdown text becomes a section of one self-contained file (no
530
+ scripts, no external requests).
531
+
532
+ ## Evaluation in pull requests
533
+
534
+ ```yaml
535
+ - uses: mkcs28/evalsuite-python@v1.2.0
536
+ with:
537
+ predictions: predictions.csv
538
+ y-true: label
539
+ y-pred: pred
540
+ baseline-pred: base_pred # e.g. the main branch's predictions
541
+ fail-on-regression: "true"
542
+ ```
543
+
544
+ The action comments metrics with intervals and paired tests on the pull request and fails it on a significant
545
+ regression ([full example](examples/evalsuite-action.yml)).
546
+
439
547
  ## Classification report
440
548
 
441
549
  ```python
@@ -532,11 +640,11 @@ metric calls. At 1,000,000 samples (pixels for segmentation; 1,000 images for de
532
640
  | text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 219.5 | 889.0 | **4.05×** |
533
641
  | text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 266.7 | 2399.8 | **9.00×** |
534
642
 
535
- **Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`, last full run with 0.7.1): all 225
536
- registered metrics and statistics functions at 10,000 and 100,000 samples. 86 are compared with a reference library, 118 with an
537
- independent textbook formula and 21 (learned, judge-dependent or randomised) are timed alone; **all 204
538
- comparisons agree**, and against the libraries the geometric-mean speed-up is **6.64×** (171 of 172
539
- measurements faster). Per-metric table in BENCHMARKS.md.
643
+ **Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`, re-run on 1.2.0): all 225 registered
644
+ metrics and statistics functions at 10,000 and 100,000 samples. 82 are compared with a reference library, 118
645
+ with an independent textbook formula and 25 (learned, judge-dependent, randomised, or whose reference library was
646
+ not installed) are timed alone; **all 200 comparisons agree**, and against the libraries the geometric-mean
647
+ speed-up is **5.50×** (164 of 164 measurements faster). Per-metric table in BENCHMARKS.md.
540
648
 
541
649
  **Nearly every workload is faster than its reference.** The text metrics (BLEU, chrF, TER, ROUGE, METEOR, CIDEr,
542
650
  CodeBLEU's n-gram terms, distinct-n), the whole COCO evaluation (IoU, score sort, matching, accumulation),
@@ -10,11 +10,20 @@
10
10
  EvalSuite brings classification, regression, clinical, statistical, segmentation and object-detection
11
11
  evaluation into one consistent, validated, documented framework.
12
12
 
13
- > **Status: stable (1.1.2).** [Example notebooks](notebooks/README.md) (Colab) ·
13
+ > **On an older version? Upgrade once:** `pip install -U evalsuite-python`. From 1.1.2 on, EvalSuite tells you
14
+ > when a newer release is out (`evalsuite upgrade`).
15
+
16
+ > **Status: stable (1.2.0).** [Example notebooks](notebooks/README.md) (Colab) ·
14
17
  > [in-browser tools](https://evalsuite-nine.vercel.app/tools) · [changelog](CHANGELOG.md)
15
18
 
16
19
  **What's new**
17
20
 
21
+ - **1.2** — LLM evaluation and research-grade statistics: benchmark presets (GSM8K, MMLU, ARC, TruthfulQA,
22
+ HumanEval) for the leaderboard, a judge report (win rates, position / length / self-preference bias, agreement
23
+ with humans), rubric reports, an end-to-end RAG report that blames each failure on retrieval or generation, a
24
+ single-file HTML report; sample-size and power planning, cluster-bootstrap intervals (`clusters=`), a fairness
25
+ report (gaps with intervals, intersectional groups) and survival metrics (C-index, time-dependent AUC,
26
+ integrated Brier score); a GitHub Action that comments results on pull requests.
18
27
  - **1.1.2** — a once-a-day notice when a newer release exists, and a one-command upgrade (`evalsuite upgrade`
19
28
  or `es.upgrade()`); every README refreshed with current benchmark numbers.
20
29
  - **1.1.1** — hardening: every engine metric fuzzed (no crashes on malformed input), NaN / Infinity preserved in
@@ -349,6 +358,101 @@ ei.log_mlflow(result)
349
358
  ei.log_wandb(result)
350
359
  ```
351
360
 
361
+ ## Planning a test set
362
+
363
+ ```python
364
+ es.sample_size_two_proportions(0.80, 0.83, discordance=0.10) # items to detect +3 points between two models
365
+ es.sample_size_proportion(0.9, 0.02) # items for accuracy ± 2 points
366
+ es.sample_size_auc(0.85, prevalence=0.2, half_width=0.03) # positives and negatives for an AUC interval
367
+ es.power_two_proportions(500, 0.80, 0.83, discordance=0.10) # power with the items you have
368
+ ```
369
+
370
+ ## Clustered data
371
+
372
+ Several scans per patient, several questions per document or several sites make ordinary intervals too narrow.
373
+ Pass the cluster of each row and every interval and baseline test resamples whole clusters:
374
+
375
+ ```python
376
+ patient = np.repeat(np.arange(40), 5) # 200 rows, 5 per patient
377
+ result = es.evaluate(y_true, y_pred, clusters=patient)
378
+ es.bootstrap_ci("roc_auc", y_true, y_prob=y_prob, clusters=patient)
379
+ ```
380
+
381
+ ## Fairness
382
+
383
+ ```python
384
+ group = np.where(np.arange(200) % 3 == 0, "A", "B")
385
+ report = es.fairness_report(y_true, y_pred, y_prob, groups={"group": group})
386
+ print(report.summary()) # per-group rates with CIs, parity / equalized-odds gaps with CIs, Holm-adjusted tests
387
+ ```
388
+
389
+ Several attributes give intersectional groups (`groups={"sex": sex, "age": age}`); gap definitions match
390
+ Fairlearn's.
391
+
392
+ ## Survival analysis
393
+
394
+ ```python
395
+ time = np.arange(1, 201) * 0.5
396
+ event = np.arange(200) % 4 != 0
397
+ risk = -time + np.sin(np.arange(200))
398
+ es.concordance_index(time, event, risk) # Harrell's C (ipcw=True: Uno's C)
399
+ es.time_dependent_auc(time, event, risk, [20, 40, 60]) # cumulative/dynamic AUC
400
+ ```
401
+
402
+ `brier_score_survival` and `integrated_brier_score` take predicted survival probabilities. All agree with
403
+ scikit-survival to 1e-15 (Harrell's C is about 17× faster).
404
+
405
+ ## LLM judges, rubrics and RAG
406
+
407
+ ```python
408
+ judgements = [
409
+ {"model_a": "m1", "model_b": "m2", "verdict": "A", "verdict_swapped": "A", "length_a": 120, "length_b": 80},
410
+ {"model_a": "m2", "model_b": "m1", "verdict": "B", "verdict_swapped": "tie", "length_a": 60, "length_b": 150},
411
+ {"model_a": "m1", "model_b": "m2", "verdict": "tie", "verdict_swapped": "tie", "length_a": 90, "length_b": 95},
412
+ ]
413
+ print(es.judge_report(judgements, n_resamples=200).summary())
414
+ # win rates, Bradley–Terry, position consistency, length bias, self-preference, agreement with humans
415
+
416
+ rag = es.rag_report(
417
+ [
418
+ {"retrieved": ["d1", "d7"], "relevant": ["d1"], "answer": "Paris", "reference": "Paris"},
419
+ {"retrieved": ["d3"], "relevant": ["d2"], "answer": "Rome", "reference": "Oslo"},
420
+ ]
421
+ )
422
+ print(rag.summary()) # retrieval / grounding / answer metrics, and each failure blamed on a stage
423
+ ```
424
+
425
+ Leaderboards know common benchmarks: `es.leaderboard(runs, benchmark="gsm8k", references=es.load_benchmark("gsm8k"))`
426
+ (also `mmlu`, `arc`, `truthfulqa`, `humaneval`; datasets via `pip install "evalsuite-python[benchmarks]"`).
427
+
428
+ ## One HTML report
429
+
430
+ ```python
431
+ page = es.html_report(
432
+ {"Test set": es.evaluate(y_true, y_pred, y_prob=y_prob), "Notes": "Model v3."},
433
+ title="Model evaluation",
434
+ path="report.html",
435
+ )
436
+ ```
437
+
438
+ Any EvalSuite result, Matplotlib figure or Markdown text becomes a section of one self-contained file (no
439
+ scripts, no external requests).
440
+
441
+ ## Evaluation in pull requests
442
+
443
+ ```yaml
444
+ - uses: mkcs28/evalsuite-python@v1.2.0
445
+ with:
446
+ predictions: predictions.csv
447
+ y-true: label
448
+ y-pred: pred
449
+ baseline-pred: base_pred # e.g. the main branch's predictions
450
+ fail-on-regression: "true"
451
+ ```
452
+
453
+ The action comments metrics with intervals and paired tests on the pull request and fails it on a significant
454
+ regression ([full example](examples/evalsuite-action.yml)).
455
+
352
456
  ## Classification report
353
457
 
354
458
  ```python
@@ -445,11 +549,11 @@ metric calls. At 1,000,000 samples (pixels for segmentation; 1,000 images for de
445
549
  | text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 219.5 | 889.0 | **4.05×** |
446
550
  | text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 266.7 | 2399.8 | **9.00×** |
447
551
 
448
- **Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`, last full run with 0.7.1): all 225
449
- registered metrics and statistics functions at 10,000 and 100,000 samples. 86 are compared with a reference library, 118 with an
450
- independent textbook formula and 21 (learned, judge-dependent or randomised) are timed alone; **all 204
451
- comparisons agree**, and against the libraries the geometric-mean speed-up is **6.64×** (171 of 172
452
- measurements faster). Per-metric table in BENCHMARKS.md.
552
+ **Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`, re-run on 1.2.0): all 225 registered
553
+ metrics and statistics functions at 10,000 and 100,000 samples. 82 are compared with a reference library, 118
554
+ with an independent textbook formula and 25 (learned, judge-dependent, randomised, or whose reference library was
555
+ not installed) are timed alone; **all 200 comparisons agree**, and against the libraries the geometric-mean
556
+ speed-up is **5.50×** (164 of 164 measurements faster). Per-metric table in BENCHMARKS.md.
453
557
 
454
558
  **Nearly every workload is faster than its reference.** The text metrics (BLEU, chrF, TER, ROUGE, METEOR, CIDEr,
455
559
  CodeBLEU's n-gram terms, distinct-n), the whole COCO evaluation (IoU, score sort, matching, accumulation),
@@ -47,6 +47,7 @@ keras = ["keras>=3"]
47
47
  lightning = ["lightning>=2"]
48
48
  mlflow = ["mlflow>=2"]
49
49
  docx = ["python-docx>=1.0"]
50
+ benchmarks = ["datasets>=2.14"]
50
51
  wandb = ["wandb>=0.16"]
51
52
  all = ["matplotlib>=3.5", "pillow>=9", "nltk>=3.8"]
52
53
  dev = [
@@ -55,6 +56,8 @@ dev = [
55
56
  "hypothesis>=6.80",
56
57
  "scikit-learn>=1.4",
57
58
  "statsmodels>=0.13",
59
+ "scikit-survival>=0.22; python_version >= '3.10'",
60
+ "fairlearn>=0.10",
58
61
  "matplotlib>=3.5",
59
62
  "pillow>=9",
60
63
  "pycocotools>=2.0.7",
@@ -319,7 +319,7 @@ checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
319
319
 
320
320
  [[package]]
321
321
  name = "evalsuite"
322
- version = "1.1.2"
322
+ version = "1.2.0"
323
323
  dependencies = [
324
324
  "criterion",
325
325
  "evalsuite-core",
@@ -334,14 +334,14 @@ dependencies = [
334
334
 
335
335
  [[package]]
336
336
  name = "evalsuite-capi"
337
- version = "1.1.2"
337
+ version = "1.2.0"
338
338
  dependencies = [
339
339
  "evalsuite",
340
340
  ]
341
341
 
342
342
  [[package]]
343
343
  name = "evalsuite-cli"
344
- version = "1.1.2"
344
+ version = "1.2.0"
345
345
  dependencies = [
346
346
  "clap",
347
347
  "csv",
@@ -351,14 +351,14 @@ dependencies = [
351
351
 
352
352
  [[package]]
353
353
  name = "evalsuite-core"
354
- version = "1.1.2"
354
+ version = "1.2.0"
355
355
  dependencies = [
356
356
  "rayon",
357
357
  ]
358
358
 
359
359
  [[package]]
360
360
  name = "evalsuite-py"
361
- version = "1.1.2"
361
+ version = "1.2.0"
362
362
  dependencies = [
363
363
  "evalsuite-core",
364
364
  "pyo3",
@@ -367,7 +367,7 @@ dependencies = [
367
367
 
368
368
  [[package]]
369
369
  name = "evalsuite-wasm"
370
- version = "1.1.2"
370
+ version = "1.2.0"
371
371
  dependencies = [
372
372
  "evalsuite",
373
373
  "js-sys",
@@ -3,7 +3,7 @@ members = ["evalsuite-core", "evalsuite-py"]
3
3
  resolver = "2"
4
4
 
5
5
  [workspace.package]
6
- version = "1.1.2"
6
+ version = "1.2.0"
7
7
  edition = "2021"
8
8
  rust-version = "1.82"
9
9
  license = "MIT OR Apache-2.0"
@@ -278,6 +278,57 @@ __all__ = [
278
278
  __all__ += list(_text_all)
279
279
  __all__ += list(_llmsys_all)
280
280
 
281
+ from .fairness import FairnessReport, fairness_report # noqa: E402
282
+ from .html_report import html_report # noqa: E402
283
+ from .judging import JudgeReport, RubricReport, judge_report, rubric_report # noqa: E402
284
+ from .llm_benchmarks import BENCHMARKS, format_multiple_choice, load_benchmark # noqa: E402
285
+ from .rag_report import RAGReport, rag_report # noqa: E402
286
+ from .stats.planning import ( # noqa: E402
287
+ SampleSize,
288
+ power_auc,
289
+ power_mean_difference,
290
+ power_two_proportions,
291
+ sample_size_auc,
292
+ sample_size_mean_difference,
293
+ sample_size_proportion,
294
+ sample_size_two_proportions,
295
+ )
296
+ from .survival import ( # noqa: E402
297
+ brier_score_survival,
298
+ concordance_index,
299
+ integrated_brier_score,
300
+ kaplan_meier,
301
+ time_dependent_auc,
302
+ )
303
+
304
+ __all__ += [
305
+ "BENCHMARKS",
306
+ "FairnessReport",
307
+ "JudgeReport",
308
+ "RAGReport",
309
+ "RubricReport",
310
+ "SampleSize",
311
+ "brier_score_survival",
312
+ "concordance_index",
313
+ "fairness_report",
314
+ "format_multiple_choice",
315
+ "html_report",
316
+ "integrated_brier_score",
317
+ "judge_report",
318
+ "kaplan_meier",
319
+ "load_benchmark",
320
+ "power_auc",
321
+ "power_mean_difference",
322
+ "power_two_proportions",
323
+ "rag_report",
324
+ "rubric_report",
325
+ "sample_size_auc",
326
+ "sample_size_mean_difference",
327
+ "sample_size_proportion",
328
+ "sample_size_two_proportions",
329
+ "time_dependent_auc",
330
+ ]
331
+
281
332
  import contextlib as _contextlib # noqa: E402
282
333
 
283
334
  from ._update import UpdateInfo, check_for_update, upgrade # noqa: E402
@@ -171,6 +171,7 @@ def attach(
171
171
  n_resamples: int,
172
172
  random_state: Optional[int],
173
173
  sample_weight: Any,
174
+ clusters: Any = None,
174
175
  ) -> EvaluationResult:
175
176
  """Return ``result`` with intervals in each metric's params (``ci_low``, ``ci_high``, ``ci_level``,
176
177
  ``ci_method``) and, with a baseline, the paired comparison (``baseline_*`` params and ``comparison``)."""
@@ -187,6 +188,22 @@ def attach(
187
188
  return result
188
189
  names = [k for k, m in result.metrics.items() if not isinstance(m.value, np.ndarray)]
189
190
  intervals: dict[str, tuple[float, float, str]] = {}
191
+ if clusters is not None:
192
+ return _attach_clustered(
193
+ result,
194
+ y_true,
195
+ y_pred,
196
+ y_prob,
197
+ names,
198
+ mode,
199
+ level,
200
+ baseline_pred,
201
+ baseline_prob,
202
+ n_resamples,
203
+ random_state,
204
+ sample_weight,
205
+ clusters,
206
+ )
190
207
  if mode == "analytic" and sample_weight is None:
191
208
  intervals = _analytic(result, y_true, y_pred, y_prob, level)
192
209
  comparison = None
@@ -267,3 +284,126 @@ def attach(
267
284
  },
268
285
  comparison=comparison,
269
286
  )
287
+
288
+
289
+ def _attach_clustered(
290
+ result: EvaluationResult,
291
+ y_true: Any,
292
+ y_pred: Any,
293
+ y_prob: Any,
294
+ names: list[str],
295
+ mode: str,
296
+ level: float,
297
+ baseline_pred: Any,
298
+ baseline_prob: Any,
299
+ n_resamples: int,
300
+ random_state: Optional[int],
301
+ sample_weight: Any,
302
+ clusters: Any,
303
+ ) -> EvaluationResult:
304
+ """Intervals and baseline tests that resample whole clusters (``evaluate(..., clusters=...)``): analytic
305
+ intervals assume independent observations, so with clusters every interval is a cluster bootstrap."""
306
+ import warnings
307
+
308
+ from . import adjust_pvalues
309
+ from .core.exceptions import EvalSuiteError
310
+ from .stats._resolve import resolve_metric
311
+ from .stats.compare import _needs_prob
312
+ from .stats.intervals import _cluster_members
313
+
314
+ yt = np.asarray(y_true)
315
+ members = _cluster_members(clusters, yt.shape[0])
316
+ g = len(members)
317
+ if g < 2:
318
+ raise InputValidationError("Clustered intervals need at least two clusters.")
319
+ kwargs = _metric_kwargs(names, result)
320
+ rng = np.random.default_rng(random_state)
321
+ picks = [np.concatenate([members[k] for k in rng.integers(0, g, g)]) for _ in range(n_resamples)]
322
+ w = None if sample_weight is None else np.asarray(sample_weight, dtype=float)
323
+
324
+ def value(name: str, second: Any, idx: Optional[np.ndarray]) -> float:
325
+ fn, _ = resolve_metric(name)
326
+ s = np.asarray(second)
327
+ kw = dict(kwargs[name])
328
+ if w is not None:
329
+ kw["sample_weight"] = w if idx is None else w[idx]
330
+ if idx is None:
331
+ return float(fn(yt, s, **kw)) if not _needs_prob(name) else float(fn(yt, y_prob=s, **kw))
332
+ return (
333
+ float(fn(yt[idx], s[idx], **kw)) if not _needs_prob(name) else float(fn(yt[idx], y_prob=s[idx], **kw))
334
+ )
335
+
336
+ def dist(name: str, second: Any) -> np.ndarray:
337
+ out = np.empty(n_resamples)
338
+ with warnings.catch_warnings():
339
+ warnings.simplefilter("ignore")
340
+ for b, idx in enumerate(picks):
341
+ try:
342
+ out[b] = value(name, second, idx)
343
+ except EvalSuiteError:
344
+ out[b] = np.nan
345
+ return out
346
+
347
+ a = (1 - level) / 2
348
+ extra: dict[str, dict[str, Any]] = {k: {} for k in names}
349
+ raw_p: dict[str, float] = {}
350
+ for name in names:
351
+ second = y_prob if _needs_prob(name) else y_pred
352
+ if second is None:
353
+ continue
354
+ d_model = dist(name, second)
355
+ if mode != "none" and d_model is not None:
356
+ v = d_model[~np.isnan(d_model)]
357
+ if v.size:
358
+ lo, hi = np.quantile(v, [a, 1 - a])
359
+ extra[name].update(
360
+ ci_low=float(lo),
361
+ ci_high=float(hi),
362
+ ci_level=level,
363
+ ci_method=f"cluster bootstrap ({g} clusters)",
364
+ )
365
+ base = baseline_prob if _needs_prob(name) else baseline_pred
366
+ if base is not None and d_model is not None:
367
+ d_base = dist(name, base)
368
+ diff = d_model - d_base
369
+ diff = diff[~np.isnan(diff)]
370
+ est = result.metrics[name].value
371
+ base_val = value(name, base, None)
372
+ if diff.size:
373
+ lo, hi = np.quantile(diff, [a, 1 - a])
374
+ # two-sided bootstrap p-value with the +1 correction, so it is never reported as exactly 0
375
+ tail = min(int(np.sum(diff <= 0)), int(np.sum(diff >= 0)))
376
+ p = float(min(1.0, 2 * (tail + 1) / (diff.size + 1)))
377
+ raw_p[name] = p
378
+ extra[name].update(
379
+ baseline_value=base_val,
380
+ baseline_difference=float(est) - base_val,
381
+ baseline_ci_low=float(lo),
382
+ baseline_ci_high=float(hi),
383
+ baseline_test="paired cluster bootstrap",
384
+ baseline_p_value=p,
385
+ )
386
+ if raw_p:
387
+ adj = adjust_pvalues(list(raw_p.values()), method="holm")
388
+ for name, p in zip(raw_p, np.atleast_1d(adj)):
389
+ extra[name]["baseline_p_adjusted"] = float(p)
390
+ metrics: dict[str, MetricResult] = {}
391
+ for key, m in result.metrics.items():
392
+ e = extra.get(key) or {}
393
+ metrics[key] = MetricResult(m.metric, m.name, m.value, {**m.params, **e}, m.labels) if e else m
394
+ return EvaluationResult(
395
+ task=result.task,
396
+ metrics=metrics,
397
+ n_samples=result.n_samples,
398
+ target_type=result.target_type,
399
+ labels=result.labels,
400
+ confusion_matrix=result.confusion_matrix,
401
+ metadata={
402
+ **result.metadata,
403
+ "ci": "cluster bootstrap",
404
+ "ci_level": level,
405
+ "clusters": g,
406
+ "n_resamples": n_resamples,
407
+ "random_state": random_state,
408
+ },
409
+ )