Skip to content

Add custom metric functions and ratio metric linearization#57

Merged
aslanbm merged 4 commits intomainfrom
feature/ab-test-abstraction
Mar 26, 2026
Merged

Add custom metric functions and ratio metric linearization#57
aslanbm merged 4 commits intomainfrom
feature/ab-test-abstraction

Conversation

@artemkuzmenko2501-del
Copy link
Copy Markdown
Collaborator

Summary

  • Custom metric functions in Tester: новый параметр metric_funcs: Dict[str, Callable] позволяет передавать произвольные функции вместо имён колонок. Работает для методов theory и empiric. Функции, переданные в run(), переопределяют те, что заданы в конструкторе.
  • LinearizationTransformer: трансформер для ratio-метрик (например, revenue/orders). Линеаризует метрику по формуле linearized_i = numerator_i - ratio * denominator_i, где ratio считается на референсных данных при fit().
  • Preprocessor.linearize(): интегрирует линеаризацию в существующую chain-архитектуру с поддержкой сериализации и replay.

Changes

  • ambrosia/tester/tester.pymetric_funcs в __init__ и run(), standalone test()
  • ambrosia/tester/handlers.pyTheoreticalTesterHandler поддерживает callable извлечение значений
  • ambrosia/preprocessing/transformers.py — новый LinearizationTransformer
  • ambrosia/preprocessing/preprocessor.py — метод linearize() + импорт трансформера
  • ambrosia/preprocessing/__init__.py — экспорт LinearizationTransformer

Test plan

  • 5 новых тестов linearize: basic, formula, chain, serialization, default name
  • 4 новых теста metric_funcs: constructor, run (theory + empiric), override
  • Rebased on current main — CI infrastructure issues resolved

- Tester now accepts metric_funcs dict mapping metric names to callables,
  enabling ratio and composite metrics without pre-computing columns
- LinearizationTransformer added for ratio metrics (e.g. revenue/orders):
  linearized_i = numerator_i - ratio * denominator_i, where ratio is
  estimated on reference data passed to fit()
- Preprocessor.linearize() integrates linearization into the existing
  chain pattern with full serialization/replay support
- 8 new tests covering metric_funcs constructor/run/override behaviour
  and linearize formula, chaining, serialization

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Аслан Байрамкулов and others added 3 commits March 26, 2026 21:13
- Document metric_funcs parameter in Tester class, run(), and test()
  docstrings with type hints, behavior description, and pandas-only note
- Add test_metric_func_bootstrap to verify metric_funcs works with
  empiric (bootstrap) method
- Replace PR's CLAUDE.md with the more complete project version

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
setuptools 82.0 removed pkg_resources, which hyperopt 0.2.7 imports
at module level. This breaks `pip install ambrosia` on any Python
version when setuptools>=82 is resolved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aslanbm aslanbm merged commit 4d94b2e into main Mar 26, 2026
20 checks passed
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.

2 participants