From 6d5c2aeb12d31101bff51e7bee5e07434e29babc Mon Sep 17 00:00:00 2001 From: Jochen Sieg Date: Fri, 30 Aug 2024 17:24:36 +0200 Subject: [PATCH] linting --- molpipeline/explainability/explanation.py | 2 +- molpipeline/explainability/visualization/visualization.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/molpipeline/explainability/explanation.py b/molpipeline/explainability/explanation.py index 98f21dd3..43da0556 100644 --- a/molpipeline/explainability/explanation.py +++ b/molpipeline/explainability/explanation.py @@ -59,4 +59,4 @@ class SHAPExplanation(Explanation): This Explanation holds additional information only present in SHAP explanations. """ - expected_value: npt.NDArray[np.float64] = np.nan + expected_value: npt.NDArray[np.float64] | None = None diff --git a/molpipeline/explainability/visualization/visualization.py b/molpipeline/explainability/visualization/visualization.py index f354e9b4..b9ca9b0c 100644 --- a/molpipeline/explainability/visualization/visualization.py +++ b/molpipeline/explainability/visualization/visualization.py @@ -408,6 +408,10 @@ def structure_heatmap_shap( raise ValueError("SHAPExplanation does not contain feature weights.") if explanation.feature_vector is None: raise ValueError("SHAPExplanation does not contain feature_vector.") + if explanation.expected_value is None: + raise ValueError("SHAPExplanation does not contain expected value.") + if explanation.prediction is None: + raise ValueError("SHAPExplanation does not contain prediction.") if explanation.molecule is None: raise ValueError("SHAPExplanation does not contain molecule.") if explanation.atom_weights is None: @@ -418,7 +422,7 @@ def structure_heatmap_shap( sum_present_shap = sum(present_shap) sum_absent_shap = sum(absent_shap) - drawer, value_grid, color_grid, normalizer, color_map = _structure_heatmap( + drawer, _, _, normalizer, color_map = _structure_heatmap( explanation.molecule, explanation.atom_weights, color=color, @@ -450,7 +454,7 @@ def structure_heatmap_shap( f"$P(y=1|X) = {explanation.prediction[1]:.2f}$ =" "\n" "\n" - f" $expected \ value={explanation.expected_value[1]:.2f}$ + " # noqa: W605 + f" $expected \ value={explanation.expected_value[1]:.2f}$ + " # noqa: W605 # pylint: disable=W1401 f"$features_{{present}}= {sum_present_shap:.2f}$ + " f"$features_{{absent}}={sum_absent_shap:.2f}$" )