shap.plots.force
- shap.plots.force(base_value, shap_values=None, features=None, feature_names=None, out_names=None, link='identity', plot_cmap='RdBu', matplotlib=False, show=True, figsize=(20, 3), ordering_keys=None, ordering_keys_time_format=None, text_rotation=0, contribution_threshold=0.05)
Visualize the given SHAP values with an additive force layout.
- Parameters:
- base_valuefloat or shap.Explanation
If a float is passed in, this is the reference value that the feature contributions start from. For SHAP values, it should be the value of
explainer.expected_value
. However, it is recommended to pass in a SHAPExplanation
object instead (shap_values
is not necessary in this case).- shap_valuesnumpy.array
Matrix of SHAP values (# features) or (# samples x # features). If this is a 1D array, then a single force plot will be drawn. If it is a 2D array, then a stacked force plot will be drawn.
- featuresnumpy.array
Matrix of feature values (# features) or (# samples x # features). This provides the values of all the features, and should be the same shape as the
shap_values
argument.- feature_nameslist
List of feature names (# features).
- out_namesstr
The name of the output of the model (plural to support multi-output plotting in the future).
- link“identity” or “logit”
The transformation used when drawing the tick mark labels. Using “logit” will change log-odds numbers into probabilities.
- plot_cmapstr or list[str]
Color map to use. It can be a string (defaults to
RdBu
) or a list of hex color strings.- matplotlibbool
Whether to use the default Javascript output, or the (less developed) matplotlib output. Using matplotlib can be helpful in scenarios where rendering Javascript/HTML is inconvenient. Defaults to False.
- showbool
Whether
matplotlib.pyplot.show()
is called before returning. Setting this toFalse
allows the plot to be customized further after it has been created. Only applicable whenmatplotlib
is set to True.- figsize
Figure size of the matplotlib output.
- contribution_thresholdfloat
Controls the feature names/values that are displayed on force plot. Only features that the magnitude of their shap value is larger than min_perc * (sum of all abs shap values) will be displayed.