midlearn.plot_conditional
- midlearn.plot_conditional(conditional: MIDConditional, style: Literal['ice', 'centered'] = 'ice', theme: str | pt.color_theme | None = None, term: str | None = None, var_alpha: str | None = None, var_color: str | None = None, var_linetype: str | None = None, var_linewidth: str | None = None, reference: int = 0, points: bool = True, sample: list[Any] | None = None, **kwargs)[source]
Visualize Individual Conditional Expectation (ICE) curves derived from a fitted MID model with plotnine. This is a porting function for the R function midr::ggmid.midcon().
ICE plots are a model-agnostic tool for visualizing how a model’s prediction for a single observation changes as one feature varies. This function plots one line for each observation in the data.
- Parameters:
conditional (MIDConditional) – A fitted
MIDConditionalobject containing the ICE data to be visualized.style ({'ice', 'centered'}, default 'ice') – The plotting style. ‘ice’ (default) plots the raw ICE curves. ‘centered’ creates the centered ICE (c-ICE) plot, where each curve is shifted to start at zero relative to a reference point, making it easier to compare the slopes.
theme (str or pt.color_theme or None, default None) – The color theme to use for the plot. See pt.color_theme for details.
term (str or None, default None) – An optional character string specifying an interaction term. If passed, the ICE curve for the specified term is plotted instead of the overall prediction.
var_alpha (str or None, default None) – A variable name or expression to map to the alpha aesthetic.
var_color (str or None, default None) – A variable name or expression to map to the color aesthetic.
var_linetype (str or None, default None) – A variable name or expression to map to the linetype aesthetic.
var_linewidth (str or None, default None) – A variable name or expression to map to the linewidth aesthetic.
reference (int, default 0) – An integer specifying the 0-based index of the evaluation point to use as the reference for centering when style=’centered’. Negative values count from the end.
points (bool, default True) – If True, points representing the actual predictions for each observation are plotted.
sample (list of Any or None, default None) – An optional list specifying the IDs of observations to be plotted.
**kwargs (dict) – Additional optional parameters passed on to the main layer (geom_line and geom_point).
- Returns:
A plotnine object representing the conditional expectation visualization.
- Return type:
plotnine.ggplot.ggplot