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
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 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 | |
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
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | |
effector.report.Report(method_name, feature_names, target_name, features, config=dict(), overview=list(), explained_variance=None, summary=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
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 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 | |
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
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
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
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 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 | |
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
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | |
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
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 | |
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
244 245 246 247 248 249 250 251 252 253 254 255 256 | |
to_dict()
Serialize to a plain JSON-able dict (arrays become lists).
Source code in effector/report.py
231 232 233 234 235 236 237 238 239 240 241 242 | |