Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

visualize_as_dataframe(show_only_changes=True) does not work when categorical data is composed of numbers #384

Open
mimicarina opened this issue Jul 8, 2023 · 0 comments

Comments

@mimicarina
Copy link

mimicarina commented Jul 8, 2023

levels.append(self.categorical_levels[cat_feature])

When categorical columns contain numerical levels (e.g. yes - 1, no - 0) visualize_as_dataframe(show_only_changes=True) (and also visualize_as_list()) does not work, as it encodes the string values to numerical.

Example dataset: https://archive.ics.uci.edu/ml/machine-learning-databases/00573/SouthGermanCredit.zip.

During data prep, categorical values are encoded as 'category' data type (see query instance below). The counterfactual uses numeric representation; hence it will show as 'changed' value even though it is the same category (e.g. '2' vs 2).

Query instance (original outcome : 1)
['1', 21, '2', '2', 3599, '1', '4', '1', '2', '1', '4', '3', '3', '1', '1', '2', '2', '1', '2', '1', 1]

Diverse Counterfactual set (new outcome: 0.0)
[1, '-', 2, 2, 17507, 1, 4, 1, 2, 1, 4, 3, 3, 1, 1, 2, 2, '2', 2, 1, 0]
[1, '-', '0', 2, '-', 1, '-', 1, 2, 1, 4, 3, 3, 1, 1, 2, 2, 1, 2, 1, 0]

This is happening because train_data[cat_feature].cat.categories.tolist() returns integer and not categories/strings; for sample dataset above the categories and levels are:

['credit_history', 'foreign_worker', 'housing', 'other_debtors', 'other_installment_plans', 'people_liable', 'personal_status_sex', 'purpose', 'savings', 'status', 'telephone', 'employment_duration', 'installment_rate', 'job', 'number_credits', 'present_residence', 'property']
[[0, 1, 2, 3, 4], [1, 2], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2], [1, 2, 3, 4], [0, 1, 2, 3, 4, 5, 6, 8, 9, 10], [1, 2, 3, 4, 5], [1, 2, 3, 4], [1, 2], [1, 2, 3, 4, 5], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant