pyreal.explanation_types.example_based.ExampleBasedExplanation#

class pyreal.explanation_types.example_based.ExampleBasedExplanation(explanation, values=None)[source]#

A type wrapper for example-based type outputs from explanation algorithms.

Example-based types include dictionary linking input rows to DataFrames, and optionally

a second dictionary linking the same input rows to Series, where the DataFrames are examples (X) for the corresponding row and the Series are the corresponding target (y) values. The row order wil depend on the specific input type.

__init__(explanation, values=None)#

Set the wrapped explanation to explanation and values to values and validate :param explanation: wrapped explanation :type explanation: object :param values: Values corresponding with the object being explained :type values: DataFrame of shape (n_instances, n_features) or None

Methods

__init__(explanation[, values])

Set the wrapped explanation to explanation and values to values and validate :param explanation: wrapped explanation :type explanation: object :param values: Values corresponding with the object being explained :type values: DataFrame of shape (n_instances, n_features) or None

apply_feature_descriptions(feature_descriptions)

Apply feature descriptions to examples

get()

Get the explanation wrapped by this type.

get_all()

Get the explanation and wrapped values as a tuple.

get_examples([row_id, rank])

Get the example in rank-th position for the given row_id. :param row_id: ID of row to get explanation of. :type row_id: int :param rank: Which example to return (ie, rank=0 returns the first example generated). If none, return all examples :type rank: int.

get_explanation()

Get the explanation wrapped by this type

get_row_ids()

Return all row_ids held by this explanation

get_targets([row_id, rank])

Get the targets in rank-th position for the given row_id. :param row_id: ID of row to get explanation of. :type row_id: int :param rank: Which example to return (ie, rank=0 returns the first example generated). If none, return all examples :type rank: int.

get_values()

Return the values associated with the explanation

update_examples(func[, inplace])

Update every example using the provided function :param func: Function to apply to every example :type func: function :param inplace: If True, change the explanation on this object. Otherwise, create a new object identical to this one but with a new explanation :type inplace: Boolean.

update_explanation(new_explanation[, ...])

Sets this object's explanation to the new value.

update_values(values[, inplace])

Updates this objects values, and validates

validate()

Validate that self.explanation is of the expected format.

validate_values()

Validate that self.values are valid values for this Explanation.