Fix edge case in AnchorTabular where no samples satisfying the anchor… #742
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.
… exist in the train data
Fixes #317.
This is an edge case when no samples satisfying the anchor exist in the training data. For example, this can happen when explaining an instance with a categorical variable whose value is not observed in the training data.
The fix is minimal with no major logic changes:
partial_ancor_rows
accordinglytry/except
and break out of the sampling and go straight to handling unknown features if anIndexError
is raisedI have checked this on a toy example explaining an instance with a categorical variable whose value is not present in the training data. In this instance and with the dummy model used (prediction is the value of the categorical variable) the anchor should be the value of the categorical variable with precision 1 and coverage 0. The following snippet reproduces the result and compares it to the original anchor implementation (
pip install anchor-exp
):Note that warning messages are raised when there are no entries in the training data satisfying the feature value.