Add custom metric functions and ratio metric linearization#56
Open
artemkuzmenko2501-del wants to merge 19 commits intodevfrom
Open
Add custom metric functions and ratio metric linearization#56artemkuzmenko2501-del wants to merge 19 commits intodevfrom
artemkuzmenko2501-del wants to merge 19 commits intodevfrom
Conversation
**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>
Create context7.json
- 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>
7dbac31 to
de0e433
Compare
- 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— экспортLinearizationTransformerCLAUDE.md— документация архитектуры для будущих сессийTest plan
metric_funcs(конструктор, run, override) +linearize(формула, chain, сериализация, имя по умолчанию)