pdstools.explanations.Plots

Classes

Plots

Plots.

Module Contents

class Plots(explanations: pdstools.explanations.Explanations.Explanations)

Bases: pdstools.utils.namespaces.LazyNamespace

Plots.

Parameters:

explanations (pdstools.explanations.Explanations.Explanations)

dependencies: ClassVar[list[str]] = ['numpy', 'plotly']
dependency_group = 'explanations'
X_AXIS_TITLE_DEFAULT = 'Contribution'
Y_AXIS_TITLE_DEFAULT = 'Predictor'
explanations
aggregate
contributions(top_n: int = 20, top_k: int = 20, *, return_df: bool = False, sort_by: pdstools.explanations.ExplanationsUtils.SortBy = 'contribution_abs', display_by: pdstools.explanations.ExplanationsUtils.DisplayBy = 'contribution', descending: bool = True, missing: bool = True, remaining: bool = True, include_numeric_single_bin: bool = False)

Plots contributions for the overall model or a selected context.

Parameters:
  • top_n (int) – Number of top predictors to display.

  • top_k (int) – Number of top unique values for each categorical predictor to display.

  • return_df (bool) – If True, skip plotting and return the underlying dataframes instead. When a context is selected, returns (predictor_df, predictor_value_df); otherwise returns the same pair computed against the overall model.

  • sort_by (str) – Column to rank/select top predictors. One of contribution, contribution_abs, contribution_weighted, contribution_weighted_abs. Default: "contribution_abs".

  • display_by (str) – Column to use for the chart axis values. Default: "contribution".

  • descending (bool) – Sort most- or least-impactful first. Default: True.

  • missing (bool) – Include missing-value bins. Default: True.

  • remaining (bool) – Include an aggregated “remaining” row. Default: True.

  • include_numeric_single_bin (bool) – Include numeric predictors that have only a single bin. Default: False.

Returns:

  • left: context header if context is selected, otherwise None

  • right: overall contributions plot and a list of predictor contribution plots.

Return type:

tuple[go.Figure, list[go.Figure]]

plot_contributions_for_overall(top_n: int = ..., top_k: int = ..., *, return_df: Literal[False] = ..., sort_by: pdstools.explanations.ExplanationsUtils.SortBy = ..., display_by: pdstools.explanations.ExplanationsUtils.DisplayBy = ..., descending: bool = ..., missing: bool = ..., remaining: bool = ..., include_numeric_single_bin: bool = ...) tuple[plotly.graph_objects.Figure, list[plotly.graph_objects.Figure]]
plot_contributions_for_overall(top_n: int = ..., top_k: int = ..., *, return_df: Literal[True], sort_by: pdstools.explanations.ExplanationsUtils.SortBy = ..., display_by: pdstools.explanations.ExplanationsUtils.DisplayBy = ..., descending: bool = ..., missing: bool = ..., remaining: bool = ..., include_numeric_single_bin: bool = ...) tuple[polars.DataFrame, polars.DataFrame]

Plot contributions for overall.

plot_contributions_by_context(context: dict[str, str], top_n: int = ..., top_k: int = ..., *, return_df: Literal[False] = ..., sort_by: pdstools.explanations.ExplanationsUtils.SortBy = ..., display_by: pdstools.explanations.ExplanationsUtils.DisplayBy = ..., descending: bool = ..., missing: bool = ..., remaining: bool = ..., include_numeric_single_bin: bool = ...) tuple[plotly.graph_objects.Figure, plotly.graph_objects.Figure, list[plotly.graph_objects.Figure]]
plot_contributions_by_context(context: dict[str, str], top_n: int = ..., top_k: int = ..., *, return_df: Literal[True], sort_by: pdstools.explanations.ExplanationsUtils.SortBy = ..., display_by: pdstools.explanations.ExplanationsUtils.DisplayBy = ..., descending: bool = ..., missing: bool = ..., remaining: bool = ..., include_numeric_single_bin: bool = ...) tuple[polars.DataFrame, polars.DataFrame]

Plot contributions by context.