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
[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,  2.24it/s]
Query instance (original outcome : 1)

age workclass education marital_status occupation race gender hours_per_week income
0 42 Private Some-college Married Blue-Collar White Male 89 1

Diverse Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - - Widowed Professional - - - 0
1 - Self-Employed - - - - - 67.0 0
2 - - - - - - - 40.0 0
3 58.0 - - - - - - 65.0 0
4 - Other/Unknown - - - - - 74.0 0
5 - - - - - - - 28.0 0
6 - - - Divorced - - Female - 0
7 28.0 - - - - - - 37.0 0
8 - Other/Unknown - Single - - - - 0
9 - Government - - - - - - 0

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)
[{'hours_per_week': 0.6, 'workclass': 0.4, 'marital_status': 0.3, 'age': 0.2, 'occupation': 0.1, 'gender': 0.1, 'education': 0.0, 'race': 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,  7.09it/s]
[{'age': 0.4, 'hours_per_week': 0.4, 'workclass': 0.2, 'education': 0.2, 'marital_status': 0.2, 'occupation': 0.2, 'gender': 0.2, 'race': 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:01<00:00,  5.27it/s]
{'marital_status': 0.57, 'education': 0.49, 'age': 0.48, 'hours_per_week': 0.42, 'occupation': 0.33, 'workclass': 0.17, 'gender': 0.14, 'race': 0.12}

Convert the counterfactual output to json

[10]:
json_str = cobj.to_json()
print(json_str)
{"test_data": [[[44, "Private", "HS-grad", "Married", "Sales", "White", "Male", 40, 0]], [[42, "Private", "Some-college", "Married", "Blue-Collar", "White", "Male", 89, 1]], [[21, "Self-Employed", "Some-college", "Single", "Service", "White", "Male", 30, 0]], [[24, "Private", "HS-grad", "Single", "White-Collar", "White", "Female", 40, 0]], [[60, "Private", "School", "Married", "Sales", "White", "Male", 40, 1]], [[51, "Private", "HS-grad", "Divorced", "Blue-Collar", "White", "Male", 40, 0]], [[23, "Private", "School", "Single", "Blue-Collar", "White", "Female", 38, 0]], [[19, "Other/Unknown", "HS-grad", "Single", "Other/Unknown", "Other", "Female", 40, 0]], [[28, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Female", 40, 1]], [[34, "Private", "Bachelors", "Married", "Professional", "White", "Male", 40, 1]]], "cfs_list": [[[44, "Private", "Assoc", "Married", "Professional", "White", "Male", 40, 1], [44, "Private", "Bachelors", "Married", "White-Collar", "White", "Male", 40, 1], [44, "Private", "HS-grad", "Married", "Sales", "White", "Male", 85.0, 1], [59.0, "Private", "HS-grad", "Married", "Sales", "White", "Male", 71.0, 1], [44, "Government", "Masters", "Married", "Sales", "White", "Male", 40, 1], [44, "Private", "HS-grad", "Married", "Sales", "Other", "Male", 93.0, 1], [44, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 92.0, 1], [44, "Private", "Masters", "Married", "Sales", "Other", "Male", 40, 1], [56.0, "Private", "HS-grad", "Married", "Sales", "White", "Male", 52.0, 1], [44, "Private", "HS-grad", "Married", "White-Collar", "White", "Male", 23.0, 1]], [[42, "Private", "Some-college", "Married", "Blue-Collar", "White", "Male", 50.0, 0], [42, "Private", "Some-college", "Married", "Blue-Collar", "Other", "Male", 1.0, 0], [42, "Private", "Some-college", "Single", "Blue-Collar", "White", "Male", 6.0, 0], [19.0, "Private", "Some-college", "Married", "Blue-Collar", "White", "Male", 68.0, 0], [42, "Private", "Some-college", "Married", "Blue-Collar", "White", "Male", 46.0, 0], [42, "Private", "Assoc", "Widowed", "Blue-Collar", "White", "Male", 89, 0], [42, "Private", "Some-college", "Divorced", "Blue-Collar", "White", "Male", 4.0, 0], [42, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 12.0, 0], [42, "Private", "Some-college", "Separated", "Blue-Collar", "White", "Male", 49.0, 0], [68.0, "Private", "Some-college", "Widowed", "Blue-Collar", "White", "Male", 89, 0]], [[43.0, "Self-Employed", "Masters", "Married", "Service", "White", "Male", 30, 1], [44.0, "Private", "Masters", "Single", "Service", "White", "Male", 30, 1], [55.0, "Self-Employed", "Masters", "Divorced", "Service", "Other", "Male", 95.0, 1], [62.0, "Self-Employed", "Some-college", "Married", "Service", "White", "Male", 93.0, 1], [49.0, "Self-Employed", "Prof-school", "Married", "White-Collar", "White", "Male", 30, 1], [73.0, "Self-Employed", "Some-college", "Married", "Sales", "White", "Male", 82.0, 1], [53.0, "Self-Employed", "Prof-school", "Married", "Service", "White", "Male", 30, 1], [40.0, "Private", "Some-college", "Married", "Service", "White", "Male", 30, 1], [67.0, "Government", "Some-college", "Married", "Service", "White", "Male", 57.0, 1], [62.0, "Self-Employed", "Assoc", "Single", "White-Collar", "White", "Male", 30, 1]], [[43.0, "Private", "Some-college", "Married", "White-Collar", "White", "Female", 86.0, 1], [33.0, "Private", "Assoc", "Married", "White-Collar", "White", "Female", 49.0, 1], [47.0, "Private", "Masters", "Single", "White-Collar", "White", "Male", 40, 1], [47.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Female", 40, 1], [34.0, "Private", "Some-college", "Married", "White-Collar", "White", "Female", 40, 1], [37.0, "Private", "HS-grad", "Single", "White-Collar", "White", "Male", 40, 1], [43.0, "Private", "Some-college", "Married", "White-Collar", "White", "Female", 40, 1], [34.0, "Private", "Some-college", "Married", "Professional", "White", "Female", 40, 1], [38.0, "Private", "Masters", "Single", "White-Collar", "White", "Male", 40, 1], [38.0, "Government", "HS-grad", "Single", "Blue-Collar", "White", "Female", 40, 0]], [[60, "Self-Employed", "School", "Married", "Service", "White", "Male", 40, 0], [40.0, "Private", "School", "Married", "Sales", "White", "Male", 40, 0], [60, "Other/Unknown", "School", "Single", "Sales", "White", "Male", 40, 0], [60, "Private", "School", "Married", "Other/Unknown", "White", "Male", 45.0, 0], [60, "Private", "School", "Separated", "Sales", "White", "Male", 40, 0], [37.0, "Private", "School", "Divorced", "Sales", "White", "Male", 40, 0], [60, "Private", "School", "Married", "White-Collar", "White", "Female", 40, 0], [24.0, "Private", "School", "Married", "Sales", "White", "Male", 40, 0], [60, "Private", "Masters", "Widowed", "Sales", "White", "Male", 40, 0], [60, "Private", "School", "Single", "Service", "White", "Male", 40, 0]], [[51, "Private", "HS-grad", "Divorced", "Professional", "White", "Male", 69.0, 0], [51, "Private", "HS-grad", "Married", "Blue-Collar", "Other", "Male", 40, 1], [51, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 42.0, 1], [51, "Private", "Doctorate", "Divorced", "Blue-Collar", "White", "Male", 71.0, 1], [51, "Private", "Assoc", "Divorced", "White-Collar", "White", "Male", 40, 1], [46.0, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 40, 1], [51, "Private", "Doctorate", "Divorced", "Blue-Collar", "White", "Male", 77.0, 1], [51, "Private", "HS-grad", "Divorced", "Professional", "White", "Male", 90.0, 1], [51, "Private", "Prof-school", "Married", "Blue-Collar", "White", "Male", 40, 1], [51, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 78.0, 1]], [[80.0, "Government", "Bachelors", "Married", "Blue-Collar", "White", "Female", 38, 1], [35.0, "Self-Employed", "Prof-school", "Married", "Blue-Collar", "White", "Female", 38, 1], [46.0, "Private", "Assoc", "Married", "Blue-Collar", "White", "Male", 38, 1], [47.0, "Private", "Prof-school", "Married", "Sales", "White", "Female", 38, 1], [80.0, "Government", "Bachelors", "Married", "Blue-Collar", "White", "Male", 38, 1], [47.0, "Other/Unknown", "Prof-school", "Married", "Sales", "White", "Female", 38, 1], [53.0, "Private", "Masters", "Married", "White-Collar", "White", "Female", 38, 1], [71.0, "Private", "Some-college", "Married", "White-Collar", "White", "Male", 59.0, 1], [23, "Self-Employed", "Doctorate", "Married", "Professional", "Other", "Female", 38, 1], [50.0, "Private", "Masters", "Married", "White-Collar", "White", "Female", 46.0, 1]], [[19, "Other/Unknown", "Masters", "Married", "Other/Unknown", "Other", "Male", 90.0, 1], [85.0, "Government", "Some-college", "Married", "Other/Unknown", "Other", "Female", 53.0, 1], [19, "Government", "Prof-school", "Married", "White-Collar", "Other", "Female", 84.0, 1], [19, "Other/Unknown", "Masters", "Married", "Service", "Other", "Male", 90.0, 0], [54.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "Other", "Male", 96.0, 1], [86.0, "Other/Unknown", "School", "Married", "Professional", "White", "Female", 40, 0], [75.0, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "Other", "Male", 92.0, 1], [88.0, "Other/Unknown", "Doctorate", "Single", "Professional", "White", "Female", 40, 1], [78.0, "Other/Unknown", "Bachelors", "Married", "Other/Unknown", "White", "Female", 40, 1], [19.0, "Other/Unknown", "Masters", "Married", "Professional", "White", "Female", 40, 1]], [[28, "Other/Unknown", "Some-college", "Separated", "Other/Unknown", "White", "Female", 79.0, 0], [28, "Other/Unknown", "Assoc", "Married", "Other/Unknown", "White", "Male", 40, 0], [65.0, "Other/Unknown", "Some-college", "Widowed", "Other/Unknown", "White", "Female", 40, 0], [28, "Other/Unknown", "Some-college", "Separated", "Other/Unknown", "White", "Female", 8.0, 0], [28, "Other/Unknown", "Some-college", "Married", "Blue-Collar", "White", "Female", 91.0, 0], [28, "Other/Unknown", "School", "Married", "Other/Unknown", "White", "Male", 40, 0], [28, "Other/Unknown", "Some-college", "Divorced", "Other/Unknown", "White", "Female", 79.0, 0], [28, "Other/Unknown", "Some-college", "Married", "Blue-Collar", "Other", "Female", 40, 0], [28, "Other/Unknown", "Some-college", "Single", "White-Collar", "White", "Female", 40, 0], [28, "Other/Unknown", "Some-college", "Married", "Blue-Collar", "White", "Female", 1.0, 0]], [[34, "Private", "Prof-school", "Married", "Professional", "White", "Male", 7.0, 0], [34, "Private", "Bachelors", "Married", "Sales", "White", "Female", 40, 0], [34, "Self-Employed", "School", "Married", "Professional", "White", "Male", 40, 0], [34, "Self-Employed", "Bachelors", "Widowed", "Professional", "White", "Male", 40, 0], [77.0, "Private", "Bachelors", "Married", "Service", "White", "Male", 40, 0], [68.0, "Private", "Bachelors", "Single", "Professional", "White", "Male", 40, 0], [38.0, "Government", "Bachelors", "Married", "Professional", "White", "Male", 40, 0], [34, "Private", "Some-college", "Single", "Professional", "White", "Male", 40, 0], [89.0, "Private", "Bachelors", "Married", "Professional", "White", "Male", 21.0, 0], [34, "Private", "Bachelors", "Divorced", "Professional", "Other", "Male", 40, 0]]], "local_importance": [[0.2, 0.1, 0.4, 0.0, 0.4, 0.2, 0.0, 0.6], [0.2, 0.0, 0.2, 0.5, 0.0, 0.1, 0.0, 0.8], [1.0, 0.3, 0.6, 0.8, 0.3, 0.1, 0.0, 0.4], [1.0, 0.1, 0.7, 0.6, 0.2, 0.0, 0.3, 0.2], [0.3, 0.2, 0.1, 0.5, 0.4, 0.0, 0.1, 0.1], [0.1, 0.0, 0.4, 0.5, 0.3, 0.1, 0.0, 0.6], [0.9, 0.5, 1.0, 1.0, 0.6, 0.1, 0.3, 0.2], [0.6, 0.2, 1.0, 0.9, 0.5, 0.4, 0.4, 0.6], [0.1, 0.0, 0.2, 0.5, 0.4, 0.1, 0.2, 0.5], [0.4, 0.3, 0.3, 0.4, 0.2, 0.1, 0.1, 0.2]], "summary_importance": [0.48, 0.17, 0.49, 0.57, 0.33, 0.12, 0.14, 0.42], "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 : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 44 Private HS-grad Married Sales White Male 40 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - Assoc - Professional - - - 1
1 - - Bachelors - White-Collar - - - 1
2 - - - - - - - 85.0 1
3 59.0 - - - - - - 71.0 1
4 - Government Masters - - - - - 1
5 - - - - - Other - 93.0 1
6 - - - - Blue-Collar - - 92.0 1
7 - - Masters - - Other - - 1
8 56.0 - - - - - - 52.0 1
9 - - - - White-Collar - - 23.0 1
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 42 Private Some-college Married Blue-Collar White Male 89 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - - - - - - 50.0 0
1 - - - - - Other - 1.0 0
2 - - - Single - - - 6.0 0
3 19.0 - - - - - - 68.0 0
4 - - - - - - - 46.0 0
5 - - Assoc Widowed - - - - 0
6 - - - Divorced - - - 4.0 0
7 - - HS-grad - - - - 12.0 0
8 - - - Separated - - - 49.0 0
9 68.0 - - Widowed - - - - 0
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 21 Self-Employed Some-college Single Service White Male 30 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 43.0 - Masters Married - - - - 1
1 44.0 Private Masters - - - - - 1
2 55.0 - Masters Divorced - Other - 95.0 1
3 62.0 - - Married - - - 93.0 1
4 49.0 - Prof-school Married White-Collar - - - 1
5 73.0 - - Married Sales - - 82.0 1
6 53.0 - Prof-school Married - - - - 1
7 40.0 Private - Married - - - - 1
8 67.0 Government - Married - - - 57.0 1
9 62.0 - Assoc - White-Collar - - - 1
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 24 Private HS-grad Single White-Collar White Female 40 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 43.0 - Some-college Married - - - 86.0 1
1 33.0 - Assoc Married - - - 49.0 1
2 47.0 - Masters - - - Male - 1
3 47.0 - - Married - - - - 1
4 34.0 - Some-college Married - - - - 1
5 37.0 - - - - - Male - 1
6 43.0 - Some-college Married - - - - 1
7 34.0 - Some-college Married Professional - - - 1
8 38.0 - Masters - - - Male - 1
9 38.0 Government - - Blue-Collar - - - -
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 60 Private School Married Sales White Male 40 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - Self-Employed - - Service - - - 0
1 40.0 - - - - - - - 0
2 - Other/Unknown - Single - - - - 0
3 - - - - Other/Unknown - - 45.0 0
4 - - - Separated - - - - 0
5 37.0 - - Divorced - - - - 0
6 - - - - White-Collar - Female - 0
7 24.0 - - - - - - - 0
8 - - Masters Widowed - - - - 0
9 - - - Single Service - - - 0
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 51 Private HS-grad Divorced Blue-Collar White Male 40 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - - - Professional - - 69.0 -
1 - - - Married - Other - - 1
2 - - - Married - - - 42.0 1
3 - - Doctorate - - - - 71.0 1
4 - - Assoc - White-Collar - - - 1
5 46.0 - - Married - - - - 1
6 - - Doctorate - - - - 77.0 1
7 - - - - Professional - - 90.0 1
8 - - Prof-school Married - - - - 1
9 - - - Married - - - 78.0 1
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 23 Private School Single Blue-Collar White Female 38 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 80.0 Government Bachelors Married - - - - 1
1 35.0 Self-Employed Prof-school Married - - - - 1
2 46.0 - Assoc Married - - Male - 1
3 47.0 - Prof-school Married Sales - - - 1
4 80.0 Government Bachelors Married - - Male - 1
5 47.0 Other/Unknown Prof-school Married Sales - - - 1
6 53.0 - Masters Married White-Collar - - - 1
7 71.0 - Some-college Married White-Collar - Male 59.0 1
8 - Self-Employed Doctorate Married Professional Other - - 1
9 50.0 - Masters Married White-Collar - - 46.0 1
Query instance (original outcome : 0)
age workclass education marital_status occupation race gender hours_per_week income
0 19 Other/Unknown HS-grad Single Other/Unknown Other Female 40 0

Counterfactual set (new outcome: 1.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - Masters Married - - Male 90.0 1
1 85.0 Government Some-college Married - - - 53.0 1
2 - Government Prof-school Married White-Collar - - 84.0 1
3 - - Masters Married Service - Male 90.0 -
4 54.0 - Some-college Married - - Male 96.0 1
5 86.0 - School Married Professional White - - -
6 75.0 - Some-college Married - - Male 92.0 1
7 88.0 - Doctorate - Professional White - - 1
8 78.0 - Bachelors Married - White - - 1
9 - - Masters Married Professional White - - 1
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 28 Other/Unknown Some-college Married Other/Unknown White Female 40 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - - Separated - - - 79.0 0
1 - - Assoc - - - Male - 0
2 65.0 - - Widowed - - - - 0
3 - - - Separated - - - 8.0 0
4 - - - - Blue-Collar - - 91.0 0
5 - - School - - - Male - 0
6 - - - Divorced - - - 79.0 0
7 - - - - Blue-Collar Other - - 0
8 - - - Single White-Collar - - - 0
9 - - - - Blue-Collar - - 1.0 0
Query instance (original outcome : 1)
age workclass education marital_status occupation race gender hours_per_week income
0 34 Private Bachelors Married Professional White Male 40 1

Counterfactual set (new outcome: 0.0)
age workclass education marital_status occupation race gender hours_per_week income
0 - - Prof-school - - - - 7.0 0
1 - - - - Sales - Female - 0
2 - Self-Employed School - - - - - 0
3 - Self-Employed - Widowed - - - - 0
4 77.0 - - - Service - - - 0
5 68.0 - - Single - - - - 0
6 38.0 Government - - - - - - 0
7 - - Some-college Single - - - - 0
8 89.0 - - - - - - 21.0 0
9 - - - Divorced - Other - - 0
[None, None, None, None, None, None, None, None, None, None]
[{'hours_per_week': 0.6, 'education': 0.4, 'occupation': 0.4, 'age': 0.2, 'race': 0.2, 'workclass': 0.1, 'marital_status': 0.0, 'gender': 0.0}, {'hours_per_week': 0.8, 'marital_status': 0.5, 'age': 0.2, 'education': 0.2, 'race': 0.1, 'workclass': 0.0, 'occupation': 0.0, 'gender': 0.0}, {'age': 1.0, 'marital_status': 0.8, 'education': 0.6, 'hours_per_week': 0.4, 'workclass': 0.3, 'occupation': 0.3, 'race': 0.1, 'gender': 0.0}, {'age': 1.0, 'education': 0.7, 'marital_status': 0.6, 'gender': 0.3, 'occupation': 0.2, 'hours_per_week': 0.2, 'workclass': 0.1, 'race': 0.0}, {'marital_status': 0.5, 'occupation': 0.4, 'age': 0.3, 'workclass': 0.2, 'education': 0.1, 'gender': 0.1, 'hours_per_week': 0.1, 'race': 0.0}, {'hours_per_week': 0.6, 'marital_status': 0.5, 'education': 0.4, 'occupation': 0.3, 'age': 0.1, 'race': 0.1, 'workclass': 0.0, 'gender': 0.0}, {'education': 1.0, 'marital_status': 1.0, 'age': 0.9, 'occupation': 0.6, 'workclass': 0.5, 'gender': 0.3, 'hours_per_week': 0.2, 'race': 0.1}, {'education': 1.0, 'marital_status': 0.9, 'age': 0.6, 'hours_per_week': 0.6, 'occupation': 0.5, 'race': 0.4, 'gender': 0.4, 'workclass': 0.2}, {'marital_status': 0.5, 'hours_per_week': 0.5, 'occupation': 0.4, 'education': 0.2, 'gender': 0.2, 'age': 0.1, 'race': 0.1, 'workclass': 0.0}, {'age': 0.4, 'marital_status': 0.4, 'workclass': 0.3, 'education': 0.3, 'occupation': 0.2, 'hours_per_week': 0.2, 'race': 0.1, 'gender': 0.1}]
{'marital_status': 0.57, 'education': 0.49, 'age': 0.48, 'hours_per_week': 0.42, 'occupation': 0.33, 'workclass': 0.17, 'gender': 0.14, 'race': 0.12}