Skip to content

Add custom metric functions and ratio metric linearization#56

Open
artemkuzmenko2501-del wants to merge 19 commits intodevfrom
feature/ab-test-abstraction
Open

Add custom metric functions and ratio metric linearization#56
artemkuzmenko2501-del wants to merge 19 commits intodevfrom
feature/ab-test-abstraction

Conversation

@artemkuzmenko2501-del
Copy link
Collaborator

@artemkuzmenko2501-del artemkuzmenko2501-del commented Mar 13, 2026

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
  • CLAUDE.md — документация архитектуры для будущих сессий

Test plan

  • 8 новых тестов: metric_funcs (конструктор, run, override) + linearize (формула, chain, сериализация, имя по умолчанию)
  • 1074 существующих теста прошли без изменений

Аслан Байрамкулов and others added 16 commits January 14, 2026 18:22
**Breaking Changes:**
- Minimum Python version raised to 3.9 (dropped 3.7, 3.8)
- Minimum PySpark version raised to 3.4 (dropped 3.2, 3.3)

**New Features:**
- Added support for Python 3.11, 3.12, 3.13
- Added hnswlib as fallback for nmslib on macOS ARM (fixes segfault)

**Dependencies:**
- Updated numpy to >=1.24.0, <3.0.0
- Updated pandas to >=1.5.0, <3.0.0
- Updated scipy to >=1.10.0
- Updated scikit-learn to >=1.3.0
- Updated nmslib to >=2.1.0
- Added hnswlib >=0.7.0 as alternative KNN backend
- Added setuptools as dependency (for hyperopt)
- Updated catboost to >=1.2.0

**Internal:**
- Replaced deprecated pkg_resources with importlib.metadata
- Replaced pytest-lazy-fixture with pytest-lazy-fixtures
- Updated CI/CD (GitHub Actions v4/v5, Python matrix 3.9-3.13)
- Updated ReadTheDocs config to Python 3.11
Migrate to Python 3.9-3.13 support
The sphinx_gallery.load_style extension uses collections.Iterable which
was removed in Python 3.10 (moved to collections.abc). This fixes the
ReadTheDocs build failure.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
sphinx_gallery has Python 3.10+ incompatibility (collections.Iterable).
Since we don't use any sphinx_gallery extensions, removing it entirely.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
nblinkgallery directive requires sphinx_gallery which has
collections.Iterable incompatibility with Python 3.10+.
Replaced with standard toctree directive.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
numpydoc 1.10.0 has a bug with docstring_parser where it fails to
import 'typing' submodule due to Python stdlib shadowing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
numpydoc 1.8.x uses sphinx.util.compat which was removed in Sphinx 9.0.
Pinning Sphinx to >=7.0,<9.0 for compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 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>
@artemkuzmenko2501-del artemkuzmenko2501-del force-pushed the feature/ab-test-abstraction branch from 7dbac31 to de0e433 Compare March 24, 2026 21:30
Аслан Байрамкулов 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>
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