OCDocker.OCScore.Analysis.SHAP.Plots module¶
Utilities to visualize SHAP outputs.
Public helpers¶
feature_importance_barh: horizontal bar chart of relative importance
beeswarm: wrapper around shap.summary_plot
shap_correlation_heatmap: correlation heatmap of SHAP values
Usage:
from OCDocker.OCScore.Analysis.SHAP.Plots import feature_importance_barh
- OCDocker.OCScore.Analysis.SHAP.Plots.beeswarm(shap_2d, X_eval, out_png, figsize=(10, 6))[source]¶
Wrapper around shap.summary_plot to save a beeswarm plot.
- Parameters:
shap_2d (np.ndarray) – SHAP values with shape (n_samples, n_features).
X_eval (pd.DataFrame) – Evaluation features (columns = names).
out_png (str) – Where to save the plot.
figsize (tuple[int, int], optional) – Plot size (width, height). Default is (10, 6).
- Returns:
Output path of the saved plot.
- Return type:
str
- OCDocker.OCScore.Analysis.SHAP.Plots.feature_importance_barh(shap_2d, feature_names, out_png, top_k=20, figsize=(10, 6))[source]¶
Horizontal bar chart of relative SHAP importance per feature.
- Parameters:
shap_2d (np.ndarray) – SHAP values array with shape (n_samples, n_features).
feature_names (list[str]) – Names of features in column order.
out_png (str) – Where to save the plot.
top_k (int, optional) – Number of top features to display. Default is 20.
figsize (tuple[int, int], optional) – Figure size. Default is (10, 6).
- Returns:
Output path of the saved plot.
- Return type:
str
- OCDocker.OCScore.Analysis.SHAP.Plots.shap_correlation_heatmap(shap_values, out_png, feature_names=None, figsize=(12, 10))[source]¶
Plot a heatmap of SHAP value correlations across features.
- Parameters:
shap_values (array-like | pd.DataFrame) – SHAP values with shape (n_samples, n_features).
out_png (str) – Where to save the heatmap image.
feature_names (list[str] | None) – Optional feature names. If shap_values is a DataFrame, its columns are used.
figsize (tuple[int, int]) – Figure size.
- Returns:
Output path of the saved heatmap.
- Return type:
str