From f89f9efd327f498edda958cf23637a50f8a83f54 Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Tue, 14 Jan 2025 09:25:19 +0100 Subject: [PATCH] Validate that explainer is of accepted type --- baybe/insights/shap.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/baybe/insights/shap.py b/baybe/insights/shap.py index d087d53d6..8c40f5e88 100644 --- a/baybe/insights/shap.py +++ b/baybe/insights/shap.py @@ -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)."""