Estimating local and global feature importance scores using DiCE

Summaries of counterfactual examples can be used to estimate importance of features. Intuitively, a feature that is changed more often to generate a proximal counterfactual is an important feature. We use this intuition to build a feature importance score.

This score can be interpreted as a measure of the necessity of a feature to cause a particular model output. That is, if the feature’s value changes, then it is likely that the model’s output class will also change (or the model’s output will significantly change in case of regression model).

Below we show how counterfactuals can be used to provide local feature importance scores for any input, and how those scores can be combined to yield a global importance score for each feature.

[1]:
from sklearn.compose import ColumnTransformer
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.ensemble import RandomForestClassifier

import dice_ml
from dice_ml import Dice
from dice_ml.utils import helpers  # helper functions
/mnt/c/Users/amshar/code/dice/dice_ml/utils/exception.py:12: UserWarning: UserConfigValidationException will be deprecated from dice_ml.utils. Please import UserConfigValidationException from raiutils.exceptions.
  warnings.warn("UserConfigValidationException will be deprecated from dice_ml.utils. "
[2]:
%load_ext autoreload
%autoreload 2

Preliminaries: Loading the data and ML model

[3]:
dataset = helpers.load_adult_income_dataset().sample(5000)  # downsampling to reduce ML model fitting time
helpers.get_adult_data_info()
[3]:
{'age': 'age',
 'workclass': 'type of industry (Government, Other/Unknown, Private, Self-Employed)',
 'education': 'education level (Assoc, Bachelors, Doctorate, HS-grad, Masters, Prof-school, School, Some-college)',
 'marital_status': 'marital status (Divorced, Married, Separated, Single, Widowed)',
 'occupation': 'occupation (Blue-Collar, Other/Unknown, Professional, Sales, Service, White-Collar)',
 'race': 'white or other race?',
 'gender': 'male or female?',
 'hours_per_week': 'total work hours per week',
 'income': '0 (<=50K) vs 1 (>50K)'}
[4]:
target = dataset["income"]

# Split data into train and test
datasetX = dataset.drop("income", axis=1)
x_train, x_test, y_train, y_test = train_test_split(datasetX,
                                                    target,
                                                    test_size=0.2,
                                                    random_state=0,
                                                    stratify=target)

numerical = ["age", "hours_per_week"]
categorical = x_train.columns.difference(numerical)

# We create the preprocessing pipelines for both numeric and categorical data.
numeric_transformer = Pipeline(steps=[
    ('scaler', StandardScaler())])

categorical_transformer = Pipeline(steps=[
    ('onehot', OneHotEncoder(handle_unknown='ignore'))])

transformations = ColumnTransformer(
    transformers=[
        ('num', numeric_transformer, numerical),
        ('cat', categorical_transformer, categorical)])

# Append classifier to preprocessing pipeline.
# Now we have a full prediction pipeline.
clf = Pipeline(steps=[('preprocessor', transformations),
                      ('classifier', RandomForestClassifier())])
model = clf.fit(x_train, y_train)
[5]:
d = dice_ml.Data(dataframe=dataset, continuous_features=['age', 'hours_per_week'], outcome_name='income')
m = dice_ml.Model(model=model, backend="sklearn")

Local feature importance

We first generate counterfactuals for a given input point.

[6]:
exp = Dice(d, m, method="random")
query_instance = x_train[1:2]
e1 = exp.generate_counterfactuals(query_instance, total_CFs=10, desired_range=None,
                                  desired_class="opposite",
                                  permitted_range=None, features_to_vary="all")
e1.visualize_as_dataframe(show_only_changes=True)
100%|█████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  1.86it/s]
Query instance (original outcome : 0)

age workclass education marital_status occupation race gender hours_per_week income
0 32 Other/Unknown Some-college Divorced Other/Unknown White Male 40 0

Diverse Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 69.0 - - Married - - - - 1
1 - - Doctorate Married - - - - 1
2 56.0 - - Married - - - - 1
3 49.0 - - Married - - - - 1
4 53.0 - - Married - - - - 1
5 48.0 - - Married - - - - 1
6 - - Bachelors - Sales - - - 1
7 83.0 - - Married - - - - 1
8 - - Prof-school - Professional - - - 1
9 - Private - - Blue-Collar - - - 1

These can now be used to calculate the feature importance scores.

[7]:
imp = exp.local_feature_importance(query_instance, cf_examples_list=e1.cf_examples_list)
print(imp.local_importance)
[{'marital_status': 0.7, 'age': 0.6, 'education': 0.3, 'occupation': 0.3, 'workclass': 0.1, 'race': 0.0, 'gender': 0.0, 'hours_per_week': 0.0}]

Feature importance can also be estimated directly, by leaving the cf_examples_list argument blank.

[8]:
imp = exp.local_feature_importance(query_instance, posthoc_sparsity_param=None)
print(imp.local_importance)
100%|█████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.70it/s]
[{'education': 0.5, 'marital_status': 0.5, 'age': 0.5, 'occupation': 0.4, 'hours_per_week': 0.3, 'workclass': 0.1, 'race': 0.0, 'gender': 0.0}]

Global importance

For global importance, we need to generate counterfactuals for a representative sample of the dataset.

[9]:
cobj = exp.global_feature_importance(x_train[0:10], total_CFs=10, posthoc_sparsity_param=None)
print(cobj.summary_importance)
100%|███████████████████████████████████████████████████████████████████████████████████| 10/10 [00:02<00:00,  3.55it/s]
{'age': 0.65, 'marital_status': 0.48, 'education': 0.36, 'occupation': 0.26, 'hours_per_week': 0.24, 'workclass': 0.08, 'race': 0.06, 'gender': 0.04}

Convert the counterfactual output to json

[10]:
json_str = cobj.to_json()
print(json_str)
{"test_data": [[[39, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 50, 1]], [[32, "Other/Unknown", "Some-college", "Divorced", "Other/Unknown", "White", "Male", 40, 0]], [[32, "Private", "Some-college", "Married", "Service", "White", "Male", 50, 0]], [[46, "Private", "Masters", "Married", "Professional", "White", "Male", 35, 1]], [[20, "Other/Unknown", "HS-grad", "Single", "Other/Unknown", "White", "Male", 32, 0]], [[29, "Private", "Some-college", "Married", "Blue-Collar", "Other", "Male", 40, 1]], [[39, "Self-Employed", "Masters", "Married", "Professional", "White", "Female", 40, 1]], [[31, "Private", "School", "Single", "Blue-Collar", "White", "Male", 25, 0]], [[45, "Private", "Masters", "Married", "White-Collar", "White", "Male", 43, 1]], [[28, "Private", "HS-grad", "Single", "White-Collar", "White", "Female", 20, 0]]], "cfs_list": [[[39, "Private", "HS-grad", "Widowed", "Blue-Collar", "White", "Male", 54.0, 0], [26.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Male", 50, 0], [52.0, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 50, 0], [90.0, "Private", "HS-grad", "Married", "Sales", "White", "Male", 50, 0], [25.0, "Private", "HS-grad", "Married", "Other/Unknown", "White", "Male", 50, 0], [39, "Private", "HS-grad", "Widowed", "Sales", "White", "Male", 50, 0], [34.0, "Private", "HS-grad", "Separated", "Blue-Collar", "White", "Male", 50, 0], [30.0, "Private", "HS-grad", "Separated", "Blue-Collar", "White", "Male", 50, 0], [78.0, "Private", "HS-grad", "Married", "Blue-Collar", "Other", "Male", 50, 0], [78.0, "Private", "HS-grad", "Married", "Service", "White", "Male", 50, 0]], [[81.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 40, 1], [40.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 40, 1], [41.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 40, 1], [32, "Other/Unknown", "HS-grad", "Married", "Other/Unknown", "White", "Male", 40, 1], [32, "Private", "Some-college", "Divorced", "Blue-Collar", "White", "Male", 40, 1], [85.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 40, 1], [32, "Other/Unknown", "Prof-school", "Divorced", "Other/Unknown", "White", "Male", 52.0, 0], [56.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 40, 1], [57.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 40, 1], [44.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 40, 1]], [[55.0, "Private", "Some-college", "Married", "Service", "White", "Male", 95.0, 1], [32, "Private", "Assoc", "Married", "White-Collar", "White", "Male", 50, 1], [32, "Private", "Masters", "Married", "Service", "White", "Female", 50, 1], [84.0, "Private", "Some-college", "Married", "Service", "White", "Male", 50, 1], [32, "Private", "Some-college", "Married", "White-Collar", "White", "Male", 68.0, 1], [80.0, "Private", "Some-college", "Married", "Service", "White", "Male", 50, 1], [55.0, "Private", "Some-college", "Married", "Service", "White", "Male", 50, 1], [81.0, "Private", "Some-college", "Married", "Service", "White", "Male", 50, 1], [87.0, "Private", "Some-college", "Married", "Service", "Other", "Male", 50, 1], [32, "Private", "Prof-school", "Married", "Sales", "White", "Male", 50, 1]], [[46, "Private", "Bachelors", "Married", "Other/Unknown", "White", "Male", 35, 0], [46, "Private", "Masters", "Single", "Professional", "White", "Male", 27.0, 0], [19.0, "Private", "Masters", "Married", "Other/Unknown", "White", "Male", 35, 0], [46, "Private", "Some-college", "Married", "Professional", "White", "Female", 35, 0], [46, "Private", "Masters", "Married", "Other/Unknown", "White", "Male", 4.0, 0], [46, "Private", "Masters", "Widowed", "Blue-Collar", "White", "Male", 35, 0], [46, "Other/Unknown", "Masters", "Married", "Professional", "White", "Male", 64.0, 0], [24.0, "Private", "Masters", "Married", "Professional", "White", "Male", 47.0, 0], [46, "Private", "Masters", "Widowed", "Service", "White", "Male", 35, 0], [46, "Private", "School", "Married", "Professional", "Other", "Male", 35, 0]], [[65.0, "Private", "Prof-school", "Single", "Other/Unknown", "White", "Male", 32, 1], [59.0, "Other/Unknown", "Prof-school", "Separated", "Other/Unknown", "White", "Male", 52.0, 1], [42.0, "Self-Employed", "Prof-school", "Single", "Blue-Collar", "White", "Male", 32, 1], [55.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 32, 1], [47.0, "Other/Unknown", "Prof-school", "Single", "Professional", "White", "Male", 32, 1], [58.0, "Other/Unknown", "Doctorate", "Married", "Service", "White", "Male", 32, 1], [67.0, "Self-Employed", "Prof-school", "Single", "Other/Unknown", "White", "Male", 32, 1], [49.0, "Other/Unknown", "Prof-school", "Single", "Sales", "White", "Male", 32, 1], [42.0, "Other/Unknown", "Prof-school", "Single", "Other/Unknown", "White", "Male", 32, 1], [63.0, "Government", "Prof-school", "Married", "Other/Unknown", "White", "Male", 32, 1]], [[29, "Private", "Assoc", "Married", "Blue-Collar", "Other", "Male", 40, 0], [28.0, "Private", "Some-college", "Married", "Blue-Collar", "Other", "Male", 67.0, 0], [29, "Private", "Some-college", "Divorced", "Blue-Collar", "Other", "Male", 40, 0], [85.0, "Private", "Some-college", "Married", "Blue-Collar", "Other", "Male", 40, 0], [49.0, "Private", "Some-college", "Separated", "Blue-Collar", "Other", "Male", 40, 0], [29, "Private", "Some-college", "Married", "Blue-Collar", "Other", "Male", 13.0, 0], [29, "Private", "Some-college", "Widowed", "Blue-Collar", "Other", "Male", 39.0, 0], [29, "Private", "Doctorate", "Divorced", "Blue-Collar", "Other", "Male", 40, 0], [29, "Private", "Masters", "Married", "Blue-Collar", "Other", "Male", 18.0, 0], [28.0, "Private", "Some-college", "Married", "Professional", "Other", "Male", 40, 0]], [[39, "Government", "Masters", "Divorced", "Professional", "White", "Female", 40, 0], [39, "Self-Employed", "Masters", "Married", "Blue-Collar", "White", "Female", 40, 0], [66.0, "Self-Employed", "Masters", "Widowed", "Professional", "White", "Female", 40, 0], [39, "Self-Employed", "Masters", "Separated", "Professional", "White", "Female", 38.0, 0], [27.0, "Self-Employed", "Some-college", "Married", "Professional", "White", "Female", 40, 0], [41.0, "Self-Employed", "Masters", "Widowed", "Professional", "White", "Female", 40, 0], [39, "Self-Employed", "Masters", "Divorced", "Professional", "Other", "Female", 40, 0], [39, "Self-Employed", "Masters", "Divorced", "Service", "White", "Female", 40, 0], [20.0, "Self-Employed", "Masters", "Married", "Professional", "White", "Female", 40, 0], [39, "Self-Employed", "Masters", "Widowed", "Professional", "White", "Female", 40, 0]], [[31, "Private", "Masters", "Married", "Blue-Collar", "White", "Male", 98.0, 1], [89.0, "Private", "School", "Married", "Blue-Collar", "White", "Male", 61.0, 1], [78.0, "Private", "School", "Married", "Blue-Collar", "White", "Male", 69.0, 1], [65.0, "Private", "Doctorate", "Single", "White-Collar", "White", "Male", 16.0, 1], [78.0, "Private", "School", "Married", "Blue-Collar", "White", "Male", 85.0, 1], [39.0, "Private", "Prof-school", "Single", "Professional", "Other", "Male", 25, 1], [62.0, "Private", "School", "Married", "Blue-Collar", "White", "Male", 61.0, 1], [31, "Private", "Doctorate", "Married", "Other/Unknown", "White", "Male", 25, 1], [46.0, "Private", "Prof-school", "Married", "Blue-Collar", "White", "Male", 25, 1], [65.0, "Private", "Doctorate", "Single", "White-Collar", "White", "Male", 25, 1]], [[45, "Private", "Masters", "Separated", "Sales", "White", "Male", 43, 0], [35.0, "Private", "Masters", "Separated", "White-Collar", "White", "Male", 43, 0], [62.0, "Private", "School", "Married", "White-Collar", "White", "Male", 43, 0], [17.0, "Private", "Masters", "Married", "White-Collar", "Other", "Male", 43, 0], [45, "Private", "Assoc", "Separated", "White-Collar", "White", "Male", 43, 0], [28.0, "Private", "Masters", "Single", "White-Collar", "White", "Male", 43, 0], [25.0, "Private", "Masters", "Married", "White-Collar", "White", "Male", 43, 0], [49.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Male", 43, 0], [45, "Private", "School", "Married", "White-Collar", "White", "Male", 9.0, 0], [45, "Private", "Masters", "Separated", "White-Collar", "White", "Male", 4.0, 0]], [[42.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Female", 20, 1], [53.0, "Other/Unknown", "Doctorate", "Single", "White-Collar", "White", "Female", 20, 0], [34.0, "Private", "Masters", "Single", "White-Collar", "White", "Female", 60.0, 1], [67.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Female", 20, 1], [87.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Female", 20, 1], [46.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Female", 20, 1], [72.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Female", 20, 1], [42.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Female", 93.0, 1], [42.0, "Private", "Prof-school", "Single", "White-Collar", "White", "Male", 20, 1], [55.0, "Private", "Prof-school", "Single", "White-Collar", "White", "Male", 20, 1]]], "local_importance": [[0.8, 0.0, 0.0, 0.4, 0.5, 0.1, 0.0, 0.1], [0.7, 0.1, 0.2, 0.8, 0.1, 0.0, 0.0, 0.1], [0.6, 0.0, 0.3, 0.0, 0.3, 0.1, 0.1, 0.2], [0.2, 0.1, 0.3, 0.3, 0.5, 0.1, 0.1, 0.4], [1.0, 0.4, 1.0, 0.4, 0.4, 0.0, 0.0, 0.1], [0.4, 0.0, 0.3, 0.4, 0.1, 0.0, 0.0, 0.4], [0.4, 0.1, 0.1, 0.7, 0.2, 0.1, 0.0, 0.1], [0.8, 0.0, 0.6, 0.7, 0.4, 0.1, 0.0, 0.6], [0.6, 0.0, 0.4, 0.5, 0.1, 0.1, 0.0, 0.2], [1.0, 0.1, 0.4, 0.6, 0.0, 0.0, 0.2, 0.2]], "summary_importance": [0.65, 0.08, 0.36, 0.48, 0.26, 0.06, 0.04, 0.24], "data_interface": {"outcome_name": "income", "data_df": "dummy_data"}, "feature_names": ["age", "workclass", "education", "marital_status", "occupation", "race", "gender", "hours_per_week"], "feature_names_including_target": ["age", "workclass", "education", "marital_status", "occupation", "race", "gender", "hours_per_week", "income"], "model_type": "classifier", "desired_class": "opposite", "desired_range": null, "metadata": {"version": "2.0"}}

Convert the json output to a counterfactual object

[11]:
imp_r = imp.from_json(json_str)
print([o.visualize_as_dataframe(show_only_changes=True) for o in imp_r.cf_examples_list])
print(imp_r.local_importance)
print(imp_r.summary_importance)
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 39 Private HS-grad Married Blue-Collar White Male 50 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - - Widowed - - - 54.0 0
1 26.0 - - - White-Collar - - - 0
2 52.0 - - - - - - - 0
3 90.0 - - - Sales - - - 0
4 25.0 - - - Other/Unknown - - - 0
5 - - - Widowed Sales - - - 0
6 34.0 - - Separated - - - - 0
7 30.0 - - Separated - - - - 0
8 78.0 - - - - Other - - 0
9 78.0 - - - Service - - - 0
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 32 Other/Unknown Some-college Divorced Other/Unknown White Male 40 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 81.0 - - Married - - - - 1
1 40.0 - - Married - - - - 1
2 41.0 - - Married - - - - 1
3 - - HS-grad Married - - - - 1
4 - Private - - Blue-Collar - - - 1
5 85.0 - - Married - - - - 1
6 - - Prof-school - - - - 52.0 -
7 56.0 - - Married - - - - 1
8 57.0 - - Married - - - - 1
9 44.0 - - Married - - - - 1
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 32 Private Some-college Married Service White Male 50 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 55.0 - - - - - - 95.0 1
1 - - Assoc - White-Collar - - - 1
2 - - Masters - - - Female - 1
3 84.0 - - - - - - - 1
4 - - - - White-Collar - - 68.0 1
5 80.0 - - - - - - - 1
6 55.0 - - - - - - - 1
7 81.0 - - - - - - - 1
8 87.0 - - - - Other - - 1
9 - - Prof-school - Sales - - - 1
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 46 Private Masters Married Professional White Male 35 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - Bachelors - Other/Unknown - - - 0
1 - - - Single - - - 27.0 0
2 19.0 - - - Other/Unknown - - - 0
3 - - Some-college - - - Female - 0
4 - - - - Other/Unknown - - 4.0 0
5 - - - Widowed Blue-Collar - - - 0
6 - Other/Unknown - - - - - 64.0 0
7 24.0 - - - - - - 47.0 0
8 - - - Widowed Service - - - 0
9 - - School - - Other - - 0
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 20 Other/Unknown HS-grad Single Other/Unknown White Male 32 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 65.0 Private Prof-school - - - - - 1
1 59.0 - Prof-school Separated - - - 52.0 1
2 42.0 Self-Employed Prof-school - Blue-Collar - - - 1
3 55.0 - Some-college Married - - - - 1
4 47.0 - Prof-school - Professional - - - 1
5 58.0 - Doctorate Married Service - - - 1
6 67.0 Self-Employed Prof-school - - - - - 1
7 49.0 - Prof-school - Sales - - - 1
8 42.0 - Prof-school - - - - - 1
9 63.0 Government Prof-school Married - - - - 1
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 29 Private Some-college Married Blue-Collar Other Male 40 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - Assoc - - - - - 0
1 28.0 - - - - - - 67.0 0
2 - - - Divorced - - - - 0
3 85.0 - - - - - - - 0
4 49.0 - - Separated - - - - 0
5 - - - - - - - 13.0 0
6 - - - Widowed - - - 39.0 0
7 - - Doctorate Divorced - - - - 0
8 - - Masters - - - - 18.0 0
9 28.0 - - - Professional - - - 0
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 39 Self-Employed Masters Married Professional White Female 40 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - Government - Divorced - - - - 0
1 - - - - Blue-Collar - - - 0
2 66.0 - - Widowed - - - - 0
3 - - - Separated - - - 38.0 0
4 27.0 - Some-college - - - - - 0
5 41.0 - - Widowed - - - - 0
6 - - - Divorced - Other - - 0
7 - - - Divorced Service - - - 0
8 20.0 - - - - - - - 0
9 - - - Widowed - - - - 0
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 31 Private School Single Blue-Collar White Male 25 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - Masters Married - - - 98.0 1
1 89.0 - - Married - - - 61.0 1
2 78.0 - - Married - - - 69.0 1
3 65.0 - Doctorate - White-Collar - - 16.0 1
4 78.0 - - Married - - - 85.0 1
5 39.0 - Prof-school - Professional Other - - 1
6 62.0 - - Married - - - 61.0 1
7 - - Doctorate Married Other/Unknown - - - 1
8 46.0 - Prof-school Married - - - - 1
9 65.0 - Doctorate - White-Collar - - - 1
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 45 Private Masters Married White-Collar White Male 43 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - - Separated Sales - - - 0
1 35.0 - - Separated - - - - 0
2 62.0 - School - - - - - 0
3 17.0 - - - - Other - - 0
4 - - Assoc Separated - - - - 0
5 28.0 - - Single - - - - 0
6 25.0 - - - - - - - 0
7 49.0 - HS-grad - - - - - 0
8 - - School - - - - 9.0 0
9 - - - Separated - - - 4.0 0
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 28 Private HS-grad Single White-Collar White Female 20 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 42.0 - - Married - - - - 1
1 53.0 Other/Unknown Doctorate - - - - - -
2 34.0 - Masters - - - - 60.0 1
3 67.0 - - Married - - - - 1
4 87.0 - - Married - - - - 1
5 46.0 - - Married - - - - 1
6 72.0 - - Married - - - - 1
7 42.0 - - Married - - - 93.0 1
8 42.0 - Prof-school - - - Male - 1
9 55.0 - Prof-school - - - Male - 1
[None, None, None, None, None, None, None, None, None, None]
[{'age': 0.8, 'occupation': 0.5, 'marital_status': 0.4, 'race': 0.1, 'hours_per_week': 0.1, 'workclass': 0.0, 'education': 0.0, 'gender': 0.0}, {'marital_status': 0.8, 'age': 0.7, 'education': 0.2, 'workclass': 0.1, 'occupation': 0.1, 'hours_per_week': 0.1, 'race': 0.0, 'gender': 0.0}, {'age': 0.6, 'education': 0.3, 'occupation': 0.3, 'hours_per_week': 0.2, 'race': 0.1, 'gender': 0.1, 'workclass': 0.0, 'marital_status': 0.0}, {'occupation': 0.5, 'hours_per_week': 0.4, 'education': 0.3, 'marital_status': 0.3, 'age': 0.2, 'workclass': 0.1, 'race': 0.1, 'gender': 0.1}, {'age': 1.0, 'education': 1.0, 'workclass': 0.4, 'marital_status': 0.4, 'occupation': 0.4, 'hours_per_week': 0.1, 'race': 0.0, 'gender': 0.0}, {'age': 0.4, 'marital_status': 0.4, 'hours_per_week': 0.4, 'education': 0.3, 'occupation': 0.1, 'workclass': 0.0, 'race': 0.0, 'gender': 0.0}, {'marital_status': 0.7, 'age': 0.4, 'occupation': 0.2, 'workclass': 0.1, 'education': 0.1, 'race': 0.1, 'hours_per_week': 0.1, 'gender': 0.0}, {'age': 0.8, 'marital_status': 0.7, 'education': 0.6, 'hours_per_week': 0.6, 'occupation': 0.4, 'race': 0.1, 'workclass': 0.0, 'gender': 0.0}, {'age': 0.6, 'marital_status': 0.5, 'education': 0.4, 'hours_per_week': 0.2, 'occupation': 0.1, 'race': 0.1, 'workclass': 0.0, 'gender': 0.0}, {'age': 1.0, 'marital_status': 0.6, 'education': 0.4, 'gender': 0.2, 'hours_per_week': 0.2, 'workclass': 0.1, 'occupation': 0.0, 'race': 0.0}]
{'age': 0.65, 'marital_status': 0.48, 'education': 0.36, 'occupation': 0.26, 'hours_per_week': 0.24, 'workclass': 0.08, 'race': 0.06, 'gender': 0.04}