Compute
Compute agreement coefficient estimates
compute(df, target, metrics, ci=False, n_boot=1000, confidence_level=0.95, level=LevelType.NOMINAL, models=None, runs=None, **filters)
¶
Compute interrater agreement coefficient estimates and optional confidence intervals.
Wraps data in a Dataset container, applies subset filters if passed, and evaluates the coefficients specified. Non-parametric BCa cluster bootstrapping can be enabled to estimate standard errors and confidence intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Long-form dataframe with at minimum, ratings and metadata |
required |
target
|
str
|
Name of the column in |
required |
metrics
|
list[str]
|
List of coefficient identifiers to compute, e.g., ["fleiss", "ac1"] |
required |
ci
|
bool
|
If |
False
|
n_boot
|
Int
|
Number of bootstrap samples when |
1000
|
confidence_level
|
float
|
Alpha for BCa bootstrap intervals when |
0.95
|
level
|
str or LevelType
|
Measurement scale level of the target column |
LevelType.NOMINAL
|
models
|
list[str]
|
Optional list of model names to filter the dataset |
None
|
runs
|
list[str]
|
Optional list of run IDs to filter the dataset |
None
|
**filters
|
Any
|
Additional keyword filters applied to metadata columns in |
{}
|
Returns:
| Type | Description |
|---|---|
AgreementResult
|
Immutable result object containing point estimates, bootstrap standard errors, confidence interval ranges, and dataset metadata |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any requested metric string is not registered in |
Examples:
>>> result = compute(
... df=ratings_df,
... target="rating",
... metrics=["cohen", "ac1"],
... ci=True,
... models=["gpt-4o", "claude-3-5-sonnet"]
... )
>>> print(result.scores)
{'cohen': 0.742, 'ac1': 0.810}
Source code in interrater/compute.py
19 20 21 22 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 | |
compute_many(dataset, fields, metrics, **compute_kwargs)
¶
Compute interrater agreement coefficient estimates and optional confidence intervals across multiple dataset fields/categories simultaneously
Slices a dataset into subsets based on the specified fields/categories and
runs compute() on each slice
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
|
required |
fields
|
list[str]
|
List of categories/fields to slice and evaluate |
required |
metrics
|
list[str]
|
List of coefficient identifiers to compute, e.g., ["fleiss", "ac1"] for each field |
required |
**compute_kwargs
|
Keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
MultiAgreementResult
|
Immutable result object containing point estimates, bootstrap standard errors, confidence interval ranges, and dataset metadata for each field |
Examples:
>>> multi_res = compute_many(
... dataset=my_dataset,
... fields=["recommendations", "hypoglycemia", "follow_up"],
... metrics=["fleiss", "ac1"],
... ci=True
... )
>>> multi_res["recommendations"].scores
{'fleiss': 0.62, 'ac1': 0.78}
Source code in interrater/compute.py
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 | |
compare_to_ground_truth(df, target, gt_source, gt_target, metrics, ci=False, n_boot=1000, confidence_level=0.95, level=LevelType.NOMINAL, **filters)
¶
Compute interrater agreement coefficient estimates between individual models and a ground truth dataset
Combines model outputs with ground truth ratings, isolates each model against the ground truth, and computes the specified metrics
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
PathOrDataFrame
|
Model outputs provided as a file path, pd.DataFrame, dictionary, or list |
required |
target
|
str
|
Name of the column in |
required |
gt_source
|
PathOrDataFrame
|
Ground truth reference provided as a file path, pd.DataFrame, dictionary, or list |
required |
gt_target
|
str
|
Name of the column in |
required |
metrics
|
list[str]
|
List of coefficient identifiers to compute, e.g., ["fleiss", "ac1"] |
required |
ci
|
bool
|
If |
False
|
n_boot
|
Int
|
Number of bootstrap samples when |
1000
|
confidence_level
|
float
|
Alpha for BCa bootstrap intervals when |
0.95
|
level
|
str | LevelType
|
Measurement scale level of the target column |
NOMINAL
|
**filters
|
Any
|
Additional key-value filters applied to combined evaluation data before comparison |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float]]
|
Nested dictionary structured as |
Examples:
>>> gt_comparison = compare_to_ground_truth(
... df="model_outputs.csv",
... target="prediction",
... gt_source="expert_labels.csv",
... gt_target="consensus_label",
... metrics=["cohen", "percent_agreement"],
... ci=True,
... n_boot=1000,
... confidence_level=0.95
... )
>>> gt_comparison["gpt-5.4-mini"]
{'cohen': 0.812, 'percent_agreement': 0.890}
Source code in interrater/compute.py
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 | |
:::