Skip to content

fix: Update Clarify SHAPConfig baseline to allow JSON structures #3804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/sagemaker/clarify.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
{object: object},
)
],
# Arbitrary JSON object as baseline
{object: object},
),
SchemaOptional("num_clusters"): int,
SchemaOptional("use_logit"): bool,
Expand Down Expand Up @@ -1211,7 +1213,7 @@ class SHAPConfig(ExplainabilityConfig):

def __init__(
self,
baseline: Optional[Union[str, List]] = None,
baseline: Optional[Union[str, List, Dict]] = None,
num_samples: Optional[int] = None,
agg_method: Optional[str] = None,
use_logit: bool = False,
Expand All @@ -1224,7 +1226,7 @@ def __init__(
"""Initializes config for SHAP analysis.
Args:
baseline (None or str or list): `Baseline dataset <https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-feature-attribute-shap-baselines.html>`_
baseline (None or str or list or dict): `Baseline dataset <https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-feature-attribute-shap-baselines.html>`_
for the Kernel SHAP algorithm, accepted in the form of:
S3 object URI, a list of rows (with at least one element),
or None (for no input baseline). The baseline dataset must have the same format
Expand Down
22 changes: 14 additions & 8 deletions tests/unit/test_clarify.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,20 @@ def test_invalid_model_predicted_label_config():
)


def test_shap_config():
baseline = [
[
0.26124998927116394,
0.2824999988079071,
0.06875000149011612,
]
]
@pytest.mark.parametrize(
"baseline",
[
([[0.26124998927116394, 0.2824999988079071, 0.06875000149011612]]),
(
{
"instances": [
{"features": [0.26124998927116394, 0.2824999988079071, 0.06875000149011612]}
]
}
),
],
)
def test_valid_shap_config(baseline):
num_samples = 100
agg_method = "mean_sq"
use_logit = True
Expand Down