Add api.py for external API calls to OpenXAI #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Implemented an
OpenXAI
class inapi.py
to serve for external API calls.Example Usage
The returned
df_full
ordf_batch
are pandas dataframes with each row corresponds to a data sample. The number of columns is 2d + 3, where d is the feature dimension.The columns from left to right are: features (d), feature attribution scores (d), label (1), predicted label (1), and is_test flag (1).
Test
The code has been successfully tested on 3 datasets ("compas", "adult", "german"), 2 models ("ann", "lr"), and 6 explainers ("grad", "sg", "itg", "ig", "shap", "lime").
To reproduce the test, run
python openxai/api.py
under the root of this repo.Note: Currently there seems to be path issues for this API to be used externally. The issue is possibly due to the path usage by
LoadModel
, which should be fixed in a separate PR.