plot#

SuperGLM.plot(
terms: Hashable | Sequence[Hashable] | None = None,
*,
kind: str = 'global',
ci: str | bool | None = 'pointwise',
X: object | None = None,
sample_weight: NDArray | None = None,
show_density: bool = True,
show_knots: bool = False,
show_bases: bool = False,
scale: str = 'response',
ci_style: str = 'band',
categorical_display: str = 'auto',
grouped_level_display: str = 'auto',
engine: str = 'matplotlib',
n_points: int = 200,
figsize: tuple[float, float] | None = None,
title: str | None = None,
subtitle: str | None = None,
plotly_style: dict[str, Any] | None = None,
alpha: float = 0.05,
n_sim: int = 10000,
seed: int = 42,
centering: str = 'native',
**kwargs,
)#

Plot model terms.

Single entry point for all plotting. Dispatches based on terms:

  • None — all main effects in a grid.

  • "age" — one main effect.

  • ["age", "region"] — subset of main effects.

  • "age:region" — one interaction.

Parameters:
termshashable label, list of labels, or None

Which term(s) to plot. None plots all main effects unless the fitted model has a feature whose exact column label is None.

kind{“global”, “local”}

"global" shows model-wide fitted effects (default). "local" is reserved for per-row explanations (not yet implemented).

ci{None, False, “pointwise”, “simultaneous”, “both”}

Confidence interval style. None or False disables bands.

Xpandas or eager Polars DataFrame, optional

Training data for density overlays.

sample_weightarray-like, optional

Observation weights for density overlays. When reusing fitting weights, they keep the model’s declared weight_semantics: replication counts under "frequency", precisions under "prior".

show_densitybool

Show sample-weighted observation density (strip for continuous, bars for categorical). Default True.

show_knotsbool

Show interior knot ticks (spline terms only).

show_basesbool

Initial visibility for coefficient-weighted spline basis contributions in the Plotly explorer. Only meaningful when scale="link"; ignored in response-scale mode and by the matplotlib renderer.

scale{“response”, “link”}

"response" (default) shows the fitted effect on the inverse-link scale (relativities). With centering="native", this is the exponentiated fitted term contribution under the model’s identifiability constraint — not a portfolio-average relativity. "link" shows the additive link-scale contribution eta(x) = B(x) @ beta, with optional basis decomposition overlays. Only used by the Plotly renderer.

ci_style{“band”, “lines”}

Plotly CI presentation. "band" (default) draws filled confidence bands. "lines" draws line-only CI bounds with no fill.

categorical_display{“auto”, “bars”, “markers”, “bars+markers”}

Plotly categorical rendering mode. "auto" (default) uses bars+markers up to 30 levels and markers-only above that.

grouped_level_display{“auto”, “expanded”, “collapsed”}

Display option for grouped categorical levels in main-effect plots. "auto" collapses grouped ordered-categorical terms and leaves unordered categoricals expanded. This is a plotting-only option; scoring, inference tables, and exports remain expanded over the original levels.

engine{“matplotlib”, “plotly”}

Plotting backend. "matplotlib" is the chart/export path for single terms and grids. "plotly" is the interactive main-effect explorer path, with a response/link scale toggle and term selector. For main effects, Plotly requires at least two terms (or terms=None); use engine="matplotlib" for a single-term chart. Requires the plotly optional dependency (pip install superglm[plotting]).

centering{“native”, “mean”}

"native" (default) returns the canonical fitted term contribution under the model’s identifiability constraint. "mean" is a reporting convenience that shifts so the geometric mean of relativities = 1. It is a change of identifiability constraint, so the standard errors and intervals change with it: they become those of the centered contrast, and the level the fit pinned stops carrying a zero-width interval.

n_pointsint

Grid resolution for spline/polynomial curves.

figsizetuple, optional

Figure size override.

title, subtitlestr, optional

Figure-level title and subtitle.

plotly_styledict, optional

Plotly main-effect explorer style overrides. Supported keys include line_color, bar_color, density_fill_color, density_edge_color, error_bar_color, text_color, and text_outline_color. Ignored by the matplotlib renderer.

alphafloat

Significance level for CIs (default 0.05).

n_simint

Posterior simulations for simultaneous bands.

seedint

Random seed for simultaneous bands.

**kwargs

Forwarded to the underlying renderer (e.g. ncols for grid plots, colormap for interactions).

Returns:
matplotlib.figure.Figure or plotly.graph_objects.Figure

Examples

>>> fig = model.plot(engine="plotly", X=X_train, sample_weight=w)
>>> fig.show()                      # interactive main-effect explorer
>>> fig.write_html("effects.html") # standalone HTML export