Skip to content

Commit

Permalink
Validate that explainer is of accepted type
Browse files Browse the repository at this point in the history
AdrianSosic committed Jan 14, 2025
1 parent bf9cf2b commit f89f9ef
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions baybe/insights/shap.py
Original file line number Diff line number Diff line change
@@ -132,6 +132,15 @@ class SHAPInsight:
background_data: pd.DataFrame = field(validator=instance_of(pd.DataFrame))
"""The background data set used by the explainer."""

@explainer.validator
def _validate_explainer(self, _, explainer: shap.Explainer) -> None:
"""Validate the explainer type."""
if (name := explainer.__class__.__name__) not in EXPLAINERS:
raise ValueError(
f"The given explainer type must be one of {EXPLAINERS}. "
f"Given: '{name}'."
)

@property
def uses_shap_explainer(self) -> bool:
"""Indicates if a SHAP explainer is used or not (e.g. MAPLE, LIME)."""

0 comments on commit f89f9ef

Please sign in to comment.