Add custom metric functions and ratio metric linearization#57
Merged
Conversation
- 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>
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.py—metric_funcsв__init__иrun(), standalonetest()ambrosia/tester/handlers.py—TheoreticalTesterHandlerподдерживает callable извлечение значенийambrosia/preprocessing/transformers.py— новыйLinearizationTransformerambrosia/preprocessing/preprocessor.py— методlinearize()+ импорт трансформераambrosia/preprocessing/__init__.py— экспортLinearizationTransformerTest plan