Summary
All global effect methods have a similar interface and workflow:
- create an instance of the global effect method you want to use
- (optional)
.fit()to customize the method .plot()to plot the global effect of a feature.eval()to evaluate the global effect of a feature at a specific grid of points
Usage
# set up the input
X = ... # input data
predict = ... # model to be explained
jacobian = ... # jacobian of the model
-
Create an instance of the global effect method you want to use:
g_method = effector.PDP(data=X, model=predict)g_method = effector.RHALE(data=X, model=predict, model_jac=jacobian)g_method = effector.ShapDP(data=X, model=predict)g_method = effector.ALE(data=X, model=predict)g_method = effector.DerPDP(data=X, model=predict, model_jac=jacobian) -
Customize the global effect method (optional):
.fit(features, **method_specific_args)This is the place for customization
The
.fit()step can be omitted if you are ok with the default settings; you can directly call the.plot(), or.eval()methods. However, if you want more control over the fitting process, you can pass additional arguments to the.fit()method. Check the Usage section below and the method-specific documentation for more information.Usage
# customize the axis-partitioning (binning) method binning_method = effector.axis_partitioning.Agglomerative( init_nof_bins = 50, # start from 50 bins (default: 20) min_points_per_bin = 10, # minimum number of points per bin (default: 2) ) g_method.fit( features=[0, 1], # list of features to be analyzed binning_method=binning_method, # custom binning method ) -
Plot the global effect of a feature:
.plot(feature)Usage
feature = ... g_method.plot(feature, **plot_specific_args) -
Evaluate the global effect of a feature at a specific grid of points:
.eval(feature, xs)Usage
# Example input feature = ... # feature to be analyzed xs = ... # grid of points to evaluate the global effect, e.g., np.linspace(0, 1, 100)y = g_method.eval(feature, xs) het = g_method.eval_heter(feature, xs)
API
effector.global_effect_ale.ALE(data, model, *, nof_instances=10000, axis_limits=None, schema=None, random_state=21)
Bases: ALEBase
Accumulated Local Effects: the effect built bin-by-bin from local model differences — the safe choice for correlated features.
ale = effector.ALE(X, model)
ale.plot("hr")
The axis is split into \(K\) fixed bins with limits \(z_0 < \dots < z_K\). Each instance in bin \(k\) contributes the secant of the model across the bin; the per-bin means \(\mu_k\) are accumulated:
Instances only move within their own bin, so ALE stays close to the data manifold where PDP would extrapolate. The heterogeneity at \(x\) is the variance of the local effects within its bin.
Differentiable model? Use RHALE
effector.RHALE reads the local effects off the model Jacobian:
no dependence on bin width, and automatic bin sizing.
Build an ALE explainer. No model calls happen here.
Heterogeneity
eval_heter returns a step function: the variance of the local
effects within the bin containing \(x\),
The bin plot draws \(\sqrt{\sigma^2_k}\) as error bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
the design matrix, shape |
required |
model
|
callable
|
the black-box model — a |
required |
nof_instances
|
Union[int, str]
|
max instances kept (default |
10000
|
axis_limits
|
Optional[ndarray]
|
per-feature plot limits, shape |
None
|
schema
|
Optional[Union[Schema, dict]]
|
input metadata — an |
None
|
random_state
|
Optional[int]
|
seed for every internal random step (default |
21
|
Methods:
| Name | Description |
|---|---|
fit |
Declare per-feature defaults and warm the caches. |
eval |
The mean effect of a feature at positions |
eval_heter |
The heterogeneity curve h(xs): how much per-instance effects disagree at each x. |
grid |
The evaluation grid on which this feature's effect is model-free. |
heter_score |
One number for a feature's heterogeneity — the scalar |
payload |
The raw fitted object behind |
importance |
How much a feature's mean effect moves the prediction (R13). |
importances |
The whole importance vector — rank your features in one call. |
find_regions |
Search for subregions that resolve a feature's heterogeneity. |
select_regions |
Greedily select which partitions earn their complexity — the CALM chain. |
explain |
The one-liner on this engine — |
plot |
Plot the (RH)ALE effect of |
Source code in effector/global_effect_ale.py
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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |
fit(features='all', *, centering=True, binning_method='fixed', order=None)
Declare per-feature defaults and warm the caches.
ale.fit("hr", binning_method=Fixed(nof_bins=30))
fit is optional
eval, plot, heter_score compute what they need lazily with
these defaults; fit declares the config once and pays the model
cost upfront.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Union[int, str, list]
|
feature(s) to fit — index, name, list, or |
'all'
|
centering
|
Union[bool, str]
|
default centering for this feature's queries —
|
True
|
binning_method
|
Union[str, Fixed]
|
|
'fixed'
|
order
|
Union[None, str, list]
|
level order for a categorical feature of interest:
Changing |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in effector/global_effect_ale.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
eval(feature, xs, centering=None, mask=None, rule=None)
The mean effect of a feature at positions xs.
xs = np.linspace(0, 24, 100)
y = pdp.eval("hr", xs) # (100,) mean effect
y_wd = pdp.eval("hr", xs, rule="workingday == 0") # same, on a subregion
One array, one type (R1)
eval always returns the mean effect only. The spread around it
has its own ladder: eval_heter (curve), heter_score (scalar),
payload (the raw fitted object).
Discrete features
Ordinal/nominal features are evaluated only at observed
levels — any other xs value raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
centering
|
Union[None, bool, str]
|
|
None
|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the mean effect at |
Source code in effector/global_effect.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
eval_heter(feature, xs, mask=None, rule=None)
The heterogeneity curve h(xs): how much per-instance effects disagree at each x.
h = pdp.eval_heter("hr", xs) # (T,) variance around the mean
band = np.sqrt(h) # std-like band, plot-ready
It's a variance, and it's method-specific (R2)
PDP: variance of centered ICE; DerPDP: of d-ICE slopes; ALE/RHALE: per-bin slope variance as a step function; ShapDP: interpolated per-bin φ variance. Take the square root for a band.
No centering argument — by design
Heterogeneity is invariant to centering; the signature enforces it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the heterogeneity curve h(xs), |
Source code in effector/global_effect.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
grid(feature)
The evaluation grid on which this feature's effect is model-free.
The observed levels for a discrete feature; otherwise
helpers.NOF_INTERNAL_POINTS equally spaced points inside the
feature's axis limits — the cache grid explain evaluates every
reported curve on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in effector/global_effect.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
heter_score(feature, mask=None, rule=None)
One number for a feature's heterogeneity — the scalar find_regions minimizes.
pdp.heter_score("hr") # global
pdp.heter_score("hr", rule="workingday == 0") # within a subregion
In output units (units contract, method_semantics.md): the RMS of
eval_heter over the feature's own (masked) data values
(frequency-weighted over levels for categorical features), bridged by
the feature's dispersion for the derivative-based methods
(ALE/RHALE/DerPDP) so every feature type and every method lands on the
same y-unit scale — "a typical instance's effect deviates from the
mean effect by about this much". eval_heter itself stays a variance
curve in the method's native units.
Pair it with importance
importance measures the mean effect's strength; heter_score
measures the spread around it — same units, mean/spread twins.
High importance + high heterogeneity = the top-right corner of
effector.plot_triage — where find_regions should look.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar, in output units. |
Source code in effector/global_effect.py
755 756 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 | |
payload(feature)
The raw fitted object behind eval/eval_heter — pure numpy, yours to inspect.
p = ale.payload("hr") # e.g. {"limits": ..., "bin_effect": ..., "bin_variance": ...}
Per method: per-bin effects and variances for (RH)ALE and ShapDP, the grid summaries for (d-)PDP. A copy — mutate freely.
Source code in effector/global_effect.py
743 744 745 746 747 748 749 750 751 752 753 | |
importance(feature, mask=None, rule=None)
How much a feature's mean effect moves the prediction (R13).
pdp.importance("temp") # scalar
pdp.importance("temp", rule="workingday == 1") # within a subregion
The dispersion of the mean effect in output units — the μ-twin of
heter_score (which measures per-instance spread on the same scale).
A flat curve scores ~0; a swinging curve scores high. Per method: std
of the mean effect over the (masked) data values (PDP/ALE/RHALE/
ShapDP; for a linear model this is |coefficient| * std(x)),
mean(|derivative|) * std(x) (DerPDP). Comparable across feature
types and, in magnitude, across methods.
No y, ever
effector never sees ground-truth labels — this is a property of the fitted effect, not a loss/permutation importance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar. |
Source code in effector/global_effect.py
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 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
importances(mask=None, rule=None)
The whole importance vector — rank your features in one call.
imp = pdp.importances() # (D,)
order = np.argsort(-np.nan_to_num(imp)) # most important first
NaN means unsupported, not unimportant
Feature types this method cannot explain (e.g. DerPDP on a
nominal feature) return NaN, with one UserWarning naming them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the per-feature importance vector, |
Source code in effector/global_effect.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
find_regions(feature=None, *, features=None, finder='best', candidate_conditioning_features='all')
Search for subregions that resolve a feature's heterogeneity.
part = pdp.find_regions("hr") # one feature -> Partition
part.show() # the tree + level stats
pdp.plot("hr", rule=part.leaves[0].rule) # drill into a leaf
parts = pdp.find_regions(features="heterogeneous") # several -> {name: Partition}
effector.plot_triage(pdp, partitions=parts) # the before/after picture
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect. Don't like a partition? Search again with different finder kwargs; nothing needs resetting.
Model-free
Every candidate split is scored by heter_score(feature, mask)
on the cached local effects — zero model calls, whatever the grid
size. Binning/scope are those the feature was fitted with,
replayed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str, None]
|
index or name of the one feature to partition
(→ |
None
|
features
|
Union[list, str, None]
|
several at once — a list, |
None
|
finder
|
|
'best'
|
|
candidate_conditioning_features
|
features allowed to define splits
( |
'all'
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
with |
Source code in effector/global_effect.py
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 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
select_regions(partitions=None, *, features='heterogeneous', finder='best', candidate_conditioning_features='all', min_r2_gain=0.01)
Greedily select which partitions earn their complexity — the CALM chain.
chain = pdp.select_regions() # search + select in one call
chain.show() # GAM R2, each accepted split, the rejected
chain.final # the last CALM — the regional analysis
chain[0] # the GAM snapshot
find_regions proposes one candidate Partition per feature;
this verb decides across features which of them actually explain
the model: starting from the GAM (all features global), each round
applies the split with the largest explained-variance gain — the
surrogate R² against f̂, measured on top of the splits already
applied — and stops when no remaining split adds at least
min_r2_gain. Every accepted round is a snapshot (CALM) of
increased complexity; the whole chain is the report's ledger.
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect.
One prediction pass
Beyond fit, the only model touch is one f̂(X) pass for the
variance denominator (cached on the effect); the search, the
scoring, and every snapshot's summaries are model-free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partitions
|
Optional[dict]
|
pre-computed candidates — |
None
|
features
|
Union[list, str]
|
which features to search when |
'heterogeneous'
|
finder
|
region finder, as in |
'best'
|
|
candidate_conditioning_features
|
features allowed to define
splits ( |
'all'
|
|
min_r2_gain
|
float
|
smallest explained-variance marginal (fraction of
|
0.01
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
it, with the rejected splits in |
|
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
the method is derivative-scale (no output-scale
surrogate) or |
Source code in effector/global_effect.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
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 | |
plot(feature, heterogeneity=True, centering=True, scale_x=None, scale_y=None, show_avg_output=False, y_limits=None, dy_limits=None, show_only_aggregated=False, show_plot=True, mask=None, rule=None, feature_label=None)
Plot the (RH)ALE effect of feature.
ale.plot("hr") # curve + heterogeneity
ale.plot("hr", rule="workingday == 0") # within a subregion
For a continuous feature the figure has two panels: the accumulated curve on top, the per-bin average local effect (± std) below. Categorical features get one bar per level with std whiskers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature to plot. |
required |
heterogeneity
|
Union[bool, str]
|
|
True
|
centering
|
Union[bool, str]
|
|
True
|
scale_x
|
Optional[dict]
|
|
None
|
scale_y
|
Optional[dict]
|
same, for the y axis. |
None
|
show_avg_output
|
bool
|
draw the model's average output as a horizontal line. |
False
|
y_limits
|
Optional[List]
|
|
None
|
dy_limits
|
Optional[List]
|
|
None
|
show_only_aggregated
|
bool
|
draw only the accumulated curve, without the bottom panel. |
False
|
show_plot
|
bool
|
if |
True
|
mask
|
Optional[ndarray]
|
boolean |
None
|
rule
|
sugar over |
None
|
|
feature_label
|
Optional[str]
|
display title for the figure (e.g. a regional node's label with its rule); defaults to the feature name. The x-axis always keeps the plain feature name. |
None
|
Source code in effector/global_effect_ale.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 460 461 462 463 464 465 466 467 468 469 | |
effector.global_effect_ale.RHALE(data, model, model_jac=None, *, data_effect=None, nof_instances=10000, axis_limits=None, schema=None, random_state=21)
Bases: ALEBase
Robust and Heterogeneity-aware ALE: ALE computed from the model Jacobian, with automatic variable-size binning.
rhale = effector.RHALE(X, model, model_jac)
rhale.plot("hr")
The local effect of an instance is the pointwise derivative instead of ALE's bin secant, so it does not depend on the bin width — bins can be sized automatically (dynamic programming by default) to balance bias and variance. Accumulation and heterogeneity are then identical to ALE:
Needs derivatives
Pass model_jac (or a precomputed data_effect); otherwise the
Jacobian is estimated with slower, less exact numerical
differentiation. The Jacobian only serves the continuous features:
ordinal ones use discrete differences with adaptive level grouping,
and nominal ones fall back to ALE exactly (one bin per transition,
no grouping — "adjacent" is not real under an arbitrary order).
Build a RHALE explainer. No model calls happen here.
Heterogeneity
eval_heter returns a step function: the variance of the
per-instance derivatives within the bin containing \(x\),
The bin plot draws \(\sqrt{\sigma^2_k}\) as error bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
the design matrix, shape |
required |
model
|
callable
|
the black-box model — a |
required |
model_jac
|
Union[None, callable]
|
the model Jacobian — a |
None
|
data_effect
|
Optional[ndarray]
|
precomputed Jacobian on |
None
|
nof_instances
|
Union[int, str]
|
max instances kept (default |
10000
|
axis_limits
|
Optional[ndarray]
|
per-feature plot limits, shape |
None
|
schema
|
Optional[Union[Schema, dict]]
|
input metadata — an |
None
|
random_state
|
Optional[int]
|
seed for every internal random step (default |
21
|
Methods:
| Name | Description |
|---|---|
fit |
Declare per-feature defaults and warm the caches. |
eval |
The mean effect of a feature at positions |
eval_heter |
The heterogeneity curve h(xs): how much per-instance effects disagree at each x. |
grid |
The evaluation grid on which this feature's effect is model-free. |
heter_score |
One number for a feature's heterogeneity — the scalar |
payload |
The raw fitted object behind |
importance |
How much a feature's mean effect moves the prediction (R13). |
importances |
The whole importance vector — rank your features in one call. |
find_regions |
Search for subregions that resolve a feature's heterogeneity. |
select_regions |
Greedily select which partitions earn their complexity — the CALM chain. |
explain |
The one-liner on this engine — |
plot |
Plot the (RH)ALE effect of |
Source code in effector/global_effect_ale.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
fit(features='all', *, centering=True, binning_method='dp', order=None, binning_scope='global')
Declare per-feature defaults and warm the caches.
rhale.fit("hr", binning_method="dp")
fit is optional
eval, plot, heter_score compute what they need lazily with
these defaults; fit declares the config once and pays the model
cost upfront.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Union[int, str, list]
|
feature(s) to fit — index, name, list, or |
'all'
|
centering
|
Union[bool, str]
|
default centering for this feature's queries —
|
True
|
binning_method
|
Union[str, DynamicProgramming, Agglomerative, Quantile, Fixed]
|
how the axis is split into bins:
For custom parameters pass an instance from
|
'dp'
|
order
|
Union[None, str, list]
|
level order for a categorical feature of interest:
Changing |
None
|
binning_scope
|
str
|
the x-range the binner covers when a masked
summary re-bins a subregion (
Recorded at fit and replayed by every masked call. Ignored when no mask is involved. |
'global'
|
Source code in effector/global_effect_ale.py
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | |
eval(feature, xs, centering=None, mask=None, rule=None)
The mean effect of a feature at positions xs.
xs = np.linspace(0, 24, 100)
y = pdp.eval("hr", xs) # (100,) mean effect
y_wd = pdp.eval("hr", xs, rule="workingday == 0") # same, on a subregion
One array, one type (R1)
eval always returns the mean effect only. The spread around it
has its own ladder: eval_heter (curve), heter_score (scalar),
payload (the raw fitted object).
Discrete features
Ordinal/nominal features are evaluated only at observed
levels — any other xs value raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
centering
|
Union[None, bool, str]
|
|
None
|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the mean effect at |
Source code in effector/global_effect.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
eval_heter(feature, xs, mask=None, rule=None)
The heterogeneity curve h(xs): how much per-instance effects disagree at each x.
h = pdp.eval_heter("hr", xs) # (T,) variance around the mean
band = np.sqrt(h) # std-like band, plot-ready
It's a variance, and it's method-specific (R2)
PDP: variance of centered ICE; DerPDP: of d-ICE slopes; ALE/RHALE: per-bin slope variance as a step function; ShapDP: interpolated per-bin φ variance. Take the square root for a band.
No centering argument — by design
Heterogeneity is invariant to centering; the signature enforces it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the heterogeneity curve h(xs), |
Source code in effector/global_effect.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
grid(feature)
The evaluation grid on which this feature's effect is model-free.
The observed levels for a discrete feature; otherwise
helpers.NOF_INTERNAL_POINTS equally spaced points inside the
feature's axis limits — the cache grid explain evaluates every
reported curve on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in effector/global_effect.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
heter_score(feature, mask=None, rule=None)
One number for a feature's heterogeneity — the scalar find_regions minimizes.
pdp.heter_score("hr") # global
pdp.heter_score("hr", rule="workingday == 0") # within a subregion
In output units (units contract, method_semantics.md): the RMS of
eval_heter over the feature's own (masked) data values
(frequency-weighted over levels for categorical features), bridged by
the feature's dispersion for the derivative-based methods
(ALE/RHALE/DerPDP) so every feature type and every method lands on the
same y-unit scale — "a typical instance's effect deviates from the
mean effect by about this much". eval_heter itself stays a variance
curve in the method's native units.
Pair it with importance
importance measures the mean effect's strength; heter_score
measures the spread around it — same units, mean/spread twins.
High importance + high heterogeneity = the top-right corner of
effector.plot_triage — where find_regions should look.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar, in output units. |
Source code in effector/global_effect.py
755 756 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 | |
payload(feature)
The raw fitted object behind eval/eval_heter — pure numpy, yours to inspect.
p = ale.payload("hr") # e.g. {"limits": ..., "bin_effect": ..., "bin_variance": ...}
Per method: per-bin effects and variances for (RH)ALE and ShapDP, the grid summaries for (d-)PDP. A copy — mutate freely.
Source code in effector/global_effect.py
743 744 745 746 747 748 749 750 751 752 753 | |
importance(feature, mask=None, rule=None)
How much a feature's mean effect moves the prediction (R13).
pdp.importance("temp") # scalar
pdp.importance("temp", rule="workingday == 1") # within a subregion
The dispersion of the mean effect in output units — the μ-twin of
heter_score (which measures per-instance spread on the same scale).
A flat curve scores ~0; a swinging curve scores high. Per method: std
of the mean effect over the (masked) data values (PDP/ALE/RHALE/
ShapDP; for a linear model this is |coefficient| * std(x)),
mean(|derivative|) * std(x) (DerPDP). Comparable across feature
types and, in magnitude, across methods.
No y, ever
effector never sees ground-truth labels — this is a property of the fitted effect, not a loss/permutation importance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar. |
Source code in effector/global_effect.py
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 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
importances(mask=None, rule=None)
The whole importance vector — rank your features in one call.
imp = pdp.importances() # (D,)
order = np.argsort(-np.nan_to_num(imp)) # most important first
NaN means unsupported, not unimportant
Feature types this method cannot explain (e.g. DerPDP on a
nominal feature) return NaN, with one UserWarning naming them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the per-feature importance vector, |
Source code in effector/global_effect.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
find_regions(feature=None, *, features=None, finder='best', candidate_conditioning_features='all')
Search for subregions that resolve a feature's heterogeneity.
part = pdp.find_regions("hr") # one feature -> Partition
part.show() # the tree + level stats
pdp.plot("hr", rule=part.leaves[0].rule) # drill into a leaf
parts = pdp.find_regions(features="heterogeneous") # several -> {name: Partition}
effector.plot_triage(pdp, partitions=parts) # the before/after picture
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect. Don't like a partition? Search again with different finder kwargs; nothing needs resetting.
Model-free
Every candidate split is scored by heter_score(feature, mask)
on the cached local effects — zero model calls, whatever the grid
size. Binning/scope are those the feature was fitted with,
replayed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str, None]
|
index or name of the one feature to partition
(→ |
None
|
features
|
Union[list, str, None]
|
several at once — a list, |
None
|
finder
|
|
'best'
|
|
candidate_conditioning_features
|
features allowed to define splits
( |
'all'
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
with |
Source code in effector/global_effect.py
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 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
select_regions(partitions=None, *, features='heterogeneous', finder='best', candidate_conditioning_features='all', min_r2_gain=0.01)
Greedily select which partitions earn their complexity — the CALM chain.
chain = pdp.select_regions() # search + select in one call
chain.show() # GAM R2, each accepted split, the rejected
chain.final # the last CALM — the regional analysis
chain[0] # the GAM snapshot
find_regions proposes one candidate Partition per feature;
this verb decides across features which of them actually explain
the model: starting from the GAM (all features global), each round
applies the split with the largest explained-variance gain — the
surrogate R² against f̂, measured on top of the splits already
applied — and stops when no remaining split adds at least
min_r2_gain. Every accepted round is a snapshot (CALM) of
increased complexity; the whole chain is the report's ledger.
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect.
One prediction pass
Beyond fit, the only model touch is one f̂(X) pass for the
variance denominator (cached on the effect); the search, the
scoring, and every snapshot's summaries are model-free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partitions
|
Optional[dict]
|
pre-computed candidates — |
None
|
features
|
Union[list, str]
|
which features to search when |
'heterogeneous'
|
finder
|
region finder, as in |
'best'
|
|
candidate_conditioning_features
|
features allowed to define
splits ( |
'all'
|
|
min_r2_gain
|
float
|
smallest explained-variance marginal (fraction of
|
0.01
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
it, with the rejected splits in |
|
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
the method is derivative-scale (no output-scale
surrogate) or |
Source code in effector/global_effect.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
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 | |
plot(feature, heterogeneity=True, centering=True, scale_x=None, scale_y=None, show_avg_output=False, y_limits=None, dy_limits=None, show_only_aggregated=False, show_plot=True, mask=None, rule=None, feature_label=None)
Plot the (RH)ALE effect of feature.
ale.plot("hr") # curve + heterogeneity
ale.plot("hr", rule="workingday == 0") # within a subregion
For a continuous feature the figure has two panels: the accumulated curve on top, the per-bin average local effect (± std) below. Categorical features get one bar per level with std whiskers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature to plot. |
required |
heterogeneity
|
Union[bool, str]
|
|
True
|
centering
|
Union[bool, str]
|
|
True
|
scale_x
|
Optional[dict]
|
|
None
|
scale_y
|
Optional[dict]
|
same, for the y axis. |
None
|
show_avg_output
|
bool
|
draw the model's average output as a horizontal line. |
False
|
y_limits
|
Optional[List]
|
|
None
|
dy_limits
|
Optional[List]
|
|
None
|
show_only_aggregated
|
bool
|
draw only the accumulated curve, without the bottom panel. |
False
|
show_plot
|
bool
|
if |
True
|
mask
|
Optional[ndarray]
|
boolean |
None
|
rule
|
sugar over |
None
|
|
feature_label
|
Optional[str]
|
display title for the figure (e.g. a regional node's label with its rule); defaults to the feature name. The x-axis always keeps the plain feature name. |
None
|
Source code in effector/global_effect_ale.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 460 461 462 463 464 465 466 467 468 469 | |
effector.global_effect_pdp.PDP(data, model, *, axis_limits=None, nof_instances=10000, schema=None, random_state=21)
Bases: PDPBase
Partial Dependence Plot: the average prediction as one feature varies.
pdp = effector.PDP(X, model)
pdp.plot("hr") # mean effect + ICE curves
y = pdp.eval("hr", np.linspace(0, 23, 100)) # (100,) mean effect
Every instance is forced to each position \(x_s\) and the predictions are averaged:
Each instance's own curve \(ICE^i(x_s) = f(x_s, \mathbf{x}_c^i)\) tells the individual story; the heterogeneity is the variance of the ICE curves around the mean (each ICE centered on its own mean first).
Correlated features
PDP averages over the marginal distribution: with strongly correlated
features it queries the model far off the data manifold. Prefer
effector.ALE or effector.RHALE there.
Build a PDP explainer. No model calls happen here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
the design matrix, shape |
required |
model
|
Callable
|
the black-box model — a |
required |
axis_limits
|
Optional[ndarray]
|
per-feature plot limits, shape |
None
|
nof_instances
|
Union[int, str]
|
max instances kept (default |
10000
|
schema
|
Optional[Union[Schema, dict]]
|
input metadata — an |
None
|
random_state
|
Optional[int]
|
seed for every internal random step (default |
21
|
Methods:
| Name | Description |
|---|---|
fit |
Declare per-feature defaults and warm the caches. |
eval |
The mean effect of a feature at positions |
eval_heter |
The heterogeneity curve h(xs): how much per-instance effects disagree at each x. |
grid |
The evaluation grid on which this feature's effect is model-free. |
heter_score |
One number for a feature's heterogeneity — the scalar |
payload |
The raw fitted object behind |
importance |
How much a feature's mean effect moves the prediction (R13). |
importances |
The whole importance vector — rank your features in one call. |
find_regions |
Search for subregions that resolve a feature's heterogeneity. |
select_regions |
Greedily select which partitions earn their complexity — the CALM chain. |
explain |
The one-liner on this engine — |
plot |
Plot the PDP of |
Source code in effector/global_effect_pdp.py
482 483 484 485 486 487 488 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 | |
fit(features='all', *, centering=False, use_vectorized=True)
Declare per-feature defaults and warm the caches.
pdp.fit("hr", centering="zero_integral")
fit is optional
eval, plot, heter_score compute what they need lazily with
these defaults; fit declares the config once and pays the model
cost upfront.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Union[int, str, list]
|
feature(s) to fit — index, name, list, or |
'all'
|
centering
|
Union[bool, str]
|
default centering for this feature's queries —
|
False
|
use_vectorized
|
bool
|
vectorize the ICE computation — faster, but
builds a |
True
|
Source code in effector/global_effect_pdp.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
eval(feature, xs, centering=None, mask=None, rule=None)
The mean effect of a feature at positions xs.
xs = np.linspace(0, 24, 100)
y = pdp.eval("hr", xs) # (100,) mean effect
y_wd = pdp.eval("hr", xs, rule="workingday == 0") # same, on a subregion
One array, one type (R1)
eval always returns the mean effect only. The spread around it
has its own ladder: eval_heter (curve), heter_score (scalar),
payload (the raw fitted object).
Discrete features
Ordinal/nominal features are evaluated only at observed
levels — any other xs value raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
centering
|
Union[None, bool, str]
|
|
None
|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the mean effect at |
Source code in effector/global_effect.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
eval_heter(feature, xs, mask=None, rule=None)
The heterogeneity curve h(xs): how much per-instance effects disagree at each x.
h = pdp.eval_heter("hr", xs) # (T,) variance around the mean
band = np.sqrt(h) # std-like band, plot-ready
It's a variance, and it's method-specific (R2)
PDP: variance of centered ICE; DerPDP: of d-ICE slopes; ALE/RHALE: per-bin slope variance as a step function; ShapDP: interpolated per-bin φ variance. Take the square root for a band.
No centering argument — by design
Heterogeneity is invariant to centering; the signature enforces it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the heterogeneity curve h(xs), |
Source code in effector/global_effect.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
grid(feature)
The evaluation grid on which this feature's effect is model-free.
The observed levels for a discrete feature; otherwise
helpers.NOF_INTERNAL_POINTS equally spaced points inside the
feature's axis limits — the cache grid explain evaluates every
reported curve on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in effector/global_effect.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
heter_score(feature, mask=None, rule=None)
One number for a feature's heterogeneity — the scalar find_regions minimizes.
pdp.heter_score("hr") # global
pdp.heter_score("hr", rule="workingday == 0") # within a subregion
In output units (units contract, method_semantics.md): the RMS of
eval_heter over the feature's own (masked) data values
(frequency-weighted over levels for categorical features), bridged by
the feature's dispersion for the derivative-based methods
(ALE/RHALE/DerPDP) so every feature type and every method lands on the
same y-unit scale — "a typical instance's effect deviates from the
mean effect by about this much". eval_heter itself stays a variance
curve in the method's native units.
Pair it with importance
importance measures the mean effect's strength; heter_score
measures the spread around it — same units, mean/spread twins.
High importance + high heterogeneity = the top-right corner of
effector.plot_triage — where find_regions should look.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar, in output units. |
Source code in effector/global_effect.py
755 756 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 | |
payload(feature)
The raw fitted object behind eval/eval_heter — pure numpy, yours to inspect.
p = ale.payload("hr") # e.g. {"limits": ..., "bin_effect": ..., "bin_variance": ...}
Per method: per-bin effects and variances for (RH)ALE and ShapDP, the grid summaries for (d-)PDP. A copy — mutate freely.
Source code in effector/global_effect.py
743 744 745 746 747 748 749 750 751 752 753 | |
importance(feature, mask=None, rule=None)
How much a feature's mean effect moves the prediction (R13).
pdp.importance("temp") # scalar
pdp.importance("temp", rule="workingday == 1") # within a subregion
The dispersion of the mean effect in output units — the μ-twin of
heter_score (which measures per-instance spread on the same scale).
A flat curve scores ~0; a swinging curve scores high. Per method: std
of the mean effect over the (masked) data values (PDP/ALE/RHALE/
ShapDP; for a linear model this is |coefficient| * std(x)),
mean(|derivative|) * std(x) (DerPDP). Comparable across feature
types and, in magnitude, across methods.
No y, ever
effector never sees ground-truth labels — this is a property of the fitted effect, not a loss/permutation importance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar. |
Source code in effector/global_effect.py
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 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
importances(mask=None, rule=None)
The whole importance vector — rank your features in one call.
imp = pdp.importances() # (D,)
order = np.argsort(-np.nan_to_num(imp)) # most important first
NaN means unsupported, not unimportant
Feature types this method cannot explain (e.g. DerPDP on a
nominal feature) return NaN, with one UserWarning naming them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the per-feature importance vector, |
Source code in effector/global_effect.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
find_regions(feature=None, *, features=None, finder='best', candidate_conditioning_features='all')
Search for subregions that resolve a feature's heterogeneity.
part = pdp.find_regions("hr") # one feature -> Partition
part.show() # the tree + level stats
pdp.plot("hr", rule=part.leaves[0].rule) # drill into a leaf
parts = pdp.find_regions(features="heterogeneous") # several -> {name: Partition}
effector.plot_triage(pdp, partitions=parts) # the before/after picture
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect. Don't like a partition? Search again with different finder kwargs; nothing needs resetting.
Model-free
Every candidate split is scored by heter_score(feature, mask)
on the cached local effects — zero model calls, whatever the grid
size. Binning/scope are those the feature was fitted with,
replayed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str, None]
|
index or name of the one feature to partition
(→ |
None
|
features
|
Union[list, str, None]
|
several at once — a list, |
None
|
finder
|
|
'best'
|
|
candidate_conditioning_features
|
features allowed to define splits
( |
'all'
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
with |
Source code in effector/global_effect.py
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 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
select_regions(partitions=None, *, features='heterogeneous', finder='best', candidate_conditioning_features='all', min_r2_gain=0.01)
Greedily select which partitions earn their complexity — the CALM chain.
chain = pdp.select_regions() # search + select in one call
chain.show() # GAM R2, each accepted split, the rejected
chain.final # the last CALM — the regional analysis
chain[0] # the GAM snapshot
find_regions proposes one candidate Partition per feature;
this verb decides across features which of them actually explain
the model: starting from the GAM (all features global), each round
applies the split with the largest explained-variance gain — the
surrogate R² against f̂, measured on top of the splits already
applied — and stops when no remaining split adds at least
min_r2_gain. Every accepted round is a snapshot (CALM) of
increased complexity; the whole chain is the report's ledger.
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect.
One prediction pass
Beyond fit, the only model touch is one f̂(X) pass for the
variance denominator (cached on the effect); the search, the
scoring, and every snapshot's summaries are model-free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partitions
|
Optional[dict]
|
pre-computed candidates — |
None
|
features
|
Union[list, str]
|
which features to search when |
'heterogeneous'
|
finder
|
region finder, as in |
'best'
|
|
candidate_conditioning_features
|
features allowed to define
splits ( |
'all'
|
|
min_r2_gain
|
float
|
smallest explained-variance marginal (fraction of
|
0.01
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
it, with the rejected splits in |
|
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
the method is derivative-scale (no output-scale
surrogate) or |
Source code in effector/global_effect.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
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 | |
plot(feature, heterogeneity='ice', centering=True, nof_points=100, scale_x=None, scale_y=None, nof_ice=100, show_avg_output=False, y_limits=None, use_vectorized=True, show_plot=True, mask=None, rule=None, feature_label=None)
Plot the PDP of feature, by default with the ICE cloud.
pdp.plot("hr") # mean effect + ICE curves
pdp.plot("hr", heterogeneity="std") # mean ± std band
pdp.plot("hr", rule="workingday == 0") # PDP within a subregion
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature to plot. |
required |
heterogeneity
|
Union[bool, str]
|
what to draw around the mean effect:
|
'ice'
|
centering
|
Union[bool, str]
|
|
True
|
nof_points
|
int
|
grid size of the x axis (default |
100
|
scale_x
|
Optional[dict]
|
|
None
|
scale_y
|
Optional[dict]
|
same, for the y axis. |
None
|
nof_ice
|
Union[int, str]
|
how many ICE curves to draw (default |
100
|
show_avg_output
|
bool
|
draw the model's average output as a horizontal line. |
False
|
y_limits
|
Optional[List]
|
|
None
|
use_vectorized
|
bool
|
vectorized ICE computation (faster, more memory). |
True
|
show_plot
|
bool
|
if |
True
|
mask
|
Optional[ndarray]
|
boolean |
None
|
rule
|
sugar over |
None
|
|
feature_label
|
Optional[str]
|
display title for the figure (e.g. a regional node's label with its rule); defaults to the feature name. The x-axis always keeps the plain feature name. |
None
|
Source code in effector/global_effect_pdp.py
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 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
effector.global_effect_pdp.DerPDP(data, model, model_jac=None, *, axis_limits=None, nof_instances=10000, schema=None, random_state=21)
Bases: PDPBase
Derivative-PDP: the model's average derivative as one feature varies.
dpdp = effector.DerPDP(X, model, model_jac)
dpdp.plot("hr") # y axis in derivative units
Flat at zero means no effect; constant non-zero means a linear effect. The heterogeneity is the variance of the d-ICE curves.
Derivative units
The y axis is in \(\partial y / \partial x_s\) units, not output
units. Without model_jac, derivatives fall back to slower, less
exact numerical differentiation.
On a discrete axis the derivative becomes the finite difference: ordinal features show one bar per adjacent-level transition (the per-instance difference of the plain ICE values at the two levels — the jacobian is never used there); nominal features additionally get order-free scalars from all level pairs (method_semantics.md).
Build a d-PDP explainer. No model calls happen here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
the design matrix, shape |
required |
model
|
Callable
|
the black-box model — a |
required |
model_jac
|
Optional[Callable]
|
the model Jacobian — a |
None
|
axis_limits
|
Optional[ndarray]
|
per-feature plot limits, shape |
None
|
nof_instances
|
Union[int, str]
|
max instances kept (default |
10000
|
schema
|
Optional[Union[Schema, dict]]
|
input metadata — an |
None
|
random_state
|
Optional[int]
|
seed for every internal random step (default |
21
|
Methods:
| Name | Description |
|---|---|
fit |
Declare per-feature defaults and warm the caches. |
eval |
The mean effect of a feature at positions |
eval_heter |
The heterogeneity curve h(xs): how much per-instance effects disagree at each x. |
grid |
The evaluation grid on which this feature's effect is model-free. |
heter_score |
One number for a feature's heterogeneity — the scalar |
payload |
The raw fitted object behind |
importance |
How much a feature's mean effect moves the prediction (R13). |
importances |
The whole importance vector — rank your features in one call. |
find_regions |
Search for subregions that resolve a feature's heterogeneity. |
select_regions |
Greedily select which partitions earn their complexity — the CALM chain. |
explain |
The one-liner on this engine — |
plot |
Plot the d-PDP of |
Source code in effector/global_effect_pdp.py
750 751 752 753 754 755 756 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 | |
fit(features='all', *, centering=False, use_vectorized=True)
Declare per-feature defaults and warm the caches.
pdp.fit("hr", centering="zero_integral")
fit is optional
eval, plot, heter_score compute what they need lazily with
these defaults; fit declares the config once and pays the model
cost upfront.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Union[int, str, list]
|
feature(s) to fit — index, name, list, or |
'all'
|
centering
|
Union[bool, str]
|
default centering for this feature's queries —
|
False
|
use_vectorized
|
bool
|
vectorize the ICE computation — faster, but
builds a |
True
|
Source code in effector/global_effect_pdp.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
eval(feature, xs, centering=None, mask=None, rule=None)
The mean effect of a feature at positions xs.
xs = np.linspace(0, 24, 100)
y = pdp.eval("hr", xs) # (100,) mean effect
y_wd = pdp.eval("hr", xs, rule="workingday == 0") # same, on a subregion
One array, one type (R1)
eval always returns the mean effect only. The spread around it
has its own ladder: eval_heter (curve), heter_score (scalar),
payload (the raw fitted object).
Discrete features
Ordinal/nominal features are evaluated only at observed
levels — any other xs value raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
centering
|
Union[None, bool, str]
|
|
None
|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the mean effect at |
Source code in effector/global_effect.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
eval_heter(feature, xs, mask=None, rule=None)
The heterogeneity curve h(xs): how much per-instance effects disagree at each x.
h = pdp.eval_heter("hr", xs) # (T,) variance around the mean
band = np.sqrt(h) # std-like band, plot-ready
It's a variance, and it's method-specific (R2)
PDP: variance of centered ICE; DerPDP: of d-ICE slopes; ALE/RHALE: per-bin slope variance as a step function; ShapDP: interpolated per-bin φ variance. Take the square root for a band.
No centering argument — by design
Heterogeneity is invariant to centering; the signature enforces it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the heterogeneity curve h(xs), |
Source code in effector/global_effect.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
grid(feature)
The evaluation grid on which this feature's effect is model-free.
The observed levels for a discrete feature; otherwise
helpers.NOF_INTERNAL_POINTS equally spaced points inside the
feature's axis limits — the cache grid explain evaluates every
reported curve on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in effector/global_effect.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
heter_score(feature, mask=None, rule=None)
One number for a feature's heterogeneity — the scalar find_regions minimizes.
pdp.heter_score("hr") # global
pdp.heter_score("hr", rule="workingday == 0") # within a subregion
In output units (units contract, method_semantics.md): the RMS of
eval_heter over the feature's own (masked) data values
(frequency-weighted over levels for categorical features), bridged by
the feature's dispersion for the derivative-based methods
(ALE/RHALE/DerPDP) so every feature type and every method lands on the
same y-unit scale — "a typical instance's effect deviates from the
mean effect by about this much". eval_heter itself stays a variance
curve in the method's native units.
Pair it with importance
importance measures the mean effect's strength; heter_score
measures the spread around it — same units, mean/spread twins.
High importance + high heterogeneity = the top-right corner of
effector.plot_triage — where find_regions should look.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar, in output units. |
Source code in effector/global_effect.py
755 756 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 | |
payload(feature)
The raw fitted object behind eval/eval_heter — pure numpy, yours to inspect.
p = ale.payload("hr") # e.g. {"limits": ..., "bin_effect": ..., "bin_variance": ...}
Per method: per-bin effects and variances for (RH)ALE and ShapDP, the grid summaries for (d-)PDP. A copy — mutate freely.
Source code in effector/global_effect.py
743 744 745 746 747 748 749 750 751 752 753 | |
importance(feature, mask=None, rule=None)
How much a feature's mean effect moves the prediction (R13).
pdp.importance("temp") # scalar
pdp.importance("temp", rule="workingday == 1") # within a subregion
The dispersion of the mean effect in output units — the μ-twin of
heter_score (which measures per-instance spread on the same scale).
A flat curve scores ~0; a swinging curve scores high. Per method: std
of the mean effect over the (masked) data values (PDP/ALE/RHALE/
ShapDP; for a linear model this is |coefficient| * std(x)),
mean(|derivative|) * std(x) (DerPDP). Comparable across feature
types and, in magnitude, across methods.
No y, ever
effector never sees ground-truth labels — this is a property of the fitted effect, not a loss/permutation importance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar. |
Source code in effector/global_effect.py
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 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
importances(mask=None, rule=None)
The whole importance vector — rank your features in one call.
imp = pdp.importances() # (D,)
order = np.argsort(-np.nan_to_num(imp)) # most important first
NaN means unsupported, not unimportant
Feature types this method cannot explain (e.g. DerPDP on a
nominal feature) return NaN, with one UserWarning naming them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the per-feature importance vector, |
Source code in effector/global_effect.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
find_regions(feature=None, *, features=None, finder='best', candidate_conditioning_features='all')
Search for subregions that resolve a feature's heterogeneity.
part = pdp.find_regions("hr") # one feature -> Partition
part.show() # the tree + level stats
pdp.plot("hr", rule=part.leaves[0].rule) # drill into a leaf
parts = pdp.find_regions(features="heterogeneous") # several -> {name: Partition}
effector.plot_triage(pdp, partitions=parts) # the before/after picture
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect. Don't like a partition? Search again with different finder kwargs; nothing needs resetting.
Model-free
Every candidate split is scored by heter_score(feature, mask)
on the cached local effects — zero model calls, whatever the grid
size. Binning/scope are those the feature was fitted with,
replayed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str, None]
|
index or name of the one feature to partition
(→ |
None
|
features
|
Union[list, str, None]
|
several at once — a list, |
None
|
finder
|
|
'best'
|
|
candidate_conditioning_features
|
features allowed to define splits
( |
'all'
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
with |
Source code in effector/global_effect.py
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 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
select_regions(partitions=None, *, features='heterogeneous', finder='best', candidate_conditioning_features='all', min_r2_gain=0.01)
Greedily select which partitions earn their complexity — the CALM chain.
chain = pdp.select_regions() # search + select in one call
chain.show() # GAM R2, each accepted split, the rejected
chain.final # the last CALM — the regional analysis
chain[0] # the GAM snapshot
find_regions proposes one candidate Partition per feature;
this verb decides across features which of them actually explain
the model: starting from the GAM (all features global), each round
applies the split with the largest explained-variance gain — the
surrogate R² against f̂, measured on top of the splits already
applied — and stops when no remaining split adds at least
min_r2_gain. Every accepted round is a snapshot (CALM) of
increased complexity; the whole chain is the report's ledger.
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect.
One prediction pass
Beyond fit, the only model touch is one f̂(X) pass for the
variance denominator (cached on the effect); the search, the
scoring, and every snapshot's summaries are model-free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partitions
|
Optional[dict]
|
pre-computed candidates — |
None
|
features
|
Union[list, str]
|
which features to search when |
'heterogeneous'
|
finder
|
region finder, as in |
'best'
|
|
candidate_conditioning_features
|
features allowed to define
splits ( |
'all'
|
|
min_r2_gain
|
float
|
smallest explained-variance marginal (fraction of
|
0.01
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
it, with the rejected splits in |
|
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
the method is derivative-scale (no output-scale
surrogate) or |
Source code in effector/global_effect.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
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 | |
plot(feature, heterogeneity='ice', centering=False, nof_points=100, scale_x=None, scale_y=None, nof_ice=100, show_avg_output=False, y_limits=None, use_vectorized=True, show_plot=True, mask=None, rule=None, feature_label=None)
Plot the d-PDP of feature, by default with the d-ICE cloud.
dpdp.plot("hr") # mean derivative + d-ICE
dpdp.plot("hr", heterogeneity="std") # mean ± std band
Derivative units
The y axis (and y_limits) is in derivative units
d(target)/d(feature), not output units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature to plot. |
required |
heterogeneity
|
Union[bool, str]
|
what to draw around the mean derivative:
|
'ice'
|
centering
|
Union[bool, str]
|
|
False
|
nof_points
|
int
|
grid size of the x axis (default |
100
|
scale_x
|
Optional[dict]
|
|
None
|
scale_y
|
Optional[dict]
|
same, for the y axis. |
None
|
nof_ice
|
Union[int, str]
|
how many d-ICE curves to draw (default |
100
|
show_avg_output
|
bool
|
draw the model's average output as a horizontal line. |
False
|
y_limits
|
Optional[List]
|
|
None
|
use_vectorized
|
bool
|
vectorized ICE computation (faster, more memory). |
True
|
show_plot
|
bool
|
if |
True
|
mask
|
Optional[ndarray]
|
boolean |
None
|
rule
|
sugar over |
None
|
|
feature_label
|
Optional[str]
|
display title for the figure (e.g. a regional node's label with its rule); defaults to the feature name. The x-axis always keeps the plain feature name. |
None
|
Source code in effector/global_effect_pdp.py
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 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
effector.global_effect_shap.ShapDP(data, model, *, axis_limits=None, nof_instances=1000, schema=None, random_state=21, shap_values=None, backend='shap', budget=512, shap_explainer_kwargs=None, shap_explanation_kwargs=None)
Bases: GlobalEffectBase
SHAP Dependence Plot: per-instance SHAP values against the feature value, with a curve fitted through them.
sdp = effector.ShapDP(X, model, nof_instances=500)
sdp.plot("hr") # SHAP scatter + fitted curve
The curve \(\hat{f}^{SDP}_j(x_j)\) is fit to the SHAP cloud \(\{(x_j^i, \hat{\phi}_j(x_j^i))\}_{i=1}^N\): the axis is binned and the per-bin SHAP means are interpolated piecewise-linearly. The heterogeneity is the per-bin variance of the SHAP values.
The slow one
SHAP values are expensive — cost grows with instances and features.
Keep nof_instances modest (default 1_000) and raise budget
only if the estimate looks noisy. Requires the shap or shapiq
package: pip install effector[shap].
Build a ShapDP explainer. SHAP values are computed lazily, on the first query.
Definition
The value of a coalition \(S\) of features is estimated as: $$ \hat{v}(S) = {1 \over N} \sum_{i=1}^N [f(\mathbf{x}_S \cup \mathbf{x}_C^i) - f(\mathbf{x}^i)] $$ i.e. the average change in the output when the features in \(S\) are set to \(\mathbf{x}_S\) and the rest are left as observed.
The contribution of feature \(j\) added to a coalition \(S\) is: $$ \hat{\Delta}_{S, j} = \hat{v}(S \cup {j}) - \hat{v}(S) $$
The SHAP value of feature \(j\) at value \(x_j\) averages this contribution over all coalitions, weighted so that every coalition size counts equally: $$ \hat{\phi}j(x_j) = \sum{S \subseteq {1, \dots, D} \setminus {j}} w_{S, j} \hat{\Delta}_{S, j} $$
The SHAP-DP curve \(\hat{f}^{SDP}_j(x_j)\) is fit to \(\{(x_j^i, \hat{\phi}_j(x_j^i))\}_{i=1}^N\): the axis is split into bins and the per-bin SHAP means are interpolated piecewise-linearly (linear extrapolation beyond the outer bin centers). See the original paper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
the design matrix, shape |
required |
model
|
Callable
|
the black-box model — a |
required |
axis_limits
|
Optional[ndarray]
|
per-feature plot limits, shape |
None
|
nof_instances
|
Union[int, str]
|
max instances used for SHAP estimation (default
|
1000
|
schema
|
Optional[Union[Schema, dict]]
|
input metadata — an |
None
|
random_state
|
Optional[int]
|
seed for every internal random step, including the
shap/shapiq explainer (default |
21
|
shap_values
|
Optional[ndarray]
|
precomputed SHAP values, shape |
None
|
backend
|
str
|
|
'shap'
|
budget
|
int
|
max model evaluations per instance for the SHAP
approximation (default |
512
|
shap_explainer_kwargs
|
Optional[dict]
|
extra kwargs for |
None
|
shap_explanation_kwargs
|
Optional[dict]
|
extra kwargs for the explanation call of the chosen backend (same code path as above). |
None
|
Methods:
| Name | Description |
|---|---|
fit |
Declare per-feature defaults and warm the caches. |
eval |
The mean effect of a feature at positions |
eval_heter |
The heterogeneity curve h(xs): how much per-instance effects disagree at each x. |
grid |
The evaluation grid on which this feature's effect is model-free. |
heter_score |
One number for a feature's heterogeneity — the scalar |
payload |
The raw fitted object behind |
importance |
How much a feature's mean effect moves the prediction (R13). |
importances |
The whole importance vector — rank your features in one call. |
find_regions |
Search for subregions that resolve a feature's heterogeneity. |
select_regions |
Greedily select which partitions earn their complexity — the CALM chain. |
explain |
The one-liner on this engine — |
plot |
Plot the SHAP-DP of |
Source code in effector/global_effect_shap.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
fit(features='all', *, centering=True, binning_method='dp', binning_scope='global')
Declare per-feature defaults and warm the caches.
sdp.fit("hr", binning_method="dp")
fit is optional — but it pays the SHAP bill
Any query computes what it needs lazily with these defaults; the
first one triggers the (expensive) SHAP computation for the whole
(N, D) table. fit lets you pay that cost upfront.
The curve is the piecewise-linear interpolation of the per-bin SHAP means (linear extrapolation beyond the outer bin centers); the heterogeneity is the same interpolation of the per-bin SHAP variances, clamped at zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Union[int, str, List]
|
feature(s) to fit — index, name, list, or |
'all'
|
centering
|
Union[bool, str]
|
default centering for this feature's queries —
|
True
|
binning_method
|
Union[str, DynamicProgramming, Agglomerative, Quantile, Fixed]
|
how the axis is split before fitting the curve:
For custom parameters pass an instance from
|
'dp'
|
binning_scope
|
str
|
the x-range the binner covers when a masked
summary re-bins a subregion (
Recorded at fit and replayed by every masked call. Ignored when no mask is involved. |
'global'
|
Source code in effector/global_effect_shap.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
eval(feature, xs, centering=None, mask=None, rule=None)
The mean effect of a feature at positions xs.
xs = np.linspace(0, 24, 100)
y = pdp.eval("hr", xs) # (100,) mean effect
y_wd = pdp.eval("hr", xs, rule="workingday == 0") # same, on a subregion
One array, one type (R1)
eval always returns the mean effect only. The spread around it
has its own ladder: eval_heter (curve), heter_score (scalar),
payload (the raw fitted object).
Discrete features
Ordinal/nominal features are evaluated only at observed
levels — any other xs value raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
centering
|
Union[None, bool, str]
|
|
None
|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the mean effect at |
Source code in effector/global_effect.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
eval_heter(feature, xs, mask=None, rule=None)
The heterogeneity curve h(xs): how much per-instance effects disagree at each x.
h = pdp.eval_heter("hr", xs) # (T,) variance around the mean
band = np.sqrt(h) # std-like band, plot-ready
It's a variance, and it's method-specific (R2)
PDP: variance of centered ICE; DerPDP: of d-ICE slopes; ALE/RHALE: per-bin slope variance as a step function; ShapDP: interpolated per-bin φ variance. Take the square root for a band.
No centering argument — by design
Heterogeneity is invariant to centering; the signature enforces it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
xs
|
ndarray
|
where to evaluate, |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the heterogeneity curve h(xs), |
Source code in effector/global_effect.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
grid(feature)
The evaluation grid on which this feature's effect is model-free.
The observed levels for a discrete feature; otherwise
helpers.NOF_INTERNAL_POINTS equally spaced points inside the
feature's axis limits — the cache grid explain evaluates every
reported curve on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in effector/global_effect.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
heter_score(feature, mask=None, rule=None)
One number for a feature's heterogeneity — the scalar find_regions minimizes.
pdp.heter_score("hr") # global
pdp.heter_score("hr", rule="workingday == 0") # within a subregion
In output units (units contract, method_semantics.md): the RMS of
eval_heter over the feature's own (masked) data values
(frequency-weighted over levels for categorical features), bridged by
the feature's dispersion for the derivative-based methods
(ALE/RHALE/DerPDP) so every feature type and every method lands on the
same y-unit scale — "a typical instance's effect deviates from the
mean effect by about this much". eval_heter itself stays a variance
curve in the method's native units.
Pair it with importance
importance measures the mean effect's strength; heter_score
measures the spread around it — same units, mean/spread twins.
High importance + high heterogeneity = the top-right corner of
effector.plot_triage — where find_regions should look.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar, in output units. |
Source code in effector/global_effect.py
755 756 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 | |
payload(feature)
The raw fitted object behind eval/eval_heter — pure numpy, yours to inspect.
p = ale.payload("hr") # e.g. {"limits": ..., "bin_effect": ..., "bin_variance": ...}
Per method: per-bin effects and variances for (RH)ALE and ShapDP, the grid summaries for (d-)PDP. A copy — mutate freely.
Source code in effector/global_effect.py
743 744 745 746 747 748 749 750 751 752 753 | |
importance(feature, mask=None, rule=None)
How much a feature's mean effect moves the prediction (R13).
pdp.importance("temp") # scalar
pdp.importance("temp", rule="workingday == 1") # within a subregion
The dispersion of the mean effect in output units — the μ-twin of
heter_score (which measures per-instance spread on the same scale).
A flat curve scores ~0; a swinging curve scores high. Per method: std
of the mean effect over the (masked) data values (PDP/ALE/RHALE/
ShapDP; for a linear model this is |coefficient| * std(x)),
mean(|derivative|) * std(x) (DerPDP). Comparable across feature
types and, in magnitude, across methods.
No y, ever
effector never sees ground-truth labels — this is a property of the fitted effect, not a loss/permutation importance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature of interest. |
required |
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
float
|
a non-negative scalar. |
Source code in effector/global_effect.py
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 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
importances(mask=None, rule=None)
The whole importance vector — rank your features in one call.
imp = pdp.importances() # (D,)
order = np.argsort(-np.nan_to_num(imp)) # most important first
NaN means unsupported, not unimportant
Feature types this method cannot explain (e.g. DerPDP on a
nominal feature) return NaN, with one UserWarning naming them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Optional[ndarray]
|
optional boolean |
None
|
rule
|
Union[None, str, Rule]
|
sugar over |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the per-feature importance vector, |
Source code in effector/global_effect.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
find_regions(feature=None, *, features=None, finder='best', candidate_conditioning_features='all')
Search for subregions that resolve a feature's heterogeneity.
part = pdp.find_regions("hr") # one feature -> Partition
part.show() # the tree + level stats
pdp.plot("hr", rule=part.leaves[0].rule) # drill into a leaf
parts = pdp.find_regions(features="heterogeneous") # several -> {name: Partition}
effector.plot_triage(pdp, partitions=parts) # the before/after picture
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect. Don't like a partition? Search again with different finder kwargs; nothing needs resetting.
Model-free
Every candidate split is scored by heter_score(feature, mask)
on the cached local effects — zero model calls, whatever the grid
size. Binning/scope are those the feature was fitted with,
replayed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str, None]
|
index or name of the one feature to partition
(→ |
None
|
features
|
Union[list, str, None]
|
several at once — a list, |
None
|
finder
|
|
'best'
|
|
candidate_conditioning_features
|
features allowed to define splits
( |
'all'
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
with |
Source code in effector/global_effect.py
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 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
select_regions(partitions=None, *, features='heterogeneous', finder='best', candidate_conditioning_features='all', min_r2_gain=0.01)
Greedily select which partitions earn their complexity — the CALM chain.
chain = pdp.select_regions() # search + select in one call
chain.show() # GAM R2, each accepted split, the rejected
chain.final # the last CALM — the regional analysis
chain[0] # the GAM snapshot
find_regions proposes one candidate Partition per feature;
this verb decides across features which of them actually explain
the model: starting from the GAM (all features global), each round
applies the split with the largest explained-variance gain — the
surrogate R² against f̂, measured on top of the splits already
applied — and stops when no remaining split adds at least
min_r2_gain. Every accepted round is a snapshot (CALM) of
increased complexity; the whole chain is the report's ledger.
A query, not a mutation (R12)
The result is a value — nothing is stored on the effect.
One prediction pass
Beyond fit, the only model touch is one f̂(X) pass for the
variance denominator (cached on the effect); the search, the
scoring, and every snapshot's summaries are model-free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partitions
|
Optional[dict]
|
pre-computed candidates — |
None
|
features
|
Union[list, str]
|
which features to search when |
'heterogeneous'
|
finder
|
region finder, as in |
'best'
|
|
candidate_conditioning_features
|
features allowed to define
splits ( |
'all'
|
|
min_r2_gain
|
float
|
smallest explained-variance marginal (fraction of
|
0.01
|
Returns:
| Type | Description |
|---|---|
|
a |
|
|
it, with the rejected splits in |
|
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
the method is derivative-scale (no output-scale
surrogate) or |
Source code in effector/global_effect.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
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 | |
plot(feature, heterogeneity='shap_values', centering=True, nof_points=100, scale_x=None, scale_y=None, nof_shap_values=100, show_avg_output=False, y_limits=None, only_shap_values=False, show_plot=True, mask=None, rule=None, feature_label=None)
Plot the SHAP-DP of feature, by default with the SHAP scatter.
sdp.plot("hr") # fitted curve + SHAP scatter
sdp.plot("hr", heterogeneity="std") # curve ± std band
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Union[int, str]
|
index or name of the feature to plot. |
required |
heterogeneity
|
Union[bool, str]
|
what to draw around the fitted curve:
|
'shap_values'
|
centering
|
Union[bool, str]
|
|
True
|
nof_points
|
int
|
grid size of the x axis (default |
100
|
scale_x
|
Optional[dict]
|
|
None
|
scale_y
|
Optional[dict]
|
same, for the y axis. |
None
|
nof_shap_values
|
Union[int, str]
|
how many SHAP values to scatter (default
|
100
|
show_avg_output
|
bool
|
draw the model's average output as a horizontal line. |
False
|
y_limits
|
Optional[List]
|
|
None
|
only_shap_values
|
bool
|
scatter the SHAP values without the fitted curve. |
False
|
show_plot
|
bool
|
if |
True
|
mask
|
Optional[ndarray]
|
boolean |
None
|
rule
|
sugar over |
None
|
|
feature_label
|
Optional[str]
|
display title for the figure (e.g. a regional node's label with its rule); defaults to the feature name. The x-axis always keeps the plain feature name. |
None
|
Source code in effector/global_effect_shap.py
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 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 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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |




