Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
C
covid_analysis
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
COMPARA
covid_analysis
Commits
11a14251
Commit
11a14251
authored
Jul 08, 2024
by
Joaquin Torres
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Completed comments
parent
cc955ffb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
explainability/compute_shap_vals.py
explainability/compute_shap_vals.py
+10
-3
No files found.
explainability/compute_shap_vals.py
View file @
11a14251
# Computing SHAP Values
# Author: Joaquín Torres Bravo
"""
Script to compute SHAP values for chosen models.
"""
# Libraries
# --------------------------------------------------------------------------------------------------------
import
pandas
as
pd
import
numpy
as
np
import
shap
import
pickle
import
shap
# Explainability
import
pickle
# Loading/saving models
# Models
from
xgboost
import
XGBClassifier
from
sklearn.ensemble
import
RandomForestClassifier
,
BaggingClassifier
,
AdaBoostClassifier
from
sklearn.neural_network
import
MLPClassifier
...
...
@@ -72,7 +79,7 @@ if __name__ == "__main__":
if
is_tree
:
explainer
=
shap
.
TreeExplainer
(
fitted_model
)
# else:
# explainer = shap.KernelExplainer
(fitted_model.predict_proba, X_test[:500])
# explainer = shap.KernelExplainer
...
# Compute shap values
shap_vals
=
explainer
.
shap_values
(
X_test
,
check_additivity
=
True
)
# Change to true for final results
# ---------------------------------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment