midlearn.plot_breakdown
- midlearn.plot_breakdown(breakdown: MIDBreakdown, style: Literal['waterfall', 'barplot'] = 'waterfall', theme: str | pt.color_theme | None = None, terms: list[str] | None = None, max_nterms: int | None = 15, catchall: str = '(others)', label_format: list[str] | None = ['%t=%v', '%t:%t'], format_args: dict[str, Any] = {}, **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
MIDBreakdownobject 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.
terms (list[str] or None, default None) – An explicit list of term names to display. If provided, only the terms in this list are plotted individually and all other contributions are aggregated into a single category defined by catchall.
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.
label_format (list of str or None, default None) – A list of one or two format strings for axis labels. The first element is used for main effects (default: “%t=%v”). The second element is used for interactions (default: “%t:%t”). Use “%t” for the term name and “%v” for its formatted value.
format_args (dict or None, default None) – A dictionary of additional arguments for formatting values (e.g., {‘digits’: 3}). Common-and currently possible-keys include ‘digits’ for decimal precision.
**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