From 2dcd88918900bb76fe1dfcf0d9e110e2921aa988 Mon Sep 17 00:00:00 2001 From: Juan Date: Mon, 31 Mar 2025 23:44:30 +0200 Subject: [PATCH 1/2] Added conversion to shap values to ensure float arrays --- .../sklearn/SHAPGlobalImportance.py | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/validmind/tests/model_validation/sklearn/SHAPGlobalImportance.py b/validmind/tests/model_validation/sklearn/SHAPGlobalImportance.py index c91b4f9d2..bebaf4b00 100644 --- a/validmind/tests/model_validation/sklearn/SHAPGlobalImportance.py +++ b/validmind/tests/model_validation/sklearn/SHAPGlobalImportance.py @@ -46,29 +46,25 @@ def select_shap_values( """ if not isinstance(shap_values, list): # For regression, return the SHAP values as they are - # TODO: shap_values is always an array of all predictions, how is the if above supposed to work? - # logger.info("Returning SHAP values as-is.") - return shap_values - - num_classes = len(shap_values) - - # Default to class 1 for binary classification where no class is specified - if num_classes == 2 and class_of_interest is None: - logger.debug("Using SHAP values for class 1 (positive class).") - return shap_values[1] + selected_values = shap_values + else: + num_classes = len(shap_values) + # Default to class 1 for binary classification where no class is specified + if num_classes == 2 and class_of_interest is None: + selected_values = shap_values[1] + # Otherwise, use the specified class_of_interest + elif class_of_interest is not None and 0 <= class_of_interest < num_classes: + selected_values = shap_values[class_of_interest] + else: + raise ValueError( + f"Invalid class_of_interest: {class_of_interest}. Must be between 0 and {num_classes - 1}." + ) - # Otherwise, use the specified class_of_interest - if ( - class_of_interest is None - or class_of_interest < 0 - or class_of_interest >= num_classes - ): - raise ValueError( - f"Invalid class_of_interest: {class_of_interest}. Must be between 0 and {num_classes - 1}." - ) + # Add type conversion here to ensure proper float array + if hasattr(selected_values, "dtype"): + selected_values = np.array(selected_values, dtype=np.float64) - logger.debug(f"Using SHAP values for class {class_of_interest}.") - return shap_values[class_of_interest] + return selected_values def generate_shap_plot( From aed3a992bd7b99e1301f4c78c3bc188ea48b0df5 Mon Sep 17 00:00:00 2001 From: Juan Date: Tue, 1 Apr 2025 10:35:50 +0200 Subject: [PATCH 2/2] 2.8.15 --- pyproject.toml | 2 +- validmind/__version__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f8c0f0532..eb0d90a62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ description = "ValidMind Library" license = "Commercial License" name = "validmind" readme = "README.pypi.md" -version = "2.8.14" +version = "2.8.15" [tool.poetry.dependencies] aiohttp = {extras = ["speedups"], version = "*"} diff --git a/validmind/__version__.py b/validmind/__version__.py index 781278681..b365dbcd9 100644 --- a/validmind/__version__.py +++ b/validmind/__version__.py @@ -1 +1 @@ -__version__ = "2.8.14" +__version__ = "2.8.15"