plot_data#
- SuperGLM.plot_data(
- 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,
- n_points: int = 200,
- alpha: float = 0.05,
- n_sim: int = 10000,
- seed: int = 42,
- centering: str = 'native',
Return plain data needed to recreate SuperGLM plots.
This is the data/export companion to
plot(). It returns plain pandas DataFrames, NumPy arrays, and metadata dictionaries instead of a figure object, so users can rebuild charts in matplotlib, plotly, Excel, or another reporting system.For main effects, the payload includes per-term fitted effects and, when requested, density overlays, spline knot positions, and basis contributions. For interactions, it includes the reconstructed effect data and, for continuous x continuous surfaces, optional density / HDR grid data when
Xandsample_weightare supplied.With
centering="native"(default), relativity values are the exponentiated fitted term contributions under the model’s identifiability constraint — not portfolio-average relativities. Passcentering="mean"for a reporting view where the geometric mean of relativities = 1.A grouped
OrderedCategoricalis always exported on the expanded axis — one row per original level — whereplot()defaults to the collapsed view and takesgrouped_level_display=, which this method does not. That matters for a merged group, because the two payload pieces then live on different axes:effect["x_position"]holds the declared level values, whilesmooth_curve["x"]spans the axis the smooth was FITTED on, which for a merged group is its members’ mean position. A merge at either end of the ordering therefore leaves the exported curve short of the outermost exported markers, and a merged group’s two markers sit off the curve’s own band — correctly, since they are one parameter reported at two coordinates, but it reads like a coverage failure if you do not expect it. Join the two on the level table, not on x.Examples
>>> payload = model.plot_data("DrivAge", X=X_train, sample_weight=w, show_knots=True) >>> curve_df = payload["terms"][0]["effect"] >>> knots_df = payload["terms"][0]["knots"]