Inspection Reference
philanthropy.inspection
Model-agnostic interpretability helpers for donor-scoring estimators.
donor_feature_importance(estimator, X, y, *, feature_names=None, n_repeats=10, random_state=None, scoring=None)
Permutation feature importance for a fitted donor-scoring estimator.
Answers "which donor signals move this model's score?" for any fitted
PhilanthroPy / scikit-learn estimator, including calibrated or
gradient-boosted models (e.g. :class:~philanthropy.models.MajorGiftClassifier)
that do not expose feature_importances_, by measuring how far a scoring
metric drops when each feature's values are randomly shuffled. It is a
dependency-free alternative to SHAP for explaining and auditing donor scores.
Because attribution is computed by scoring against held-out y, run this on
a validation split (not the training data) for an honest read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
fitted estimator
|
Any fitted estimator implementing |
required |
X
|
array-like or pandas.DataFrame of shape (n_samples, n_features)
|
Feature matrix to permute. |
required |
y
|
array-like of shape (n_samples,)
|
True targets used to score each permutation. |
required |
feature_names
|
sequence of str
|
Column labels for |
None
|
n_repeats
|
int
|
Number of times each feature is permuted. |
10
|
random_state
|
int, RandomState instance or None
|
Controls the permutation shuffling for reproducibility. |
None
|
scoring
|
(str, callable or None)
|
Scorer passed through to
:func: |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per feature with columns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |