tea_tasting.metrics.base
#
Base classes for metrics.
AggrCols
#
Bases: NamedTuple
Columns to be aggregated for a metric analysis.
Attributes:
Name | Type | Description |
---|---|---|
has_count |
bool
|
If |
mean_cols |
Sequence[str]
|
Column names for calculation of sample means. |
var_cols |
Sequence[str]
|
Column names for calculation of sample variances. |
cov_cols |
Sequence[tuple[str, str]]
|
Pairs of column names for calculation of sample covariances. |
MetricBase
#
Bases: ABC
, Generic[R]
, ReprMixin
Base class for metrics.
analyze(data, control, treatment, variant)
abstractmethod
#
Analyze a metric in an experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
IntoFrame | Table
|
Experimental data. |
required |
control |
Any
|
Control variant. |
required |
treatment |
Any
|
Treatment variant. |
required |
variant |
str
|
Variant column name. |
required |
Returns:
Type | Description |
---|---|
R
|
Analysis result. |
Source code in src/tea_tasting/metrics/base.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
MetricBaseAggregated
#
Bases: MetricBase[R]
, _HasAggrCols
Base class for metrics, which are analyzed using aggregated statistics.
aggr_cols: AggrCols
abstractmethod
property
#
Columns to be aggregated for an analysis.
analyze(data, control, treatment, variant=None)
#
Analyze a metric in an experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
IntoFrame | Table | dict[Any, Aggregates]
|
Experimental data. |
required |
control |
Any
|
Control variant. |
required |
treatment |
Any
|
Treatment variant. |
required |
variant |
str | None
|
Variant column name. |
None
|
Returns:
Type | Description |
---|---|
R
|
Analysis result. |
Source code in src/tea_tasting/metrics/base.py
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 |
|
analyze_aggregates(control, treatment)
abstractmethod
#
Analyze metric in an experiment using aggregated statistics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control |
Aggregates
|
Control data. |
required |
treatment |
Aggregates
|
Treatment data. |
required |
Returns:
Type | Description |
---|---|
R
|
Analysis result. |
Source code in src/tea_tasting/metrics/base.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
MetricBaseGranular
#
Bases: MetricBase[R]
, _HasCols
Base class for metrics, which are analyzed using granular data.
cols: Sequence[str]
abstractmethod
property
#
Columns to be fetched for an analysis.
analyze(data, control, treatment, variant=None)
#
Analyze a metric in an experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
IntoFrame | Table | dict[Any, Table]
|
Experimental data. |
required |
control |
Any
|
Control variant. |
required |
treatment |
Any
|
Treatment variant. |
required |
variant |
str | None
|
Variant column name. |
None
|
Returns:
Type | Description |
---|---|
R
|
Analysis result. |
Source code in src/tea_tasting/metrics/base.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
analyze_granular(control, treatment)
abstractmethod
#
Analyze metric in an experiment using granular data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control |
Table
|
Control data. |
required |
treatment |
Table
|
Treatment data. |
required |
Returns:
Type | Description |
---|---|
R
|
Analysis result. |
Source code in src/tea_tasting/metrics/base.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
MetricPowerResults
#
Bases: UserList[P]
, DictsReprMixin
Power analysis results.
to_arrow()
#
Convert the object to a PyArrow Table.
Source code in src/tea_tasting/utils.py
247 248 249 |
|
to_dicts()
#
"Convert the results to a sequence of dictionaries.
Source code in src/tea_tasting/metrics/base.py
38 39 40 |
|
to_html(keys=None, formatter=get_and_format_num, *, indent=None)
#
Convert the object to HTML.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter |
Callable[[dict[str, Any], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
indent |
str | None
|
Whitespace to insert for each indentation level. If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as HTML. |
Source code in src/tea_tasting/utils.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
to_pandas()
#
Convert the object to a Pandas DataFrame.
Source code in src/tea_tasting/utils.py
251 252 253 254 |
|
to_polars()
#
Convert the object to a Polars DataFrame.
Source code in src/tea_tasting/utils.py
256 257 258 259 |
|
to_pretty_dicts(keys=None, formatter=get_and_format_num)
#
Convert the object to a list of dictionaries with formatted values.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter |
Callable[[dict[str, Any], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
Returns:
Type | Description |
---|---|
list[dict[str, str]]
|
List of dictionaries with formatted values. |
Source code in src/tea_tasting/utils.py
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 |
|
to_string(keys=None, formatter=get_and_format_num)
#
Convert the object to a string.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter |
Callable[[dict[str, Any], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as string. |
Source code in src/tea_tasting/utils.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
PowerBase
#
Bases: ABC
, Generic[S]
, ReprMixin
Base class for the analysis of power.
solve_power(data, parameter='rel_effect_size')
abstractmethod
#
Solve for a parameter of the power of a test.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
IntoFrame | Table
|
Sample data. |
required |
parameter |
Literal['power', 'effect_size', 'rel_effect_size', 'n_obs']
|
Parameter name. |
'rel_effect_size'
|
Returns:
Type | Description |
---|---|
S
|
Power analysis result. |
Source code in src/tea_tasting/metrics/base.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
PowerBaseAggregated
#
Bases: PowerBase[S]
, _HasAggrCols
Base class for the analysis of power using aggregated statistics.
aggr_cols: AggrCols
abstractmethod
property
#
Columns to be aggregated for an analysis.
solve_power(data, parameter='rel_effect_size')
#
Solve for a parameter of the power of a test.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
IntoFrame | Table | Aggregates
|
Sample data. |
required |
parameter |
Literal['power', 'effect_size', 'rel_effect_size', 'n_obs']
|
Parameter name. |
'rel_effect_size'
|
Returns:
Type | Description |
---|---|
S
|
Power analysis result. |
Source code in src/tea_tasting/metrics/base.py
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 |
|
solve_power_from_aggregates(data, parameter='rel_effect_size')
abstractmethod
#
Solve for a parameter of the power of a test.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Aggregates
|
Sample data. |
required |
parameter |
Literal['power', 'effect_size', 'rel_effect_size', 'n_obs']
|
Parameter name. |
'rel_effect_size'
|
Returns:
Type | Description |
---|---|
S
|
Power analysis result. |
Source code in src/tea_tasting/metrics/base.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
aggregate_by_variants(data, aggr_cols, variant=None)
#
Aggregate experimental data by variants.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
IntoFrame | Table | dict[Any, Aggregates]
|
Experimental data. |
required |
aggr_cols |
AggrCols
|
Columns to be aggregated. |
required |
variant |
str | None
|
Variant column name. |
None
|
Returns:
Type | Description |
---|---|
dict[Any, Aggregates]
|
Experimental data as a dictionary of Aggregates. |
Source code in src/tea_tasting/metrics/base.py
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 |
|
read_granular(data, cols, variant=None)
#
Read granular experimental data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
IntoFrame | Table | dict[Any, Table]
|
Experimental data. |
required |
cols |
Sequence[str]
|
Columns to read. |
required |
variant |
str | None
|
Variant column name. |
None
|
Returns:
Type | Description |
---|---|
dict[Any, Table]
|
Experimental data as a dictionary of PyArrow Tables. |
Source code in src/tea_tasting/metrics/base.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|