Repository navigation
feat: add Explanation.to_markdown() for notebooks and reports (#1) - #22
Conversation
adaumsilva
left a comment
There was a problem hiding this comment.
Thanks for implementing this! The tests pass, but the table needs to escape its headers and cell contents before joining them.
For example, a feature named income|monthly introduces an extra column, and a feature value containing a newline breaks the row. This also affects custom consensus method names used as column headers.
Please add a shared Markdown-escaping helper for headers and cells. Handle pipes and backslashes, and convert embedded line breaks into a representation that stays within one table row.
Please add regression tests covering these characters in feature names, feature values, and consensus method headers. Once this is corrected, the implementation should be ready for another review.
|
@DYNOSuprovo thanks for the work! I requested a few changes before merging the PR. Please address these changes and submit the PR again. |
Add _escape_markdown helper to escape backslashes, table delimiter pipes, and embedded line breaks (<br>) across headers and cell values in to_markdown. Add regression tests covering special characters in feature names, values, and custom consensus method headers.
|
Hi @adaumsilva! 👋 I've implemented the requested Markdown escaping and added comprehensive regression tests:
Ready for your review! |
|
Solid work @DYNOSuprovo ! Thanks for addressing the changes. PR approved and merged. Remember to star the repo if you didn't yet. |
|
Thanks @adaumsilva for merging! Starred the repository — glad to contribute to XAI-framework. |
What
Closes #1
Adds
Explanation.to_markdown(k=10) -> strto render explanations as formatted Markdown tables for notebooks, pull request descriptions, and reports.Why
Currently,
Explanationsupportsto_text(),to_dataframe(),to_dict(), andplot(). When embedding explanations in Markdown documents, reports, or PR descriptions, a native Markdown table is cleaner and more readable than plain text.How
Explanation.to_markdown(k=10):_headline()for the summary line.feature | value | attributioncolumns for local explanations, orfeature | attributionwhenfeature_valuesisNone(such as in global explanations).ConsensusExplanationusing normalised attributions via_markdown_component_data()._extra_text()to append agreement level hints for consensus explanations (or surrogate fittabulate).tests/test_explanation.pycovering local classification, row limits viak, global explanations, regression, consensus explanations with method columns, and surrogateREADME.md's "TheExplanationobject" table andCHANGELOG.mdunder[Unreleased].Checklist
pytestpassesruff checkandruff format --checkpassself.rng(reproducible withrandom_state)