Skip to content

Commit 5190a37

Browse files
Merge pull request #49 from predict-idlab/dev-jonas
💨 updating dependencies - python 3.12 compatible
2 parents 81eecbc + 3c400b6 commit 5190a37

File tree

6 files changed

+1670
-1437
lines changed

6 files changed

+1670
-1437
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
os: ['ubuntu-latest'] # TODO - do we add other OSes?
30-
python-version: ["3.7", "3.8", "3.9", "3.10"]
30+
python-version: ["3.9", "3.10", "3.11", "3.12"]
3131
defaults:
3232
run:
3333
shell: bash

poetry.lock

Lines changed: 1652 additions & 1420 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

powershap/shap_wrappers/shap_explainer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
__author__ = "Jarne Verhaeghe, Jeroen Van Der Donckt"
22

3+
import gc
34
import warnings
45
from abc import ABC
56
from copy import copy
@@ -12,8 +13,6 @@
1213
from sklearn.model_selection import train_test_split
1314
from tqdm.auto import tqdm
1415

15-
import gc
16-
1716

1817
class ShapExplainer(ABC):
1918
"""Interface class for a (POWERshap explainer class."""
@@ -172,7 +171,8 @@ def explain(
172171
Shap_values = np.abs(Shap_values)
173172

174173
if len(np.shape(Shap_values)) > 2:
175-
Shap_values = np.max(Shap_values, axis=0)
174+
# Shap_values = np.max(Shap_values, axis=0)
175+
Shap_values = np.max(Shap_values, axis=0).T
176176

177177
# TODO: consider to convert to even float16?
178178
Shap_values = np.mean(Shap_values, axis=0).astype("float32")
@@ -185,7 +185,6 @@ def explain(
185185
# on every iteration.
186186
gc.collect()
187187

188-
189188
shaps = np.array(shaps)
190189

191190
return pd.DataFrame(data=shaps, columns=X.columns.values)
@@ -350,7 +349,7 @@ def supports_model(model) -> bool:
350349
def _fit_get_shap(self, X_train, Y_train, X_val, Y_val, random_seed, **kwargs) -> np.array:
351350
import tensorflow as tf
352351

353-
tf.compat.v1.disable_v2_behavior() # https://github.com/slundberg/shap/issues/2189
352+
# tf.compat.v1.disable_v2_behavior() # https://github.com/slundberg/shap/issues/2189
354353

355354
# Fit the model
356355
PowerShap_model = tf.keras.models.clone_model(self.model)
@@ -359,6 +358,7 @@ def _fit_get_shap(self, X_train, Y_train, X_val, Y_val, random_seed, **kwargs) -
359358
loss=kwargs["loss"],
360359
optimizer=kwargs["optimizer"],
361360
metrics=metrics if metrics is None else [metrics],
361+
# run_eagerly=True,
362362
)
363363
_ = PowerShap_model.fit(
364364
X_train,

pyproject.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ repository = "https://github.com/predict-idlab/powershap"
99
keywords = ["feature selection", "shap", "data-science", "machine learning"]
1010

1111
[tool.poetry.dependencies]
12-
python = ">=3.7.1,<3.11"
12+
python = ">=3.9,<=3.12"
1313
catboost = "^1.0.5"
1414
statsmodels = "^0.13.2"
15-
numpy = "^1.21"
1615
pandas = ">=1.3"
17-
shap = "^0.40"
16+
shap = "^0.45.0"
1817
scikit-learn = "*"
1918

2019
[tool.poetry.dev-dependencies]
2120
pytest = "^7.1.1"
2221
pytest-cov = "^3.0.0"
23-
tensorflow = "^2.8.0"
22+
tensorflow = [
23+
{ version = "<2.16.0", python = "<3.12"}
24+
# support 3.12 when shap support tf 2.16 - https://github.com/shap/shap/issues/3562
25+
]
2426
lightgbm = "^3.3.2"
2527
xgboost = "^1.6.0"
2628
black = "^22.12.0"
@@ -54,5 +56,5 @@ multi_line_output = 3
5456
include_trailing_comma = true
5557
force_grid_wrap = 0
5658
combine_as_imports = true
57-
color_output = true
59+
color_output = false
5860
skip = "tests/toml_test.py"

tests/test_deep_learning_powershap.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .conftest import dummy_classification, dummy_regression
88

9+
# tf.compat.v1.enable_eager_execution()
910

1011
def test_deep_learning_class_powershap(dummy_classification):
1112
X, y = dummy_classification

tests/test_powershap.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
__author__ = "Jeroen Van Der Donckt"
22

3+
import hashlib
4+
35
import numpy as np
46
import pandas as pd
57
from catboost import CatBoostClassifier, CatBoostRegressor
@@ -8,8 +10,6 @@
810

911
from .conftest import dummy_classification, dummy_regression
1012

11-
import hashlib
12-
1313
### DEFAULT MODEL & AUTOMATIC MODE
1414

1515

@@ -251,8 +251,7 @@ def test_powershap_cv_groupshufflesplit(dummy_classification):
251251

252252

253253
def test_no_mutate_df(dummy_classification):
254-
"""Ensure that powershap fit doesn't mutate an input pandas dataframe.
255-
"""
254+
"""Ensure that powershap fit doesn't mutate an input pandas dataframe."""
256255
X, y = dummy_classification
257256
n_informative = sum([c.startswith("informative") for c in X.columns])
258257
assert n_informative > 0, "No informative columns in the dummy data!"
@@ -277,8 +276,7 @@ def test_no_mutate_df(dummy_classification):
277276

278277

279278
def test_no_mutate_numpy(dummy_classification):
280-
"""Ensure that powershap fit doesn't mutate an input numpy array.
281-
"""
279+
"""Ensure that powershap fit doesn't mutate an input numpy array."""
282280
X, y = dummy_classification
283281

284282
X = X.to_numpy()

0 commit comments

Comments
 (0)