ebaml 0.3.3__tar.gz → 0.4.0__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.3.3 → ebaml-0.4.0}/PKG-INFO +12 -1
- {ebaml-0.3.3 → ebaml-0.4.0}/README.md +8 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/pyproject.toml +40 -3
- {ebaml-0.3.3 → ebaml-0.4.0}/pyproject.toml.orig +32 -6
- ebaml-0.4.0/src/ebaml/mcp/__init__.py +4 -0
- ebaml-0.4.0/src/ebaml/mcp/explain_tools.py +71 -0
- ebaml-0.4.0/src/ebaml/mcp/llm_tools.py +47 -0
- ebaml-0.4.0/src/ebaml/mcp/model_store.py +138 -0
- ebaml-0.4.0/src/ebaml/mcp/read_tools.py +155 -0
- ebaml-0.4.0/src/ebaml/mcp/server.py +230 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/LICENSE +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/.baml-generator-output-root +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/.baml-generator-output.json +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/.gitignore +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/_baml_sources.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/_function_registry.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/_inlinedbaml.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/_invocation_types.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/_invocation_types.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/_typemap.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/clients/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/clients/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/content/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/content/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/errors/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/errors/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/events/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/events/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/mcp/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/mcp/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/stream/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/stream/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/tools/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/tools/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/wire/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/ai/wire/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/crypto/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/crypto/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/csv/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/csv/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/env/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/env/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/errors/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/errors/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/fs/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/fs/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/future/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/future/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/glob/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/glob/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/hash/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/hash/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/host/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/host/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/http/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/http/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/io/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/io/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/iter/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/iter/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/json/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/json/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/media/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/media/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/net/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/net/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/ops/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/ops/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/panics/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/panics/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/random/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/random/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/regex/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/regex/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/sap/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/sap/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/spawn/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/spawn/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/sys/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/sys/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/time/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/time/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/toml/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/toml/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/ws/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/ws/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/yaml/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/baml/yaml/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/experimental/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/experimental/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/py.typed +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/class_/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/class_/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/enum/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/enum/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/errors/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/errors/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/function/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/function/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/interface/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/reflect/interface/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/anthropic/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/anthropic/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/anthropic/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/anthropic/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/assert_/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/assert_/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/aws/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/aws/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/aws/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/aws/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/claude_code/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/claude_code/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/claude_code/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/claude_code/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/google/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/google/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/google/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/google/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/openai/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/openai/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/openai/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/openai/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/openai/internal/decisions/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/openai/internal/decisions/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/testing/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/testing/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/trace/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/trace/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/typesafeai/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/typesafeai/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/typesafeai/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/typesafeai/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/vercel/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/vercel/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/vercel/internal/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/baml_sdk/vendor/vercel/internal/__init__.pyi +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/benchmark.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/core/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/core/custom_types.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/core/exceptions.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/ebm_graph.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/graph_text.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/model_kinds.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/request_text.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/terms.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/token_budget.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/graphs/token_weights.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/descriptors.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/options.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/provider_errors.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/retry.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/sdk_setup.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/token_learning.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/llm/token_weights.json +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/local/__init__.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/local/audience.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/local/fact_text.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/local/facts.py +0 -0
- {ebaml-0.3.3 → ebaml-0.4.0}/src/ebaml/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ebaml
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: BAML for Explainable Boosting Machines: talk to your EBM.
|
|
5
5
|
Keywords: baml,llm,explainable-ai,explainable-boosting-machine,interpretml
|
|
6
6
|
Author: Johnny Godoy
|
|
@@ -22,11 +22,14 @@ Requires-Dist: orjson>=3.13.0
|
|
|
22
22
|
Requires-Dist: pandas>=3.0.6
|
|
23
23
|
Requires-Dist: scipy>=1.18.1
|
|
24
24
|
Requires-Dist: structlog>=26.1.0
|
|
25
|
+
Requires-Dist: joblib>=1.5.0 ; extra == 'mcp'
|
|
26
|
+
Requires-Dist: mcp>=1.30.0 ; extra == 'mcp'
|
|
25
27
|
Requires-Python: >=3.13
|
|
26
28
|
Project-URL: Documentation, https://johnny-godoy.github.io/EBaMl/
|
|
27
29
|
Project-URL: Source, https://github.com/johnny-godoy/EBaMl
|
|
28
30
|
Project-URL: Issues, https://github.com/johnny-godoy/EBaMl/issues
|
|
29
31
|
Project-URL: Changelog, https://github.com/johnny-godoy/EBaMl/blob/main/CHANGELOG.md
|
|
32
|
+
Provides-Extra: mcp
|
|
30
33
|
Description-Content-Type: text/markdown
|
|
31
34
|
|
|
32
35
|
# EBaMl
|
|
@@ -52,11 +55,13 @@ LLM calls go through [OpenRouter](https://openrouter.ai)'s free router (`openrou
|
|
|
52
55
|
| Model summary (`describe_ebm`) | ✅ | ✅ | ✅ | ⚠️ |
|
|
53
56
|
| Graph text (`EBMGraph`) | ✅ | ✅ | ✅ | ⚠️ |
|
|
54
57
|
| Local explanations (`explain_instance`) | ✅ | ❌ | ❌ | ❌ |
|
|
58
|
+
| MCP server (`ebaml-mcp`) | ✅ | ✅ | ✅ | ⚠️ |
|
|
55
59
|
|
|
56
60
|
✅ supported. ⚠️ partly supported: the main effects are described, and the interaction terms are skipped.
|
|
57
61
|
`describe_graph` and `describe_ebm` log an `interactions_skipped` warning that names them. ❌ not supported yet. Full support is on the
|
|
58
62
|
[roadmap](https://github.com/johnny-godoy/EBaMl/blob/main/ROADMAP.md).
|
|
59
63
|
<!-- --8<-- [end:supported-models] -->
|
|
64
|
+
The MCP server reads every kind of model. Its explain tool works for binary classifiers only.
|
|
60
65
|
## Setup
|
|
61
66
|
|
|
62
67
|
<!-- --8<-- [start:setup] -->
|
|
@@ -342,6 +347,12 @@ graph.
|
|
|
342
347
|
uv run marimo edit notebooks/model_kinds.py
|
|
343
348
|
```
|
|
344
349
|
|
|
350
|
+
## MCP server
|
|
351
|
+
|
|
352
|
+
`ebaml-mcp` serves a fitted EBM to an agent, for example Claude Code. The agent reads the features and the graphs, and
|
|
353
|
+
explains one prediction with the exact local facts. These tools call no LLM, so they need no key. See the
|
|
354
|
+
[MCP server guide](https://johnny-godoy.github.io/EBaMl/mcp/).
|
|
355
|
+
|
|
345
356
|
## Benchmark
|
|
346
357
|
|
|
347
358
|
The benchmark follows [TalkToEBM's benchmark](https://github.com/interpretml/TalkToEBM/tree/main/benchmark) that checks how well a
|
|
@@ -21,11 +21,13 @@ LLM calls go through [OpenRouter](https://openrouter.ai)'s free router (`openrou
|
|
|
21
21
|
| Model summary (`describe_ebm`) | ✅ | ✅ | ✅ | ⚠️ |
|
|
22
22
|
| Graph text (`EBMGraph`) | ✅ | ✅ | ✅ | ⚠️ |
|
|
23
23
|
| Local explanations (`explain_instance`) | ✅ | ❌ | ❌ | ❌ |
|
|
24
|
+
| MCP server (`ebaml-mcp`) | ✅ | ✅ | ✅ | ⚠️ |
|
|
24
25
|
|
|
25
26
|
✅ supported. ⚠️ partly supported: the main effects are described, and the interaction terms are skipped.
|
|
26
27
|
`describe_graph` and `describe_ebm` log an `interactions_skipped` warning that names them. ❌ not supported yet. Full support is on the
|
|
27
28
|
[roadmap](https://github.com/johnny-godoy/EBaMl/blob/main/ROADMAP.md).
|
|
28
29
|
<!-- --8<-- [end:supported-models] -->
|
|
30
|
+
The MCP server reads every kind of model. Its explain tool works for binary classifiers only.
|
|
29
31
|
## Setup
|
|
30
32
|
|
|
31
33
|
<!-- --8<-- [start:setup] -->
|
|
@@ -311,6 +313,12 @@ graph.
|
|
|
311
313
|
uv run marimo edit notebooks/model_kinds.py
|
|
312
314
|
```
|
|
313
315
|
|
|
316
|
+
## MCP server
|
|
317
|
+
|
|
318
|
+
`ebaml-mcp` serves a fitted EBM to an agent, for example Claude Code. The agent reads the features and the graphs, and
|
|
319
|
+
explains one prediction with the exact local facts. These tools call no LLM, so they need no key. See the
|
|
320
|
+
[MCP server guide](https://johnny-godoy.github.io/EBaMl/mcp/).
|
|
321
|
+
|
|
314
322
|
## Benchmark
|
|
315
323
|
|
|
316
324
|
The benchmark follows [TalkToEBM's benchmark](https://github.com/interpretml/TalkToEBM/tree/main/benchmark) that checks how well a
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ebaml"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "BAML for Explainable Boosting Machines: talk to your EBM."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -37,6 +37,15 @@ dependencies = [
|
|
|
37
37
|
name = "Johnny Godoy"
|
|
38
38
|
email = "johnny.godoy@ing.uchile.cl"
|
|
39
39
|
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
mcp = [
|
|
42
|
+
"joblib>=1.5.0",
|
|
43
|
+
"mcp>=1.30.0",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.scripts]
|
|
47
|
+
ebaml-mcp = "ebaml.mcp.server:main"
|
|
48
|
+
|
|
40
49
|
[project.urls]
|
|
41
50
|
Documentation = "https://johnny-godoy.github.io/EBaMl/"
|
|
42
51
|
Source = "https://github.com/johnny-godoy/EBaMl"
|
|
@@ -128,7 +137,11 @@ select = ["ALL"]
|
|
|
128
137
|
]
|
|
129
138
|
|
|
130
139
|
[tool.vulture]
|
|
131
|
-
ignore_decorators = [
|
|
140
|
+
ignore_decorators = [
|
|
141
|
+
"@pytest.fixture",
|
|
142
|
+
"@server.tool",
|
|
143
|
+
"@server.resource",
|
|
144
|
+
]
|
|
132
145
|
ignore_names = [
|
|
133
146
|
"pytestmark",
|
|
134
147
|
"pytest_*",
|
|
@@ -152,9 +165,10 @@ root_package = "ebaml"
|
|
|
152
165
|
include_external_packages = true
|
|
153
166
|
|
|
154
167
|
[[tool.importlinter.contracts]]
|
|
155
|
-
name = "Layers: llm over local over graphs over core"
|
|
168
|
+
name = "Layers: mcp over llm over local over graphs over core"
|
|
156
169
|
type = "layers"
|
|
157
170
|
layers = [
|
|
171
|
+
"ebaml.mcp",
|
|
158
172
|
"ebaml.llm",
|
|
159
173
|
"ebaml.local",
|
|
160
174
|
"ebaml.graphs",
|
|
@@ -175,6 +189,28 @@ forbidden_modules = [
|
|
|
175
189
|
"baml_bridge",
|
|
176
190
|
]
|
|
177
191
|
|
|
192
|
+
[[tool.importlinter.contracts]]
|
|
193
|
+
name = "The MCP layer reaches the BAML SDK only through ebaml.llm"
|
|
194
|
+
type = "forbidden"
|
|
195
|
+
source_modules = ["ebaml.mcp"]
|
|
196
|
+
forbidden_modules = [
|
|
197
|
+
"baml_sdk",
|
|
198
|
+
"baml_bridge",
|
|
199
|
+
]
|
|
200
|
+
allow_indirect_imports = true
|
|
201
|
+
|
|
202
|
+
[[tool.importlinter.contracts]]
|
|
203
|
+
name = "Only ebaml.mcp imports the MCP SDK"
|
|
204
|
+
type = "forbidden"
|
|
205
|
+
source_modules = [
|
|
206
|
+
"ebaml.core",
|
|
207
|
+
"ebaml.graphs",
|
|
208
|
+
"ebaml.local",
|
|
209
|
+
"ebaml.llm",
|
|
210
|
+
"ebaml.benchmark",
|
|
211
|
+
]
|
|
212
|
+
forbidden_modules = ["mcp"]
|
|
213
|
+
|
|
178
214
|
[[tool.importlinter.contracts]]
|
|
179
215
|
name = "Only llm.descriptors imports the BAML SDK"
|
|
180
216
|
type = "forbidden"
|
|
@@ -198,6 +234,7 @@ forbidden_modules = [
|
|
|
198
234
|
"ebaml.graphs",
|
|
199
235
|
"ebaml.local",
|
|
200
236
|
"ebaml.llm",
|
|
237
|
+
"ebaml.mcp",
|
|
201
238
|
]
|
|
202
239
|
|
|
203
240
|
[tool.pyrefly]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ebaml"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "BAML for Explainable Boosting Machines: talk to your EBM."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -30,6 +30,17 @@ dependencies = [
|
|
|
30
30
|
"structlog>=26.1.0",
|
|
31
31
|
]
|
|
32
32
|
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
# The server for agents. Only ebaml.mcp imports these packages. The lower bound of mcp matches the override in
|
|
35
|
+
# the uv override list, so the extra keeps the fixed release after the override goes away.
|
|
36
|
+
mcp = [
|
|
37
|
+
"joblib>=1.5.0",
|
|
38
|
+
"mcp>=1.30.0",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
ebaml-mcp = "ebaml.mcp.server:main"
|
|
43
|
+
|
|
33
44
|
[project.urls]
|
|
34
45
|
Documentation = "https://johnny-godoy.github.io/EBaMl/"
|
|
35
46
|
Source = "https://github.com/johnny-godoy/EBaMl"
|
|
@@ -171,8 +182,9 @@ release = [
|
|
|
171
182
|
]
|
|
172
183
|
|
|
173
184
|
[tool.vulture]
|
|
174
|
-
# reason: fixtures are used through pytest's name-based injection,
|
|
175
|
-
|
|
185
|
+
# reason: recurring patterns: fixtures are used through pytest's name-based injection, and the functions that
|
|
186
|
+
# @server.tool and @server.resource register are called by the MCP SDK by name. Vulture cannot see either.
|
|
187
|
+
ignore_decorators = ["@pytest.fixture", "@server.tool", "@server.resource"]
|
|
176
188
|
# reason: pytest reads pytestmark and the pytest_* hooks of a conftest.py by name, code never references them, so vulture
|
|
177
189
|
# reports them as unused.
|
|
178
190
|
ignore_names = ["pytestmark", "pytest_*"]
|
|
@@ -197,9 +209,9 @@ root_package = "ebaml"
|
|
|
197
209
|
include_external_packages = true
|
|
198
210
|
|
|
199
211
|
[[tool.importlinter.contracts]]
|
|
200
|
-
name = "Layers: llm over local over graphs over core"
|
|
212
|
+
name = "Layers: mcp over llm over local over graphs over core"
|
|
201
213
|
type = "layers"
|
|
202
|
-
layers = ["ebaml.llm", "ebaml.local", "ebaml.graphs", "ebaml.core"]
|
|
214
|
+
layers = ["ebaml.mcp", "ebaml.llm", "ebaml.local", "ebaml.graphs", "ebaml.core"]
|
|
203
215
|
|
|
204
216
|
[[tool.importlinter.contracts]]
|
|
205
217
|
name = "Domain code does not import the BAML SDK"
|
|
@@ -207,6 +219,20 @@ type = "forbidden"
|
|
|
207
219
|
source_modules = ["ebaml.core", "ebaml.graphs", "ebaml.local", "ebaml.benchmark"]
|
|
208
220
|
forbidden_modules = ["baml_sdk", "baml_bridge"]
|
|
209
221
|
|
|
222
|
+
[[tool.importlinter.contracts]]
|
|
223
|
+
name = "The MCP layer reaches the BAML SDK only through ebaml.llm"
|
|
224
|
+
type = "forbidden"
|
|
225
|
+
source_modules = ["ebaml.mcp"]
|
|
226
|
+
forbidden_modules = ["baml_sdk", "baml_bridge"]
|
|
227
|
+
# reason: ebaml.mcp calls describe_graph and describe_ebm of ebaml.llm, which import the SDK, so only a direct import is wrong.
|
|
228
|
+
allow_indirect_imports = true
|
|
229
|
+
|
|
230
|
+
[[tool.importlinter.contracts]]
|
|
231
|
+
name = "Only ebaml.mcp imports the MCP SDK"
|
|
232
|
+
type = "forbidden"
|
|
233
|
+
source_modules = ["ebaml.core", "ebaml.graphs", "ebaml.local", "ebaml.llm", "ebaml.benchmark"]
|
|
234
|
+
forbidden_modules = ["mcp"]
|
|
235
|
+
|
|
210
236
|
[[tool.importlinter.contracts]]
|
|
211
237
|
name = "Only llm.descriptors imports the BAML SDK"
|
|
212
238
|
type = "forbidden"
|
|
@@ -226,7 +252,7 @@ ignore_imports = [
|
|
|
226
252
|
name = "The benchmark stands alone"
|
|
227
253
|
type = "forbidden"
|
|
228
254
|
source_modules = ["ebaml.benchmark"]
|
|
229
|
-
forbidden_modules = ["ebaml.core", "ebaml.graphs", "ebaml.local", "ebaml.llm"]
|
|
255
|
+
forbidden_modules = ["ebaml.core", "ebaml.graphs", "ebaml.local", "ebaml.llm", "ebaml.mcp"]
|
|
230
256
|
|
|
231
257
|
[tool.pyrefly]
|
|
232
258
|
# The strict preset reports implicit `Any` in parameters, lambdas, attributes, empty containers and type arguments.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""The tool that explains one prediction with the exact local facts. It calls no LLM."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
|
|
5
|
+
import attrs
|
|
6
|
+
|
|
7
|
+
from ebaml.core.custom_types import FeatureValue
|
|
8
|
+
from ebaml.core.exceptions import InvalidInstanceError
|
|
9
|
+
from ebaml.local.audience import resolve_audience
|
|
10
|
+
from ebaml.local.fact_text import FactTexts, facts_to_texts
|
|
11
|
+
from ebaml.local.facts import LocalFacts, LocalOptions, compute_local_facts
|
|
12
|
+
from ebaml.mcp.model_store import ModelStore
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@attrs.frozen
|
|
16
|
+
class PredictionExplanation:
|
|
17
|
+
"""The facts of one prediction and their texts.
|
|
18
|
+
|
|
19
|
+
Attributes
|
|
20
|
+
----------
|
|
21
|
+
facts: LocalFacts
|
|
22
|
+
The prediction, the contributions and the three local explanations.
|
|
23
|
+
texts: FactTexts
|
|
24
|
+
The facts as the JSON texts that the prompts read, for the audience of the call.
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
facts: LocalFacts
|
|
29
|
+
texts: FactTexts
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def explain_prediction(
|
|
33
|
+
store: ModelStore,
|
|
34
|
+
*,
|
|
35
|
+
instance: Mapping[str, FeatureValue] | None = None,
|
|
36
|
+
row: int | None = None,
|
|
37
|
+
confidence_level: float = 0.95,
|
|
38
|
+
audience: str = "layperson",
|
|
39
|
+
) -> PredictionExplanation:
|
|
40
|
+
"""Compute the local facts of one prediction.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
store: ModelStore
|
|
45
|
+
The session.
|
|
46
|
+
instance: Mapping[str, FeatureValue], optional
|
|
47
|
+
The value of every feature, by feature name.
|
|
48
|
+
row: int, optional
|
|
49
|
+
The position of a row of the data of ``--data``. Give exactly one of ``instance`` and ``row``.
|
|
50
|
+
confidence_level: float, default=0.95
|
|
51
|
+
See ``LocalOptions.confidence_level``.
|
|
52
|
+
audience: str, default="layperson"
|
|
53
|
+
The name of a built-in audience. It decides the keys of the texts.
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
PredictionExplanation
|
|
58
|
+
The facts and their texts.
|
|
59
|
+
|
|
60
|
+
Raises
|
|
61
|
+
------
|
|
62
|
+
InvalidInstanceError
|
|
63
|
+
If the call gives both or none of ``instance`` and ``row``.
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
if (instance is None) == (row is None):
|
|
67
|
+
msg = "Give exactly one of instance and row."
|
|
68
|
+
raise InvalidInstanceError(msg)
|
|
69
|
+
values = store.row_instance(row) if row is not None else dict(instance or {})
|
|
70
|
+
facts = compute_local_facts(store.ebm, values, LocalOptions(confidence_level=confidence_level))
|
|
71
|
+
return PredictionExplanation(facts=facts, texts=facts_to_texts(facts, resolve_audience(audience)))
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""The tools that ask the LLM to describe the model. The server registers them only when the user gives ``--llm``."""
|
|
2
|
+
|
|
3
|
+
from ebaml.llm.descriptors import describe_ebm, describe_graph
|
|
4
|
+
from ebaml.llm.options import ModelOptions
|
|
5
|
+
from ebaml.mcp.model_store import ModelStore
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def describe_feature(store: ModelStore, llm: ModelOptions, feature: str) -> str:
|
|
9
|
+
"""Ask the LLM to describe the graph of one feature.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
store: ModelStore
|
|
14
|
+
The session.
|
|
15
|
+
llm: ModelOptions
|
|
16
|
+
The LLM.
|
|
17
|
+
feature: str
|
|
18
|
+
The name of the feature.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
str
|
|
23
|
+
The output of ``describe_graph``.
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
return describe_graph(store.ebm, store.feature_index(feature), model=llm)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def describe_model(store: ModelStore, llm: ModelOptions) -> str:
|
|
30
|
+
"""Ask the LLM to describe the whole model. The first call computes the text and the next calls reuse it.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
store: ModelStore
|
|
35
|
+
The session.
|
|
36
|
+
llm: ModelOptions
|
|
37
|
+
The LLM.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
str
|
|
42
|
+
The output of ``describe_ebm``.
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
if store.model_description is None:
|
|
46
|
+
store.model_description = describe_ebm(store.ebm, model=llm)
|
|
47
|
+
return store.model_description
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""The state of one server session: the EBM, the optional data and the optional LLM options.
|
|
2
|
+
|
|
3
|
+
The user gives the paths at start. No tool argument names a path, so an agent cannot make the server load a file.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
import attrs
|
|
9
|
+
import joblib
|
|
10
|
+
import pandas as pd
|
|
11
|
+
from interpret.glassbox import ExplainableBoostingClassifier, ExplainableBoostingRegressor # pyrefly: ignore[implicit-reexport] -- interpret.glassbox has no __all__, so pyrefly reads its public classes as private imports
|
|
12
|
+
|
|
13
|
+
from ebaml.core.custom_types import ExplainableBoostingModel, FeatureValue
|
|
14
|
+
from ebaml.core.exceptions import InvalidInstanceError, UnsupportedModelError
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@attrs.define
|
|
18
|
+
class ModelStore:
|
|
19
|
+
"""The EBM of the session and what the tools need besides it.
|
|
20
|
+
|
|
21
|
+
Attributes
|
|
22
|
+
----------
|
|
23
|
+
ebm: ExplainableBoostingModel
|
|
24
|
+
The fitted EBM.
|
|
25
|
+
data: pd.DataFrame | None
|
|
26
|
+
The rows that the ``row`` argument of the explain tool indexes.
|
|
27
|
+
model_description: str | None
|
|
28
|
+
The output of ``describe_ebm``. The first call computes it and the next calls reuse it.
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
ebm: ExplainableBoostingModel
|
|
33
|
+
data: pd.DataFrame | None = None
|
|
34
|
+
model_description: str | None = None
|
|
35
|
+
|
|
36
|
+
def feature_index(self, feature: str) -> int:
|
|
37
|
+
"""Find the index of a feature by its name.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
feature: str
|
|
42
|
+
The name of the feature.
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
int
|
|
47
|
+
The index of the feature in ``feature_names_in_``.
|
|
48
|
+
|
|
49
|
+
Raises
|
|
50
|
+
------
|
|
51
|
+
InvalidInstanceError
|
|
52
|
+
If the model has no feature with this name.
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
names = list(self.ebm.feature_names_in_)
|
|
56
|
+
if feature not in names:
|
|
57
|
+
msg = f"The model has no feature {feature!r}. The features are: {names}."
|
|
58
|
+
raise InvalidInstanceError(msg)
|
|
59
|
+
return names.index(feature)
|
|
60
|
+
|
|
61
|
+
# nosemgrep: ebaml-return-attrs-not-container -- the keys are the feature names of the model, so they are data
|
|
62
|
+
def row_instance(self, row: int) -> dict[str, FeatureValue]:
|
|
63
|
+
"""Read one row of the data as an instance of the model.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
row: int
|
|
68
|
+
The position of the row in the data of ``--data``.
|
|
69
|
+
|
|
70
|
+
Returns
|
|
71
|
+
-------
|
|
72
|
+
dict[str, FeatureValue]
|
|
73
|
+
The value of each feature of the model.
|
|
74
|
+
|
|
75
|
+
Raises
|
|
76
|
+
------
|
|
77
|
+
InvalidInstanceError
|
|
78
|
+
If the server has no data, the row does not exist, or the data lacks a feature.
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
if self.data is None:
|
|
82
|
+
msg = "The server has no data. Start it with --data to use the row argument, or pass an instance."
|
|
83
|
+
raise InvalidInstanceError(msg)
|
|
84
|
+
if not 0 <= row < len(self.data):
|
|
85
|
+
msg = f"The row {row} does not exist. The data has {len(self.data)} rows, numbered from 0."
|
|
86
|
+
raise InvalidInstanceError(msg)
|
|
87
|
+
names = list(self.ebm.feature_names_in_)
|
|
88
|
+
missing = [name for name in names if name not in self.data.columns]
|
|
89
|
+
if missing:
|
|
90
|
+
msg = f"The data has no column for these features: {missing}."
|
|
91
|
+
raise InvalidInstanceError(msg)
|
|
92
|
+
return {name: self.data.iloc[row][name] for name in names}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def load_model(path: str | os.PathLike[str]) -> ExplainableBoostingModel:
|
|
96
|
+
"""Load a pickled or joblib EBM from the path that the user gave.
|
|
97
|
+
|
|
98
|
+
Loading a pickle runs code from the file. Call this function only with a path from the command line of the user,
|
|
99
|
+
never with a path from a tool argument.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
path: str | os.PathLike[str]
|
|
104
|
+
The file of the fitted EBM.
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
ExplainableBoostingModel
|
|
109
|
+
The EBM.
|
|
110
|
+
|
|
111
|
+
Raises
|
|
112
|
+
------
|
|
113
|
+
UnsupportedModelError
|
|
114
|
+
If the file does not hold an EBM.
|
|
115
|
+
|
|
116
|
+
"""
|
|
117
|
+
model = joblib.load(path)
|
|
118
|
+
if not isinstance(model, ExplainableBoostingClassifier | ExplainableBoostingRegressor):
|
|
119
|
+
msg = f"The file {os.fspath(path)!r} does not hold an EBM. It holds a {type(model).__name__}."
|
|
120
|
+
raise UnsupportedModelError(msg)
|
|
121
|
+
return model
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def load_data(path: str | os.PathLike[str]) -> pd.DataFrame:
|
|
125
|
+
"""Read the CSV file of the data.
|
|
126
|
+
|
|
127
|
+
Parameters
|
|
128
|
+
----------
|
|
129
|
+
path: str | os.PathLike[str]
|
|
130
|
+
The CSV file.
|
|
131
|
+
|
|
132
|
+
Returns
|
|
133
|
+
-------
|
|
134
|
+
pd.DataFrame
|
|
135
|
+
The rows.
|
|
136
|
+
|
|
137
|
+
"""
|
|
138
|
+
return pd.read_csv(path)
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""The tools that read an EBM: its summary, its features and the text of a graph.
|
|
2
|
+
|
|
3
|
+
Each function calls code of a lower layer and returns an attrs class. The server turns the class into JSON.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import attrs
|
|
7
|
+
import numpy as np
|
|
8
|
+
from interpret.glassbox import ExplainableBoostingClassifier # pyrefly: ignore[implicit-reexport] -- interpret.glassbox has no __all__, so pyrefly reads its public classes as private imports
|
|
9
|
+
|
|
10
|
+
from ebaml.core.custom_types import ClassLabel, Normalization
|
|
11
|
+
from ebaml.graphs.ebm_graph import EBMGraph
|
|
12
|
+
from ebaml.graphs.model_kinds import model_kind
|
|
13
|
+
from ebaml.graphs.terms import main_effect_features, main_term
|
|
14
|
+
from ebaml.mcp.model_store import ModelStore
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@attrs.frozen
|
|
18
|
+
class ModelSummary:
|
|
19
|
+
"""The facts about the model that an agent needs first.
|
|
20
|
+
|
|
21
|
+
Attributes
|
|
22
|
+
----------
|
|
23
|
+
kind: str
|
|
24
|
+
``BinaryClassifier``, ``MulticlassClassifier`` or ``Regressor``.
|
|
25
|
+
outputs: list[str]
|
|
26
|
+
The names of the outputs of the model.
|
|
27
|
+
classes: list[ClassLabel]
|
|
28
|
+
The class labels, in the order of the scores. The list is empty for a regressor.
|
|
29
|
+
score_meaning: str
|
|
30
|
+
What a score of a graph means.
|
|
31
|
+
intercept: list[float]
|
|
32
|
+
The intercept: one value, or one value per class for a multiclass classifier.
|
|
33
|
+
feature_count: int
|
|
34
|
+
The number of features that have a graph.
|
|
35
|
+
skipped_terms: list[str]
|
|
36
|
+
The interaction terms. The tools skip them.
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
kind: str
|
|
41
|
+
outputs: list[str]
|
|
42
|
+
classes: list[ClassLabel]
|
|
43
|
+
score_meaning: str
|
|
44
|
+
intercept: list[float]
|
|
45
|
+
feature_count: int
|
|
46
|
+
skipped_terms: list[str]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@attrs.frozen
|
|
50
|
+
class FeatureInfo:
|
|
51
|
+
"""One feature of the model."""
|
|
52
|
+
|
|
53
|
+
name: str
|
|
54
|
+
type: str
|
|
55
|
+
importance: float
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def model_summary(store: ModelStore) -> ModelSummary:
|
|
59
|
+
"""Summarize the model.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
store: ModelStore
|
|
64
|
+
The session.
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
ModelSummary
|
|
69
|
+
The kind, the outputs, the intercept, the number of features and the interaction terms that the tools skip.
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
ebm = store.ebm
|
|
73
|
+
kind = model_kind(ebm)
|
|
74
|
+
names = list(ebm.feature_names_in_)
|
|
75
|
+
# only a classifier has class labels; one check at the entry narrows the union of the two interpret classes
|
|
76
|
+
classes: list[ClassLabel] = (
|
|
77
|
+
np.asarray(ebm.classes_).tolist() if isinstance(ebm, ExplainableBoostingClassifier) else []
|
|
78
|
+
)
|
|
79
|
+
skipped = [" x ".join(names[index] for index in features) for features in ebm.term_features_ if len(features) > 1]
|
|
80
|
+
return ModelSummary(
|
|
81
|
+
kind=type(kind).__name__,
|
|
82
|
+
outputs=kind.outputs,
|
|
83
|
+
classes=classes,
|
|
84
|
+
score_meaning=kind.score_meaning,
|
|
85
|
+
intercept=[float(value) for value in np.ravel(ebm.intercept_)],
|
|
86
|
+
feature_count=len(main_effect_features(ebm)),
|
|
87
|
+
skipped_terms=skipped,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def list_features(store: ModelStore) -> list[FeatureInfo]:
|
|
92
|
+
"""List the features with a graph, the most important first.
|
|
93
|
+
|
|
94
|
+
Parameters
|
|
95
|
+
----------
|
|
96
|
+
store: ModelStore
|
|
97
|
+
The session.
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
list[FeatureInfo]
|
|
102
|
+
The name, the type and the importance of each feature, sorted by importance.
|
|
103
|
+
|
|
104
|
+
"""
|
|
105
|
+
ebm = store.ebm
|
|
106
|
+
importances = ebm.term_importances()
|
|
107
|
+
features = [
|
|
108
|
+
FeatureInfo(
|
|
109
|
+
name=ebm.feature_names_in_[index],
|
|
110
|
+
type=ebm.feature_types_in_[index],
|
|
111
|
+
importance=float(importances[main_term(ebm, index)]),
|
|
112
|
+
)
|
|
113
|
+
for index in main_effect_features(ebm)
|
|
114
|
+
]
|
|
115
|
+
return sorted(features, key=lambda feature: feature.importance, reverse=True)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def graph_text( # ruff: ignore[too-many-arguments] -- one argument for each option of the get_graph tool
|
|
119
|
+
store: ModelStore,
|
|
120
|
+
feature: str,
|
|
121
|
+
*,
|
|
122
|
+
normalization: Normalization | str = Normalization.NONE,
|
|
123
|
+
x_axis_precision: int | None = None,
|
|
124
|
+
y_axis_precision: int | None = None,
|
|
125
|
+
max_tokens: int = 3000,
|
|
126
|
+
) -> str:
|
|
127
|
+
"""Write the graph of a feature as text.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
store: ModelStore
|
|
132
|
+
The session.
|
|
133
|
+
feature: str
|
|
134
|
+
The name of the feature.
|
|
135
|
+
normalization: Normalization | str, default=Normalization.NONE
|
|
136
|
+
See ``EBMGraph.from_ebm``.
|
|
137
|
+
x_axis_precision: int, optional
|
|
138
|
+
See ``EBMGraph.to_text``.
|
|
139
|
+
y_axis_precision: int, optional
|
|
140
|
+
See ``EBMGraph.to_text``.
|
|
141
|
+
max_tokens: int, default=3000
|
|
142
|
+
See ``EBMGraph.to_text``.
|
|
143
|
+
|
|
144
|
+
Returns
|
|
145
|
+
-------
|
|
146
|
+
str
|
|
147
|
+
The text of ``EBMGraph.to_text``.
|
|
148
|
+
|
|
149
|
+
"""
|
|
150
|
+
graph = EBMGraph.from_ebm(store.ebm, store.feature_index(feature), normalization)
|
|
151
|
+
return graph.to_text(
|
|
152
|
+
x_axis_precision=x_axis_precision,
|
|
153
|
+
y_axis_precision=y_axis_precision,
|
|
154
|
+
max_tokens=max_tokens,
|
|
155
|
+
)
|