midlearn.plot_breakdown

midlearn.plot_breakdown(breakdown: MIDBreakdown, style: Literal['waterfall', 'barplot'] = 'waterfall', theme: str | pt.color_theme | None = None, max_nterms: int | None = 15, catchall: str = 'others', format: tuple[str, str] = ('%t=%v', '%t'), **kwargs)[source]

Visualize the decomposition of a single prediction into contributions from each component term with plotnine. This is a porting function for the R function midr::ggmid.mid.breakdown().

Parameters:
  • breakdown (MIDBreakdown) – A fitted MIDBreakdown object containing the term contributions for a specific data point.

  • style ({'waterfall', 'barplot'}, default 'waterfall') – The plotting style. ‘waterfall’ displays contributions as a cascading plot, showing how each term adds to the final prediction, starting from the intercept. ‘barplot’ displays contributions as simple horizontal bars, relative to zero.

  • theme (str or pt.color_theme or None, default None) – The color theme to use for the plot.

  • max_nterms (int or None, default 15) – The maximum number of terms to display. Terms beyond this limit are grouped into a single ‘catchall’ category. If None, all terms are displayed.

  • catchall (str, default 'others') – The label used for the grouped category when the number of terms exceeds max_nterms.

  • format (tuple[str, str], default ('%t=%v', '%t')) – A tuple of two format strings for labeling terms on the y-axis. The first string is for main effects (e.g., ‘term=value’), and the second is for interaction terms (e.g., ‘term’). %t is replaced by the term name, and %v is replaced by the predictor value.

  • **kwargs (dict) – Additional keyword arguments passed to the main layer of the plot.

Returns:

A plotnine object representing the breakdown visualization.

Return type:

plotnine.ggplot.ggplot