ebaml 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ebaml-0.2.1 → ebaml-0.2.2}/PKG-INFO +1 -1
- {ebaml-0.2.1 → ebaml-0.2.2}/pyproject.toml +1 -1
- {ebaml-0.2.1 → ebaml-0.2.2}/pyproject.toml.orig +1 -1
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/graphs/ebm_graph.py +7 -3
- ebaml-0.2.2/src/ebaml/graphs/terms.py +58 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/llm/descriptors.py +12 -7
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/local/facts.py +10 -4
- {ebaml-0.2.1 → ebaml-0.2.2}/LICENSE +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/README.md +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/.baml-generator-output-root +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/.baml-generator-output.json +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/.gitignore +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/_baml_sources.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/_function_registry.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/_inlinedbaml.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/_invocation_types.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/_invocation_types.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/_typemap.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/clients/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/clients/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/content/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/content/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/errors/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/errors/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/events/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/events/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/mcp/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/mcp/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/stream/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/stream/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/tools/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/tools/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/wire/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/ai/wire/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/crypto/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/crypto/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/csv/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/csv/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/env/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/env/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/errors/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/errors/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/fs/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/fs/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/future/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/future/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/glob/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/glob/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/hash/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/hash/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/host/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/host/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/http/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/http/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/io/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/io/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/iter/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/iter/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/json/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/json/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/media/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/media/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/net/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/net/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/ops/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/ops/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/panics/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/panics/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/random/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/random/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/regex/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/regex/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/sap/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/sap/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/spawn/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/spawn/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/sys/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/sys/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/time/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/time/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/toml/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/toml/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/ws/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/ws/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/yaml/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/baml/yaml/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/experimental/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/experimental/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/py.typed +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/class_/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/class_/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/enum/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/enum/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/errors/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/errors/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/function/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/function/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/interface/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/reflect/interface/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/anthropic/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/anthropic/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/anthropic/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/anthropic/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/assert_/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/assert_/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/aws/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/aws/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/aws/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/aws/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/claude_code/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/claude_code/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/claude_code/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/claude_code/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/google/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/google/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/google/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/google/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/openai/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/openai/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/openai/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/openai/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/openai/internal/decisions/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/openai/internal/decisions/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/testing/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/testing/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/trace/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/trace/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/typesafeai/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/typesafeai/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/typesafeai/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/typesafeai/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/vercel/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/vercel/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/vercel/internal/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/baml_sdk/vendor/vercel/internal/__init__.pyi +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/benchmark.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/core/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/core/custom_types.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/core/exceptions.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/graphs/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/graphs/graph_text.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/graphs/model_kinds.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/llm/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/llm/options.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/llm/provider_errors.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/llm/retry.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/llm/sdk_setup.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/local/__init__.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/local/fact_text.py +0 -0
- {ebaml-0.2.1 → ebaml-0.2.2}/src/ebaml/py.typed +0 -0
|
@@ -27,6 +27,7 @@ from ebaml.core.exceptions import (
|
|
|
27
27
|
)
|
|
28
28
|
from ebaml.graphs.graph_text import parse_graph_text, xy_to_json
|
|
29
29
|
from ebaml.graphs.model_kinds import model_kind
|
|
30
|
+
from ebaml.graphs.terms import main_term
|
|
30
31
|
|
|
31
32
|
# nominal features are unordered categories
|
|
32
33
|
_FORMAT_ALIASES = {FeatureType.NOMINAL: FeatureType.CATEGORICAL}
|
|
@@ -303,7 +304,8 @@ class EBMGraph:
|
|
|
303
304
|
ebm: ExplainableBoostingModel
|
|
304
305
|
The EBM model.
|
|
305
306
|
feature_index: int
|
|
306
|
-
The index of the feature in the EBM.
|
|
307
|
+
The index of the feature in the EBM. A feature that ``exclude`` or ``remove_terms`` left out has no
|
|
308
|
+
main-effect term, and raises ``UnsupportedModelError``.
|
|
307
309
|
normalization: Normalization | str, default=Normalization.NONE
|
|
308
310
|
How to normalize the graph (shift on the y-axis).
|
|
309
311
|
use_feature_bounds: bool, default=True
|
|
@@ -342,8 +344,10 @@ class EBMGraph:
|
|
|
342
344
|
# read the variables from the ebm
|
|
343
345
|
feature_name = ebm.feature_names_in_[feature_index]
|
|
344
346
|
feature_type = ebm.feature_types_in_[feature_index]
|
|
345
|
-
scores
|
|
346
|
-
|
|
347
|
+
# the scores are kept by term, and term i is not always feature i
|
|
348
|
+
term = main_term(ebm, feature_index)
|
|
349
|
+
scores = np.array(ebm.term_scores_[term][1:-1], dtype=float) # Drop missing and unknown bins
|
|
350
|
+
stds = np.asarray(ebm.standard_deviations_[term][1:-1], dtype=float)
|
|
347
351
|
selected = _select_outputs(model_kind(ebm).outputs, feature_name, scores, stds, classes)
|
|
348
352
|
scores, stds = selected.scores, selected.stds
|
|
349
353
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""The term of an EBM that holds the main effect of each feature.
|
|
2
|
+
|
|
3
|
+
interpret keeps the scores, the standard deviations, the bin weights and the importances by term, and the names, the
|
|
4
|
+
types and the bins by feature. Term ``i`` is not always feature ``i``: a feature that ``exclude`` leaves out at fit
|
|
5
|
+
time, or that ``remove_terms`` removes later, has no term, and the terms after it move. So other code finds the term
|
|
6
|
+
of a feature here, and does not index the term attributes with the index of a feature.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from ebaml.core.custom_types import ExplainableBoostingModel
|
|
10
|
+
from ebaml.core.exceptions import UnsupportedModelError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main_term(ebm: ExplainableBoostingModel, feature_index: int) -> int:
|
|
14
|
+
"""Find the term that holds the main effect of a feature.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
ebm: ExplainableBoostingModel
|
|
19
|
+
The fitted EBM.
|
|
20
|
+
feature_index: int
|
|
21
|
+
The index of the feature in ``feature_names_in_``.
|
|
22
|
+
|
|
23
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
int
|
|
26
|
+
The index of the term in ``term_features_``, ``term_scores_`` and the other term attributes.
|
|
27
|
+
|
|
28
|
+
Raises
|
|
29
|
+
------
|
|
30
|
+
UnsupportedModelError
|
|
31
|
+
If the feature has no main-effect term, because ``exclude`` or ``remove_terms`` left it out.
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
for term_index, features in enumerate(ebm.term_features_):
|
|
35
|
+
if tuple(features) == (feature_index,):
|
|
36
|
+
return term_index
|
|
37
|
+
msg = (
|
|
38
|
+
f"The feature {ebm.feature_names_in_[feature_index]!r} has no main-effect term in the EBM,"
|
|
39
|
+
" because exclude or remove_terms left it out."
|
|
40
|
+
)
|
|
41
|
+
raise UnsupportedModelError(msg)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def main_effect_features(ebm: ExplainableBoostingModel) -> list[int]:
|
|
45
|
+
"""List the features that have a main-effect term.
|
|
46
|
+
|
|
47
|
+
Parameters
|
|
48
|
+
----------
|
|
49
|
+
ebm: ExplainableBoostingModel
|
|
50
|
+
The fitted EBM.
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
list[int]
|
|
55
|
+
The index of each such feature in ``feature_names_in_``, in increasing order.
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
return sorted(features[0] for features in ebm.term_features_ if len(features) == 1)
|
|
@@ -16,6 +16,7 @@ from baml_bridge.errors import BamlError
|
|
|
16
16
|
from ebaml.core.custom_types import Audience, ExplainableBoostingModel, FeatureValue, coerce_enum
|
|
17
17
|
from ebaml.core.exceptions import InvalidOptionError
|
|
18
18
|
from ebaml.graphs.ebm_graph import EBMGraph
|
|
19
|
+
from ebaml.graphs.terms import main_effect_features, main_term
|
|
19
20
|
from ebaml.llm.options import GraphOptions, ModelOptions, PromptOptions
|
|
20
21
|
from ebaml.llm.provider_errors import provider_errors
|
|
21
22
|
from ebaml.llm.retry import call_with_shrinking_graph
|
|
@@ -38,7 +39,7 @@ _DEFAULT_PROMPT_OPTIONS = PromptOptions()
|
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
def _feature_importances_to_text(ebm: ExplainableBoostingModel) -> str:
|
|
41
|
-
"""Convert the
|
|
42
|
+
"""Convert the importances of the main-effect terms of an EBM to text, one line per feature.
|
|
42
43
|
|
|
43
44
|
Parameters
|
|
44
45
|
----------
|
|
@@ -50,10 +51,11 @@ def _feature_importances_to_text(ebm: ExplainableBoostingModel) -> str:
|
|
|
50
51
|
str: Textual representation of the feature importances.
|
|
51
52
|
|
|
52
53
|
"""
|
|
54
|
+
# the importances are kept by term, and term i is not always feature i
|
|
53
55
|
importances = ebm.term_importances()
|
|
54
56
|
return "\n".join(
|
|
55
|
-
f"{
|
|
56
|
-
for feature_idx
|
|
57
|
+
f"{ebm.feature_names_in_[feature_idx]}: {importances[main_term(ebm, feature_idx)]:.2f}"
|
|
58
|
+
for feature_idx in main_effect_features(ebm)
|
|
57
59
|
)
|
|
58
60
|
|
|
59
61
|
|
|
@@ -374,6 +376,7 @@ def describe_ebm( # ruff: ignore[too-many-arguments] -- the model, two limits,
|
|
|
374
376
|
Each feature graph is described like in ``describe_graph`` (concurrently, at most ``max_concurrency`` at a time,
|
|
375
377
|
each retried with a simplified graph if the reply is cut off by ``max_tokens``), and then the LLM summarizes the
|
|
376
378
|
descriptions. The descriptions skip the interaction terms, and an ``interactions_skipped`` warning names them.
|
|
379
|
+
They also skip a feature that ``exclude`` or ``remove_terms`` left out, because it has no graph.
|
|
377
380
|
The logged usage leaves out the cut-off attempts, because the provider error carries no token count. It is a lower
|
|
378
381
|
bound, and the ``usage`` log event has the number of those attempts in ``truncated_attempts``.
|
|
379
382
|
|
|
@@ -401,10 +404,12 @@ def describe_ebm( # ruff: ignore[too-many-arguments] -- the model, two limits,
|
|
|
401
404
|
"""
|
|
402
405
|
# Convert all objects to text and check the model before prompting the LLM the first time, so that errors in
|
|
403
406
|
# processing one of the graphs or in the model surface before any LLM call is paid for.
|
|
404
|
-
|
|
405
|
-
|
|
407
|
+
# a feature that exclude or remove_terms left out has no graph to describe
|
|
408
|
+
features = main_effect_features(ebm)
|
|
409
|
+
feature_names = [ebm.feature_names_in_[feature_index] for feature_index in features]
|
|
410
|
+
_warn_skipped_interactions(ebm, features)
|
|
406
411
|
feature_importances = _feature_importances_to_text(ebm)
|
|
407
|
-
graph_texts = [_graph_text(ebm, feature_index, graph) for feature_index in
|
|
412
|
+
graph_texts = [_graph_text(ebm, feature_index, graph) for feature_index in features]
|
|
408
413
|
model_spec = _model_spec(model)
|
|
409
414
|
opts = _prompt_options(prompt)
|
|
410
415
|
|
|
@@ -419,7 +424,7 @@ def describe_ebm( # ruff: ignore[too-many-arguments] -- the model, two limits,
|
|
|
419
424
|
opts=opts,
|
|
420
425
|
model=model_spec,
|
|
421
426
|
),
|
|
422
|
-
|
|
427
|
+
features,
|
|
423
428
|
graph_texts,
|
|
424
429
|
),
|
|
425
430
|
)
|
|
@@ -33,6 +33,7 @@ from ebaml.core.custom_types import ClassLabel, ExplainableBoostingModel, Featur
|
|
|
33
33
|
from ebaml.core.exceptions import InvalidInstanceError, OptionRangeError, UnsupportedModelError
|
|
34
34
|
from ebaml.graphs.ebm_graph import EBMGraph
|
|
35
35
|
from ebaml.graphs.model_kinds import BinaryClassifier, model_kind
|
|
36
|
+
from ebaml.graphs.terms import main_effect_features, main_term
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
@attrs.frozen
|
|
@@ -366,22 +367,27 @@ def _features(
|
|
|
366
367
|
Raises
|
|
367
368
|
------
|
|
368
369
|
UnsupportedModelError
|
|
369
|
-
If the model has interactions.
|
|
370
|
+
If the model has interactions, or a feature has no main-effect term.
|
|
370
371
|
InvalidInstanceError
|
|
371
372
|
If the instance lacks a feature, a value is missing, or a category was not seen in training.
|
|
372
373
|
|
|
373
374
|
"""
|
|
374
|
-
|
|
375
|
-
if [len(term) for term in ebm.term_features_] != [1] * len(ebm.feature_names_in_):
|
|
375
|
+
if any(len(term) > 1 for term in ebm.term_features_):
|
|
376
376
|
msg = "Local explanations need an EBM without interactions (fit with interactions=0)."
|
|
377
377
|
raise UnsupportedModelError(msg)
|
|
378
|
+
# a feature that exclude or remove_terms left out has no score, so the prediction cannot be split by feature
|
|
379
|
+
with_term = main_effect_features(ebm)
|
|
380
|
+
if with_term != list(range(len(ebm.feature_names_in_))):
|
|
381
|
+
missing = [name for index, name in enumerate(ebm.feature_names_in_) if index not in with_term]
|
|
382
|
+
msg = f"Local explanations need a main-effect term for every feature. These features have none: {missing}."
|
|
383
|
+
raise UnsupportedModelError(msg)
|
|
378
384
|
features = []
|
|
379
385
|
for index, name in enumerate(ebm.feature_names_in_):
|
|
380
386
|
if name not in instance:
|
|
381
387
|
msg = f"The instance has no value for feature {name!r}."
|
|
382
388
|
raise InvalidInstanceError(msg)
|
|
383
389
|
graph = EBMGraph.from_ebm(ebm, index)
|
|
384
|
-
weights = np.asarray(ebm.bin_weights_[index][1:-1], dtype=float)
|
|
390
|
+
weights = np.asarray(ebm.bin_weights_[main_term(ebm, index)][1:-1], dtype=float)
|
|
385
391
|
bin_index = _bin_index(ebm, index, graph, instance[name])
|
|
386
392
|
plausible = _plausible_bins(weights, continuous=graph.feature_type == "continuous", min_support=min_support)
|
|
387
393
|
plausible[bin_index] = True
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|