Skip to content

counterfactual-explanation.md's worked example crashes with a TypeError and uses columns the real dataset doesn't have #641

Description

@yakew7

Where: explainers/counterfactual-explanation.md's nearest_counterfactual() and its "ORIGINAL APPLICATION" worked example.

Bug 1 - TypeError on the file's own worked example: the example instance (credit_amount: 4800, duration_months: 36, employment_years: 1, existing_credits: 2 - all whole numbers) is built into a pandas Series, which infers int64 dtype. nearest_counterfactual()'s perturbation step (candidate[feature] = np.clip(candidate[feature] + delta, low, high)) then tries to write a float perturbation into that int64 slot:

TypeError: Invalid value '...' for dtype 'int64'

(confirmed under pandas 3.0.3, the version pinned in requirements-lock.txt, using the file's own example values).

Bug 2 - nonexistent columns: the same worked example and its "Usage example" use duration_months and employment_years. The real German Credit Lending/credit_customers.csv (the dataset this repo's unfair.py/fair.py/audit.yaml actually use) has no such columns - the real columns are duration (numeric months) and employment (a categorical bucket: '>=7', '1<=X<4', '4<=X<7', 'unemployed', '<1'), not a plain integer year count.

Fix direction: cast the instance Series to float64 before perturbation (fixing bug 1 in a dataset-independent way), and rename the worked example's columns to the real duration/employment (adjusting the employment value to a real bucket string rather than an integer year count, fixing bug 2).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions