@@ -244,29 +244,32 @@ def decision(
244
244
----------
245
245
base_value : float or numpy.ndarray
246
246
This is the reference value that the feature contributions start from. Usually, this is
247
- explainer.expected_value.
247
+ `` explainer.expected_value`` .
248
248
249
249
shap_values : numpy.ndarray
250
- Matrix of SHAP values (# features) or (# samples x # features) from explainer.shap_values(). Or cube of SHAP
251
- interaction values (# samples x # features x # features) from explainer.shap_interaction_values().
250
+ Matrix of SHAP values (# features) or (# samples x # features) from
251
+ ``explainer.shap_values()``. Or cube of SHAP interaction values (# samples x
252
+ # features x # features) from ``explainer.shap_interaction_values()``.
252
253
253
254
features : numpy.array or pandas.Series or pandas.DataFrame or numpy.ndarray or list
254
255
Matrix of feature values (# features) or (# samples x # features). This provides the values of all the
255
256
features and, optionally, the feature names.
256
257
257
258
feature_names : list or numpy.ndarray
258
- List of feature names (# features). If None, names may be derived from the features argument if a Pandas
259
- object is provided. Otherwise, numeric feature names will be generated.
259
+ List of feature names (# features). If ``None``, names may be derived from the
260
+ ``features`` argument if a Pandas object is provided. Otherwise, numeric feature
261
+ names will be generated.
260
262
261
263
feature_order : str or None or list or numpy.ndarray
262
- Any of "importance" (the default), "hclust" (hierarchical clustering), "none", or a list/array of indices.
264
+ Any of "importance" (the default), "hclust" (hierarchical clustering), ``None``,
265
+ or a list/array of indices.
263
266
264
267
feature_display_range: slice or range
265
- The slice or range of features to plot after ordering features by feature_order. A step of 1 or None
268
+ The slice or range of features to plot after ordering features by `` feature_order`` . A step of 1 or `` None``
266
269
will display the features in ascending order. A step of -1 will display the features in descending order. If
267
- feature_display_range=None, slice(-1, -21, -1) is used (i.e. show the last 20 features in descending order).
268
- If shap_values contains interaction values, the number of features is automatically expanded to include all
269
- possible interactions: N(N + 1)/2 where N = shap_values.shape[1].
270
+ `` feature_display_range=None``, `` slice(-1, -21, -1)`` is used (i.e. show the last 20 features in descending order).
271
+ If `` shap_values`` contains interaction values, the number of features is automatically expanded to include all
272
+ possible interactions: N(N + 1)/2 where N = `` shap_values.shape[1]`` .
270
273
271
274
highlight : Any
272
275
Specify which observations to draw in a different line style. All numpy indexing methods are supported. For
@@ -277,7 +280,7 @@ def decision(
277
280
log-odds into probabilities.
278
281
279
282
plot_color : str or matplotlib.colors.ColorMap
280
- Color spectrum used to draw the plot lines. If str, a registered matplotlib color name is assumed.
283
+ Color spectrum used to draw the plot lines. If `` str`` , a registered matplotlib color name is assumed.
281
284
282
285
axis_color : str or int
283
286
Color used to draw plot axes.
@@ -289,39 +292,46 @@ def decision(
289
292
Alpha blending value in [0, 1] used to draw plot lines.
290
293
291
294
color_bar : bool
292
- Whether to draw the color bar.
295
+ Whether to draw the color bar (legend) .
293
296
294
297
auto_size_plot : bool
295
- Whether to automatically size the matplotlib plot to fit the number of features displayed. If `False`,
296
- specify the plot size using matplotlib before calling this function.
298
+ Whether to automatically size the matplotlib plot to fit the number of features
299
+ displayed. If ``False``, specify the plot size using matplotlib before calling
300
+ this function.
297
301
298
302
title : str
299
303
Title of the plot.
300
304
301
305
xlim: tuple[float, float]
302
- The extents of the x-axis (e.g. (-1.0, 1.0)). If not specified, the limits are determined by the
303
- maximum/minimum predictions centered around base_value when link='identity'. When link='logit', the
304
- x-axis extents are (0, 1) centered at 0.5. x_lim values are not transformed by the link function. This
305
- argument is provided to simplify producing multiple plots on the same scale for comparison.
306
+ The extents of the x-axis (e.g. ``(-1.0, 1.0)``). If not specified, the limits
307
+ are determined by the maximum/minimum predictions centered around base_value
308
+ when ``link="identity"``. When ``link="logit"``, the x-axis extents are ``(0,
309
+ 1)`` centered at 0.5. ``xlim`` values are not transformed by the ``link``
310
+ function. This argument is provided to simplify producing multiple plots on the
311
+ same scale for comparison.
306
312
307
313
show : bool
308
- Whether to automatically display the plot.
314
+ Whether ``matplotlib.pyplot.show()`` is called before returning.
315
+ Setting this to ``False`` allows the plot
316
+ to be customized further after it has been created.
309
317
310
318
return_objects : bool
311
- Whether to return a DecisionPlotResult object containing various plotting features. This can be used to
312
- generate multiple decision plots using the same feature ordering and scale.
319
+ Whether to return a :obj:`DecisionPlotResult` object containing various plotting
320
+ features. This can be used to generate multiple decision plots using the same
321
+ feature ordering and scale.
313
322
314
323
ignore_warnings : bool
315
324
Plotting many data points or too many features at a time may be slow, or may create very large plots. Set
316
- this argument to `True` to override hard-coded limits that prevent plotting large amounts of data.
325
+ this argument to `` True` ` to override hard-coded limits that prevent plotting large amounts of data.
317
326
318
327
new_base_value : float
319
- SHAP values are relative to a base value; by default, the expected value of the model's raw predictions. Use
320
- `new_base_value` to shift the base value to an arbitrary value (e.g. the cutoff point for a binary
328
+ SHAP values are relative to a base value. By default, this base value is the
329
+ expected value of the model's raw predictions. Use ``new_base_value`` to shift
330
+ the base value to an arbitrary value (e.g. the cutoff point for a binary
321
331
classification task).
322
332
323
333
legend_labels : list of str
324
- List of legend labels. If `None`, legend will not be shown.
334
+ List of legend labels. If `` None` `, legend will not be shown.
325
335
326
336
legend_location : str
327
337
Legend location. Any of "best", "upper right", "upper left", "lower left", "lower right", "right",
@@ -330,15 +340,19 @@ def decision(
330
340
Returns
331
341
-------
332
342
DecisionPlotResult or None
333
- Returns a DecisionPlotResult object if `return_objects=True`. Returns `None` otherwise (the default).
343
+ Returns a :obj:`DecisionPlotResult` object if ``return_objects=True``. Returns ``None`` otherwise (the default).
344
+
345
+ Examples
346
+ --------
334
347
335
- Example
336
- -------
337
348
Plot two decision plots using the same feature order and x-axis.
349
+
338
350
>>> range1, range2 = range(20), range(20, 40)
339
351
>>> r = decision_plot(base, shap_values[range1], features[range1], return_objects=True)
340
352
>>> decision_plot(base, shap_values[range2], features[range2], feature_order=r.feature_idx, xlim=r.xlim)
341
353
354
+ See more `decision plot examples here <https://shap.readthedocs.io/en/latest/example_notebooks/api_examples/plots/decision_plot.html>`_.
355
+
342
356
"""
343
357
344
358
# code taken from force_plot. auto unwrap the base_value
0 commit comments