I'm using shap.utils.hclust to figure out which features are redundant and following the documentation
Reproducible example:
import pandas as pd
import numpy as np
import shap
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
from lightgbm import LGBMClassifier
data = pd.read_csv("https://raw.githubusercontent.com/gdmarmerola/random-stuff/master/probability_calibration/UCI_Credit_Card.csv")
# getting design matrix and target
X = data.copy().drop(['ID','default.payment.next.month'], axis=1)
y = data.copy()['default.payment.next.month']
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = .2, random_state = 42)
model = LGBMClassifier(random_state = 42).fit(X_train, y_train)
# compute SHAP values
explainer = shap.Explainer(model, X_test)
shap_values = explainer(X_test)
clustering = shap.utils.hclust(X_test, y_test) # by default this trains (X.shape[1] choose 2) 2-feature XGBoost models
shap.plots.bar(shap_values, clustering=clustering)
It retrieves the following plot:
My questions are:
In the implementation why is this an
XGBRegressoreven for classification tasks?How can I use
clusteringto remove redundant features, beyond the bar plot visual inspection?
UPDATE:
My main question is:
In this toy example, how can I use the (22,4) shape output matrix to check which features are in the same cluster and thus being able to reduce the dimensionality? I have a data frame with more than 10,000 features, that's why visual inspection is not feasible.
array([[15. , 16. , 0.2877219 , 2. ],
[12. , 13. , 0.36595157, 2. ],
[11. , 24. , 0.37372008, 3. ],
[14. , 25. , 0.420607 , 4. ],
[23. , 26. , 0.43781072, 6. ],
[ 9. , 10. , 0.45111704, 2. ],
[21. , 27. , 0.50203449, 7. ],
[20. , 29. , 0.51782125, 8. ],
[18. , 30. , 0.52462131, 9. ],
[17. , 31. , 0.52700263, 10. ],
[ 8. , 28. , 0.52802497, 3. ],
[19. , 32. , 0.54064447, 11. ],
[ 5. , 6. , 0.56145751, 2. ],
[ 7. , 33. , 0.57828146, 4. ],
[35. , 36. , 0.62561315, 6. ],
[34. , 37. , 0.66345358, 17. ],
[22. , 38. , 0.6892271 , 18. ],
[ 0. , 39. , 0.76330948, 19. ],
[ 4. , 40. , 0.91275334, 20. ],
[ 2. , 41. , 0.94387454, 21. ],
[ 1. , 42. , 0.98299891, 22. ],
[ 3. , 43. , 0.98913395, 23. ]])

