pdstools.explanations.Aggregates

Classes

Aggregates

Aggregates.

Module Contents

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

Bases: pdstools.utils.namespaces.LazyNamespace

Aggregates.

Parameters:

explanations (pdstools.explanations.Explanations.Explanations)

dependencies: ClassVar[list[str]] = ['polars']
dependency_group = 'explanations'
explanations
context_operations
predictor_contributions(context: dict[str, str] | None = None, top_n: int = 20, *, sort_by: pdstools.explanations._constants.ContributionType = 'contribution_abs', descending: bool = True, missing: bool = True, remaining: bool = True, include_numeric_single_bin: bool = False) polars.DataFrame

Get the top-n predictor contributions for a given context or overall.

Parameters:
  • context (dict[str, str] | None) – The context to filter contributions by. If None, contributions for all contexts will be returned.

  • top_n (int) – Number of top predictors.

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

  • 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 for predictors outside the top-n. Default: True.

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

Return type:

polars.DataFrame

predictor_value_contributions(predictors: list[str], context: dict[str, str] | None = None, top_k: int = 20, *, sort_by: pdstools.explanations._constants.ContributionType = 'contribution_abs', descending: bool = True, missing: bool = True, remaining: bool = True, include_numeric_single_bin: bool = False) polars.DataFrame

Get the top-k predictor value contributions for a given context or overall.

Parameters:
  • predictors (list[str]) – Required. list of predictors to get the contributions for.

  • context (dict[str, str] | None) – The context to filter contributions by. If None, contributions for all contexts will be returned.

  • top_k (int) – Number of unique categorical predictor values to return.

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

  • 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 for values outside the top-k. Default: True.

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

Return type:

polars.DataFrame

unique_contexts(context_infos: list[dict[str, str]] | None = None, with_partition_col: bool = False) list[dict[str, str]]

Get unique contexts list.

Parameters:
Return type:

list[dict[str, str]]