alibi.api.interfaces module

class alibi.api.interfaces.AlibiPrettyPrinter(*args, **kwargs)[source]

Bases: PrettyPrinter

Overrides the built in dictionary pretty representation to look more similar to the external prettyprinter libary.

class alibi.api.interfaces.Base(meta=_Nothing.NOTHING)[source]

Bases: object

Base class for all alibi algorithms. Implements a structured approach to handle metadata.

meta: dict

Object metadata.

class alibi.api.interfaces.Explainer(meta=_Nothing.NOTHING)[source]

Bases: ABC, Base

Base class for explainer algorithms from alibi.explainers.

abstract explain(X)[source]
Return type:

Explanation

classmethod load(path, predictor)[source]

Load an explainer from disk.

Parameters:
  • path (Union[str, PathLike]) – Path to a directory containing the saved explainer.

  • predictor (Any) – Model or prediction function used to originally initialize the explainer.

Return type:

Explainer

Returns:

An explainer instance.

reset_predictor(predictor)[source]

Resets the predictor.

Parameters:

predictor (Any) – New predictor.

Return type:

None

save(path)[source]

Save an explainer to disk. Uses the dill module.

Parameters:

path (Union[str, PathLike]) – Path to a directory. A new directory will be created if one does not exist.

Return type:

None

class alibi.api.interfaces.Explanation(meta, data)[source]

Bases: object

Explanation class returned by explainers.

__attrs_post_init__()[source]

Expose keys stored in self.meta and self.data as attributes of the class.

__getitem__(item)[source]

This method is purely for deprecating previous behaviour of accessing explanation data via items in the returned dictionary.

data: dict
classmethod from_json(jsonrepr)[source]

Create an instance of an Explanation class using a json representation of the Explanation.

Parameters:

jsonreprjson representation of an explanation.

Return type:

Explanation

Returns:

An Explanation object.

meta: dict
to_json()[source]

Serialize the explanation data and metadata into a json format.

Return type:

str

Returns:

String containing json representation of the explanation.

class alibi.api.interfaces.FitMixin[source]

Bases: ABC

abstract fit(X)[source]
Return type:

Explainer

class alibi.api.interfaces.Summariser(meta=_Nothing.NOTHING)[source]

Bases: ABC, Base

Base class for prototype algorithms from alibi.prototypes.

classmethod load(path)[source]
Return type:

Summariser

save(path)[source]
Return type:

None

abstract summarise(num_prototypes)[source]
Return type:

Explanation

alibi.api.interfaces.default_meta()[source]
Return type:

dict