openavmkit.shap_analysis
compute_shap
compute_shap(smr, plot=False, title='')
Compute SHAP values for a given model and dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smr
|
SingleModelResults
|
The SingleModelResults object containing the fitted model and data splits. |
required |
plot
|
bool
|
If True, generate and display a SHAP summary plot. Defaults to False. |
False
|
title
|
str
|
Title to use for the SHAP plot if |
''
|
Returns:
Type | Description |
---|---|
ndarray
|
SHAP values array for the evaluation dataset. |
Source code in openavmkit/shap_analysis.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
plot_full_beeswarm
plot_full_beeswarm(explanation, title='SHAP Beeswarm', wrap_width=20)
Plot a full SHAP beeswarm for a tree-based model with wrapped feature names.
This function wraps long feature names, auto-scales figure size to the number of features, and renders a beeswarm plot with rotated, smaller y-axis labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
explanation
|
Explanation
|
SHAP Explanation object with |
required |
title
|
str
|
Title of the plot. Defaults to "SHAP Beeswarm". |
'SHAP Beeswarm'
|
wrap_width
|
int
|
Maximum character width for feature name wrapping. Defaults to 20. |
20
|
Source code in openavmkit/shap_analysis.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|