fix sorting of dataframe for aequitas calculations during evaluations #858
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.
Currently, the attributes for bias analysis via
aequitas
are getting scrambled relative to the scores and labels when the latter get sorted for "best case" and "worst case" analyses. To fix this issue, this PR sorts the index (e.g., theentity_id
,as_of_date
tuple) as well, then applies this re-sorted index to the dataframe with the attributes used foraequitas
calculations.Also note that I added a check that raises a
ValueError
if there is a mismatch between the indices for theprotected_df
and labels (the must have the same shape and sets of unique values). This will enforce thatprotected_df
covers the full set of entities and has no duplicates, which I don't think is an unreasonable requirement for running the bias analysis, but if anyone disagrees, we can remove the check.