arthurai.explainability.explanation_packager.ExplanationPackager#

class arthurai.explainability.explanation_packager.ExplanationPackager(model, **kwargs)#

Bases: object

Manages the project source code and explainer for this model. Intended only for internal use. Used to create explainer object, package files and format config for the update enrichments API endpoint.

See model.update_enrichments() for more details on usage

Methods

build_categorical_lookup_table

Builds the lookup table that ArthurExplainer needs for encoding strings

contains_file_fields

Returns (onePresent, allPresent) onePresent is true if at least one file field was supplied AllPresent is true if all file fields are supplied

copy_files

Copy the files that are required for testing the docker image.

create

Create an explainer for this model.

create_test_script

Create a test script.

get_request_config

Generates config dict for explainer.

get_request_files

Returns files needed for request, for use with model.update_enrichments

make_zip

Create the zip file for the project directory.

test

Download the docker container, install the files, and make sure the predict function can be run.

validate_requirements_add_sklearn

Checks the user requirements file to make sure versions are correct.

Attributes

FILE_FIELDS

build_categorical_lookup_table()#

Builds the lookup table that ArthurExplainer needs for encoding strings

Return type

List[Optional[Dict[str, int]]]

contains_file_fields()#

Returns (onePresent, allPresent) onePresent is true if at least one file field was supplied AllPresent is true if all file fields are supplied

Return type

Tuple[bool, bool]

copy_files(example)#

Copy the files that are required for testing the docker image.

Param

example: the example to use in the test script

Return type

None

create()#

Create an explainer for this model.

Param

df: the training data for the explainer

Param

shap_nrows: number of rows to sample the dataframe passed in

Return type

None

create_test_script(example)#

Create a test script.

Param

example:the example to use in the test script

Return type

str

Returns

the script contents

get_request_config()#

Generates config dict for explainer. For use with model.update_enrichments

Return type

Dict[str, str]

get_request_files()#

Returns files needed for request, for use with model.update_enrichments

Return type

List[Any]

make_zip()#

Create the zip file for the project directory.

Return type

None

test()#

Download the docker container, install the files, and make sure the predict function can be run.

Return type

None

validate_requirements_add_sklearn()#

Checks the user requirements file to make sure versions are correct.

Also handles making sure scikit-learn version is pinned in user requirements file, if it is installed in local environment and not specified.

scikit-learn is a dependency of shap, and arthurai doesn’t require scikit-learn explicitly. This can lead to version A being installed and used locally when pickling explainer, then version B getting installed on model server as part of shap install. This can lead to pickle errors, since the pickled version of shap (client side) used a different version of sklearn than what is on model server.

Return type

List[str]