Effector

effector
an eXplainable AI package for tabular data. It:
📖 Documentation | 🔍 Intro to global and regional effects | 🔧 API | 🏗 Examples
Installation
Effector requires Python 3.10+:
pip install effector
Dependencies: numpy
, scipy
, matplotlib
, tqdm
, shap
.
Quickstart
Train an ML model
import effector
import keras
import numpy as np
import tensorflow as tf
np.random.seed(42)
tf.random.set_seed(42)
bike_sharing = effector.datasets.BikeSharing(pcg_train=0.8)
X_train, Y_train = bike_sharing.x_train, bike_sharing.y_train
X_test, Y_test = bike_sharing.x_test, bike_sharing.y_test
model = keras.Sequential([
keras.layers.Dense(1024, activation="relu"),
keras.layers.Dense(512, activation="relu"),
keras.layers.Dense(256, activation="relu"),
keras.layers.Dense(1)
])
model.compile(optimizer="adam", loss="mse", metrics=["mae", keras.metrics.RootMeanSquaredError()])
model.fit(X_train, Y_train, batch_size=512, epochs=20, verbose=1)
model.evaluate(X_test, Y_test, verbose=1)
Wrap it in a callable
def predict(x):
return model(x).numpy().squeeze()
Explain it with global effect plots
pdp = effector.PDP(
X_test,
predict,
feature_names=bike_sharing.feature_names,
target_name=bike_sharing.target_name
)
pdp.plot(
feature=3,
nof_ice=200,
scale_x={"mean": bike_sharing.x_test_mu[3], "std": bike_sharing.x_test_std[3]},
scale_y={"mean": bike_sharing.y_test_mu, "std": bike_sharing.y_test_std},
centering=True,
show_avg_output=True,
y_limits=[-200, 1000]
)

Explain it with regional effect plots
r_pdp = effector.RegionalPDP(
X_test,
predict,
feature_names=bike_sharing.feature_names,
target_name=bike_sharing.target_name
)
r_pdp.summary(
features=3,
scale_x_list=[
{"mean": bike_sharing.x_test_mu[i], "std": bike_sharing.x_test_std[i]}
for i in range(X_test.shape[1])
]
)
Feature 3 - Full partition tree:
🌳 Full Tree Structure:
───────────────────────
hr 🔹 [id: 0 | heter: 0.43 | inst: 3476 | w: 1.00]
workingday = 0.00 🔹 [id: 1 | heter: 0.36 | inst: 1129 | w: 0.32]
temp ≤ 6.50 🔹 [id: 3 | heter: 0.17 | inst: 568 | w: 0.16]
temp > 6.50 🔹 [id: 4 | heter: 0.21 | inst: 561 | w: 0.16]
workingday ≠ 0.00 🔹 [id: 2 | heter: 0.28 | inst: 2347 | w: 0.68]
temp ≤ 6.50 🔹 [id: 5 | heter: 0.19 | inst: 953 | w: 0.27]
temp > 6.50 🔹 [id: 6 | heter: 0.20 | inst: 1394 | w: 0.40]
--------------------------------------------------
Feature 3 - Statistics per tree level:
🌳 Tree Summary:
─────────────────
Level 0🔹heter: 0.43
Level 1🔹heter: 0.31 | 🔻0.12 (28.15%)
Level 2🔹heter: 0.19 | 🔻0.11 (37.10%)
The summary of feature hr
(hour) says that its effect on the output is highly dependent on the value of features:
workingday
, wheteher it is a workingday or not
temp
, what is the temperature the specific hour
Let's see how the effect changes on these subregions!
Is it workingday or not?
for node_idx in [1, 2]:
r_pdp.plot(
feature=3,
node_idx=node_idx,
nof_ice=200,
scale_x_list=[
{"mean": bike_sharing.x_test_mu[i], "std": bike_sharing.x_test_std[i]}
for i in range(X_test.shape[1])
],
scale_y={"mean": bike_sharing.y_test_mu, "std": bike_sharing.y_test_std},
y_limits=[-200, 1000]
)
Is it hot or cold?
for node_idx in [3, 4, 5, 6]:
r_pdp.plot(
feature=3,
node_idx=node_idx,
nof_ice=200,
scale_x_list=[
{"mean": bike_sharing.x_test_mu[i], "std": bike_sharing.x_test_std[i]}
for i in range(X_test.shape[1])
],
scale_y={"mean": bike_sharing.y_test_mu, "std": bike_sharing.y_test_std},
y_limits=[-200, 1000]
)
Supported Methods
effector
implements global and regional effect methods:
PDP | PDP | RegionalPDP | PDP | any | Fast for a small dataset |
d-PDP | DerPDP | RegionalDerPDP | d-PDP | differentiable | Fast for a small dataset |
ALE | ALE | RegionalALE | ALE | any | Fast |
RHALE | RHALE | RegionalRHALE | RHALE | differentiable | Very fast |
SHAP-DP | ShapDP | RegionalShapDP | SHAP | any | Fast for a small dataset and a light ML model |
Method Selection Guide
From the runtime persepective there are three criterias:
- is the dataset
small
(N<10K) or large
(N>10K instances) ?
- is the ML model
light
(runtime < 0.1s) or heavy
(runtime > 0.1s) ?
- is the ML model
differentiable
or non-differentiable
?
Trust us and follow this guide:
light
+ small
+ differentiable
= any([PDP, RHALE, ShapDP, ALE, DerPDP])
light
+ small
+ non-differentiable
: [PDP, ALE, ShapDP]
heavy
+ small
+ differentiable
= any([PDP, RHALE, ALE, DerPDP])
heavy
+ small
+ non differentiable
= any([PDP, ALE])
big
+ not differentiable
= ALE
big
+ differentiable
= RHALE
Citation
If you use effector
, please cite it:
@misc{gkolemis2024effector,
title={effector: A Python package for regional explanations},
author={Vasilis Gkolemis et al.},
year={2024},
eprint={2404.02629},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
Spotlight on effector
📚 Featured Publications
🎤 Talks & Presentations
🌍 Adoption & Collaborations
🔍 Additional Resources
📚 Related Publications
Papers that have inspired effector
:
-
REPID: Regional Effects in Predictive Models
Herbinger et al., 2022 - Link
-
Decomposing Global Feature Effects Based on Feature Interactions
Herbinger et al., 2023 - Link
-
RHALE: Robust Heterogeneity-Aware Effects
Gkolemis Vasilis et al., 2023 - Link
-
DALE: Decomposing Global Feature Effects
Gkolemis Vasilis et al., 2023 - Link
-
Greedy Function Approximation: A Gradient Boosting Machine
Friedman, 2001 - Link
-
Visualizing Predictor Effects in Black-Box Models
Apley, 2016 - Link
-
SHAP: A Unified Approach to Model Interpretation
Lundberg & Lee, 2017 - Link
-
Regionally Additive Models: Explainable-by-design models minimizing feature interactions
Gkolemis Vasilis et al., 2023 - Link
License
effector
is released under the MIT License.