Confusion Tables¶
A replicated recovery or discrimination study generates independent cohorts
from each candidate structure and reads every cohort with a prespecified rule,
for example "favour A", "favour B", "indistinguishable" or "failed".
confusion_table tabulates the verdicts by generating structure and gives a
fixed-sample proportion interval for every cell, so the
probability of the right verdict is reported beside the wrong-structure and
no-verdict rates.
table = confusion_table(truth, verdict, rows=["A", "B"],
columns=["A", "B", "none", "failed"],
adjustment="bonferroni")
table.cell("A", "A") # probability of favouring A when A generated the cohort
table.row_total("A") # cohorts generated from A, failed trials included
Every cohort is in a declared row and column: undeclared labels raise, a
declared row without a cohort raises, and a failed trial is a column of its
own, never a dropped cohort. The intervals assume independent cohorts and a
prespecified number per row; the caller establishes both. Without
adjustment each interval is marginal; adjustment="bonferroni" uses level
1 - (1 - confidence) / len(columns) so that the statements about the columns of
one row hold simultaneously at approximately the nominal level (Wilson coverage is
approximate, and different rows are separate statements that are not adjusted).
Labels that compare equal (1, True, 1.0) are one label. power_curve reads one 0/1 indicator per
design; the confusion table reports all verdicts of a design together.
trade_study.ConfusionTable(rows, columns, counts, intervals, confidence, family_confidence, adjustment, method)
dataclass
¶
Counts and row-wise proportion intervals of verdicts by truth.
Attributes:
| Name | Type | Description |
|---|---|---|
rows |
tuple[Hashable, ...]
|
Row labels (the truth), in the order declared by the caller. |
columns |
tuple[Hashable, ...]
|
Column labels (the verdicts), in declared order. |
counts |
tuple[tuple[int, ...], ...]
|
|
intervals |
tuple[tuple[ProportionInterval, ...], ...]
|
|
confidence |
float
|
Two-sided level of each reported interval (after any adjustment). |
family_confidence |
float
|
Nominal simultaneous level across the columns of a
row (approximate for Wilson intervals); equals |
adjustment |
str | None
|
|
method |
str
|
Interval method passed to |
cell(row, column)
¶
Interval for the probability of column given row.
Returns:
| Type | Description |
|---|---|
ProportionInterval
|
The fixed-sample interval of that cell. |
Source code in src/trade_study/confusion.py
row_total(row)
¶
Number of cohorts of row, including failed trials.
Returns:
| Type | Description |
|---|---|
int
|
The row total. |
trade_study.confusion_table(truth, verdict, rows, columns, *, confidence=0.95, method='wilson', adjustment=None)
¶
Tabulate one verdict per independent cohort against its truth.
Each position of truth and verdict is one independent cohort.
Every label must be declared in rows or columns and every declared
row must have at least one cohort, so no cohort is dropped and a failed
trial is a column of its own. Each cell interval is a fixed-sample
interval for independent cohorts of a prespecified number per row; the
caller establishes the independence and the number (see
proportion_interval). With adjustment="bonferroni" the intervals of
a row use level 1 - (1 - confidence) / len(columns), so that the
statements about the columns of one row hold simultaneously at
approximately the nominal level (Wilson coverage is approximate; the
rows are separate statements and are not adjusted). Labels that compare
equal (1, True and 1.0) are the same label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
truth
|
Sequence[Hashable]
|
Generating label of each cohort. |
required |
verdict
|
Sequence[Hashable]
|
Verdict label of each cohort, aligned with |
required |
rows
|
Sequence[Hashable]
|
Declared truth labels. |
required |
columns
|
Sequence[Hashable]
|
Declared verdict labels, including a failure label if the study can fail. |
required |
confidence
|
float
|
Two-sided family level in (0, 1). |
0.95
|
method
|
str
|
|
'wilson'
|
adjustment
|
Literal['bonferroni'] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
ConfusionTable
|
The counts and the interval of every cell. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If lengths differ, labels are repeated or undeclared, a
declared row has no cohort, or |
Examples:
>>> table = confusion_table(
... ["A", "A", "A", "B"],
... ["A", "A", "none", "B"],
... rows=["A", "B"],
... columns=["A", "B", "none"],
... )
>>> table.counts
((2, 0, 1), (0, 1, 0))
>>> table.cell("A", "A").estimate
0.6666666666666666
Source code in src/trade_study/confusion.py
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 | |