Api report
Summary
effector.explain(data, model, ...) runs the whole explanation pipeline in one
call and returns a Report — a serializable value (design contract R12):
- fit the chosen
methodonce - rank features by
importance(R13) - compute the mean-effect + heterogeneity curves for the top-
top_k find_regionson the features whoseheter_scoreclears the threshold
Every model call happens through the single fit; importance, curves, and
find_regions are all model-free afterwards.
Usage
import effector
report = effector.explain(X, predict, method="pdp", top_k=5)
report.show() # importance-ranked table + region trees
report.plot_importance() # horizontal bar chart
report.to_html("report.html") # self-contained page (figures inlined)
d = report.to_dict() # serialize (no effect needed to round-trip)
report2 = effector.Report.from_dict(d)
API
effector.report.explain(data, model, model_jac=None, *, y=None, schema=None, method='pdp', top_k=5, coverage=0.8, heter_threshold=None, min_r2_gain=0.01, finder='best', candidate_conditioning_features='all', nof_instances=10000, random_state=21)
Run the whole explanation pipeline and return a Report — a value.
report = effector.explain(X, model, method="pdp")
report.show() # ledger + ranked table + partition trees
report.to_html("report.html") # self-contained page
Fits the chosen method once, searches regions on every heterogeneous
feature (heter_score >= heter_threshold), greedily selects which splits
earn their complexity (select_regions — the CALM chain), and plots the
features that carry the analysis: descending final-CALM importance until
coverage of the total importance mass is shown, never more than
top_k, plus every accepted split feature.
Search wide, display by coverage
The region search and the R² selection run over all heterogeneous
features — a feature outside the display cut can still carry the
biggest explained-variance gain. coverage/top_k only trim the
curve plots; the triage plane and the ranked table always cover every
supported feature.
One model touch
All model calls happen through the single fit, plus one prediction
pass for the explained-variance denominator (f̂(X), cached on the
effect); everything after — importances, curves, find_regions, the
surrogate R²s — is model-free, so the call count does not grow with
top_k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
|
required | |
model
|
callable |
required | |
model_jac
|
callable |
None
|
|
y
|
optional |
None
|
|
schema
|
optional feature schema (names/types/categories). |
None
|
|
method
|
effect method — |
'pdp'
|
|
top_k
|
hard ceiling on how many features get curve plots. |
5
|
|
coverage
|
stop plotting once the shown features carry this share of the total importance mass (final-CALM importances, share-of-sum over the supported features; default 0.8). The report states the achieved share. |
0.8
|
|
heter_threshold
|
minimum |
None
|
|
min_r2_gain
|
smallest explained-variance marginal (fraction of
|
0.01
|
|
finder
|
region finder — |
'best'
|
|
candidate_conditioning_features
|
features allowed to define splits
( |
'all'
|
|
nof_instances
|
subsample size the effect is built on. |
10000
|
|
random_state
|
seed for the subsample. |
21
|
Returns:
| Type | Description |
|---|---|
Report
|
a |
Report
|
final-CALM-importance-descending order, partitions stored as dicts, |
Report
|
an |
Report
|
feature, and |
Report
|
( |
Report
|
splits, one snapshot per accepted split). |
Source code in effector/report.py
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 | |
effector.global_effect.GlobalEffectBase.explain(*, y=None, top_k=5, coverage=0.8, heter_threshold=None, min_r2_gain=0.01, finder='best', candidate_conditioning_features='all')
The one-liner on this engine — effector.explain without leaving the session.
pdp = effector.PDP(X, model, schema=schema)
report = pdp.explain() # same Report as effector.explain
Runs the same pipeline as effector.explain on the already-built
engine: features you have fit with custom config keep it (missing
ones are computed with the defaults), and every cache the pipeline
warms stays on the engine for your follow-up queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Optional[ndarray]
|
optional ground truth aligned with the original |
None
|
top_k
|
int
|
hard ceiling on how many features get curve plots. |
5
|
coverage
|
float
|
stop plotting once the shown features carry this share of the total importance mass (default 0.8). |
0.8
|
heter_threshold
|
Optional[float]
|
minimum |
None
|
min_r2_gain
|
float
|
smallest explained-variance marginal a split must add to earn a snapshot in the CALM chain. |
0.01
|
finder
|
region finder, as in |
'best'
|
|
candidate_conditioning_features
|
features allowed to define splits. |
'all'
|
Returns:
| Type | Description |
|---|---|
|
a |
Source code in effector/global_effect.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 | |
effector.report.Report(method_name, feature_names, target_name, features, config=dict(), overview=list(), explained_variance=None, summary=None, scale_y=None, scale_x_list=None)
dataclass
An importance-ranked, serializable explanation of a model — a value.
report = effector.explain(X, model)
report.show() # ledger + ranked table + partition trees
report.to_html("report.html") # self-contained page
features holds one FeatureReport per plotted feature, final-CALM
importance descending (split features at the instance-weighted mean of
their subregions). overview holds the cheap global scalars —
importance and heterogeneity — for every supported feature (superset
of features), so the triage plane renders even on unbound reports.
explained_variance holds the serialized CALM chain
(CalmSequence.to_dict()): the flat decision-sequence keys (gam_r2,
regional_r2, min_gain, stages, skipped) plus one serialized
snapshot per accepted split under calms — plain floats, so it too
renders unbound; None for derivative-scale methods. A report produced
by explain is bound to its fitted effect, which to_html uses for the
per-leaf regional plots; everything else works from the stored values
alone.
Methods:
| Name | Description |
|---|---|
show |
Print the report as three tables: what was explained (data + model), |
plot_importance |
Horizontal bar chart of feature importance: sorted descending, |
to_html |
Render the report as one self-contained HTML page — the pipeline in reading order. |
to_dict |
Serialize to a plain JSON-able dict. |
from_dict |
Rebuild a |
show(ascii=False)
Print the report as three tables: what was explained (data + model), the explained-variance decision sequence (accepted splits, then the rejected ones), and the ranked feature table (final-CALM values — split features at the instance-weighted mean of their subregions). Each accepted partition tree follows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ascii
|
draw with plain ASCII instead of box-drawing/block characters, for terminals and logs that mangle unicode. |
False
|
Works on unbound reports (rebuilt via from_dict) too.
Source code in effector/report.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
plot_importance(show_plot=True)
Horizontal bar chart of feature importance: sorted descending,
value at each bar tip, accepted split features tagged · split.
Covers every feature in overview (all supported features), not just
the reported top-k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_plot
|
|
True
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in effector/report.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
to_html(path=None, share_y='across')
Render the report as one self-contained HTML page — the pipeline in reading order.
The page reads top-down as the analysis: the overview first — the explained-variance ledger bar (the headline: what the global read buys, what each accepted split adds, what stays unexplained), the triage plane over all supported features with one arrow per accepted split (global point → weighted-mean point), the clickable ranked table with the achieved importance coverage, and the decision-sequence table. Then the regional analysis — the final CALM: one section per plotted feature in descending final-CALM importance; an accepted split renders as a group of per-leaf regional plots in rule order, everything else as its global curve (with a one-line pointer when a found split was rejected). Last, the global baseline: the split features' global curves alone — the counterfactual read without regions. Every figure is a base64 PNG; navigation, click-to-zoom, and collapsing are inline vanilla JS/CSS — no external assets, one file, one click.
For at-a-glance comparison, every panel of every effect plot — the
effect axis, and (RH)ALE's dy/dx axis below it — shares a y range
with the same panel of the other plots, either across all features
(share_y="across") or within each one ("within"). The x range is
always shared per feature (its global plot and its leaves). Every
figure is drawn with the method's own default heterogeneity view — the
dy/dx bars for the (RH)ALE family, the (d-)ICE cloud for the PDP
family, the SHAP scatter for SHAP-DP.
Unbound reports
A report rebuilt with from_dict renders everything from stored
values — including the ledger and the triage arrows; only the
per-leaf regional plots need the live effect, and leaf
statistics are shown in a table instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
optional file path to write the page to. |
None
|
|
share_y
|
scope of the shared y (and |
'across'
|
No windows
The figures are built off-screen and closed once encoded, so
rendering a report never pops up a plot — even in an interactive
session where plot() normally does.
Returns:
| Type | Description |
|---|---|
|
the HTML string when |
|
|
|
|
|
markup. |
Source code in effector/report.py
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 | |
to_dict()
Serialize to a plain JSON-able dict.
Values only
Curves, scores, and partition rules are serialized — never the model, the data, or the fitted effect.
Returns:
| Type | Description |
|---|---|
|
a dict that |
Source code in effector/report.py
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 | |
from_dict(d)
classmethod
Rebuild a Report from to_dict() output.
The result is unbound: show, plot_importance, and to_html all
work from the stored values; to_html skips only the per-leaf
regional plots and the triage arrows, which need the live effect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
a dict produced by |
required |
Returns:
| Type | Description |
|---|---|
|
an unbound |
Source code in effector/report.py
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 | |
effector.report.FeatureReport(feature, name, importance, heter_score, xs, y, h, partition=None)
dataclass
The per-feature slice of a Report — plain values, no live effect.
Attributes:
| Name | Type | Description |
|---|---|---|
feature |
int
|
feature index. |
name |
str
|
feature display name. |
importance |
float
|
the feature's importance score. |
heter_score |
float
|
the feature's scalar heterogeneity. |
xs |
ndarray
|
evaluation grid, |
y |
ndarray
|
mean-effect curve at |
h |
ndarray
|
heterogeneity curve at |
partition |
Optional[dict]
|
|
Methods:
| Name | Description |
|---|---|
from_dict |
Rebuild a |
to_dict |
Serialize to a plain JSON-able dict (arrays become lists). |
from_dict(d)
classmethod
Rebuild a FeatureReport from to_dict() output.
Source code in effector/report.py
257 258 259 260 261 262 263 264 265 266 267 268 269 | |
to_dict()
Serialize to a plain JSON-able dict (arrays become lists).
Source code in effector/report.py
244 245 246 247 248 249 250 251 252 253 254 255 | |