pdstools.explanations.ExplanationsUtils

Classes

_PREDICTOR_TYPE

Create a collection of name/value pairs.

_TABLE_NAME

Create a collection of name/value pairs.

_CONTRIBUTION_TYPE

Create a collection of name/value pairs.

_COL

Create a collection of name/value pairs.

_SPECIAL

Create a collection of name/value pairs.

_DEFAULT

Create a collection of name/value pairs.

ContextInfo

dict() -> new empty dictionary

ContextOperations

Context related operations such as to filter unique contexts.

Module Contents

class _PREDICTOR_TYPE(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

NUMERIC = 'NUMERIC'
SYMBOLIC = 'SYMBOLIC'
class _TABLE_NAME(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

NUMERIC = 'numeric'
SYMBOLIC = 'symbolic'
NUMERIC_OVERALL = 'numeric_overall'
SYMBOLIC_OVERALL = 'symbolic_overall'
CREATE = 'create'
MODEL_CONTEXTS = 'model_contexts'
class _CONTRIBUTION_TYPE(default, alt, text)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

alt
text
classmethod validate_and_get_type(val)

Get the accepted contribution type which is validated against user input

CONTRIBUTION = ('contribution', 'contribution', 'average contribution')
CONTRIBUTION_ABS = ('contribution_abs', '|contribution|', 'absolute average contribution')
CONTRIBUTION_WEIGHTED = ('contribution_weighted', 'contribution weighted', 'weighted average contribution')
CONTRIBUTION_WEIGHTED_ABS = ('contribution_weighted_abs', '|contribution weighted|', 'absolute weighted average contribution')
FREQUENCY = ('frequency', 'frequency', 'frequency')
CONTRIBUTION_MIN = ('contribution_min', 'contribution min', 'minimum contribution')
CONTRIBUTION_MAX = ('contribution_max', 'contribution max', 'maximum contribution')
class _COL(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

PARTITON = 'partition'
PREDICTOR_NAME = 'predictor_name'
PREDICTOR_TYPE = 'predictor_type'
BIN_CONTENTS = 'bin_contents'
BIN_ORDER = 'bin_order'
CONTRIBUTION = 'contribution'
CONTRIBUTION_ABS = 'contribution_abs'
CONTRIBUTION_MIN = 'contribution_min'
CONTRIBUTION_MAX = 'contribution_max'
CONTRIBUTION_WEIGHTED = 'contribution_weighted'
CONTRIBUTION_WEIGHTED_ABS = 'contribution_weighted_abs'
FREQUENCY = 'frequency'
class _SPECIAL(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

REMAINING = 'remaining'
TOTAL_FREQUENCY = 'total_frequency'
MISSING = 'missing'
class _DEFAULT(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

TOP_N = 20
TOP_K = 20
DESCENDING = True
MISSING = True
REMAINING = True
class ContextInfo

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

context_key: str
context_value: str
class ContextOperations(aggregate: pdstools.explanations.Aggregate.Aggregate)

Bases: pdstools.utils.namespaces.LazyNamespace

Context related operations such as to filter unique contexts.

Parameters:
aggregate(Aggregate)
Type:

The aggregate object.

_df(Optional[pl.DataFrame])
Type:

DataFrame containing context information.

_context_keys(Optional[list[str]])
Type:

list of context keys.

initialized(bool)
Type:

Flag indicating if the context operations have been initialized.

get_context_keys():

Returns the list of context keys from loaded data. Eg. [‘pyChannel’, ‘pyDirection’, …]

get_df(context_infos=None, with_partition_col=False):

Returns a DataFrame containing unique contexts If with_partition_col is True, includes the partition column. If context_infos is None, returns the full unique contexts, else filtered by the context Eg. with partition column: | pyChannel | pyDirection | … | partition | |-----------|————-|-----|———–| | channel1 | direction1 | … | {“partition”: {“pyChannel”: “channel1”, “pyDirection”: “direction1”}} | | channel1 | direction2 | … | {“partition”: {“pyChannel”: “channel1”, “pyDirection”: “direction2”}} |

get_list(context_infos=None, with_partition_col=False):

Returns a list[ContextInfo] containing unique contexts If with_partition_col is True, includes the partition column. If context_infos is None, returns the full unique contexts, else filtered by the context Eg. without partition column: [

{“pyChannel”: “channel1”, “pyDirection”: “direction1”, …}, {“pyChannel”: “channel1”, “pyDirection”: “direction2”, …},

]

get_context_info_str(context_info, sep="-"):

Returns a string representation of a single context information. Eg. channel1-direction1-…

dependencies = ['polars']
dependency_group = 'explanations'
aggregate
_df: polars.DataFrame | None = None
_context_keys: list[str] | None = None
initialized = False
_load()
get_context_keys()
get_df(context_infos: list[ContextInfo] | None = None, with_partition_col: bool = False) polars.DataFrame

Get the DataFrame filtered by the provided context information.

Parameters:
Return type:

polars.DataFrame

get_list(context_infos: list[ContextInfo] | None = None, with_partition_col: bool = False) list[ContextInfo]

Get the list of context information filtered by the provided context information.

Parameters:
Return type:

list[ContextInfo]

_filter_df_by_context_infos(df, context_infos)
static _get_filter_expression(context_infos)
static _get_clean_df(df: polars.DataFrame) polars.DataFrame
Parameters:

df (polars.DataFrame)

Return type:

polars.DataFrame

static get_context_info_str(context_info: ContextInfo, sep: str = '-') str
Parameters:
Return type:

str