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.93it/s]
Query instance (original outcome : 0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 34 | Private | HS-grad | Single | Sales | White | Female | 40 | 0 |
Diverse Counterfactual set (new outcome: 1.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 35.0 | - | - | - | - | - | Male | - | 1 |
1 | - | - | - | Married | Professional | - | - | - | - |
2 | 87.0 | - | - | Married | - | - | - | - | 1 |
3 | 53.0 | - | - | Married | - | - | - | - | 1 |
4 | 45.0 | - | - | Married | - | - | - | - | 1 |
5 | 72.0 | - | - | Married | - | - | - | - | 1 |
6 | 38.0 | - | - | - | - | - | Male | - | 1 |
7 | - | - | - | Married | - | - | Male | - | 1 |
8 | 61.0 | - | - | Married | - | - | - | - | 1 |
9 | 44.0 | - | - | Married | - | - | - | - | 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.8, 'age': 0.8, 'gender': 0.3, 'occupation': 0.1, 'workclass': 0.0, 'education': 0.0, 'race': 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, 9.63it/s]
[{'marital_status': 0.8, 'age': 0.8, 'gender': 0.3, 'occupation': 0.1, 'workclass': 0.0, 'education': 0.0, 'race': 0.0, 'hours_per_week': 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, 8.38it/s]
{'education': 0.42, 'marital_status': 0.39, 'age': 0.38, 'hours_per_week': 0.38, 'occupation': 0.22, 'workclass': 0.14, 'gender': 0.09, 'race': 0.07}
Convert the counterfactual output to json¶
[10]:
json_str = cobj.to_json()
print(json_str)
{"test_data": [[[40, "Private", "HS-grad", "Married", "Sales", "White", "Male", 60, 1]], [[34, "Private", "HS-grad", "Single", "Sales", "White", "Female", 40, 0]], [[17, "Private", "School", "Single", "Sales", "White", "Female", 12, 0]], [[55, "Private", "Bachelors", "Married", "Professional", "White", "Male", 40, 1]], [[72, "Other/Unknown", "School", "Divorced", "Other/Unknown", "White", "Male", 30, 0]], [[42, "Private", "HS-grad", "Married", "Blue-Collar", "Other", "Male", 40, 1]], [[35, "Private", "Some-college", "Married", "Professional", "White", "Male", 38, 1]], [[36, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 45, 0]], [[47, "Private", "Some-college", "Married", "Service", "White", "Male", 47, 1]], [[30, "Other/Unknown", "HS-grad", "Married", "Other/Unknown", "Other", "Female", 40, 0]]], "cfs_list": [[[61.0, "Private", "HS-grad", "Married", "Sales", "White", "Male", 30.0, 0], [40, "Private", "HS-grad", "Separated", "Sales", "White", "Male", 41.0, 0], [40, "Private", "HS-grad", "Separated", "Sales", "White", "Male", 60, 0], [40, "Private", "HS-grad", "Divorced", "Sales", "White", "Male", 26.0, 0], [40, "Private", "Bachelors", "Single", "Sales", "White", "Male", 60, 0], [21.0, "Self-Employed", "HS-grad", "Married", "Sales", "White", "Male", 60, 0], [46.0, "Private", "HS-grad", "Married", "White-Collar", "White", "Male", 60, 0], [20.0, "Private", "HS-grad", "Married", "Service", "White", "Male", 60, 0], [40, "Private", "HS-grad", "Single", "Blue-Collar", "White", "Male", 60, 0], [40, "Private", "HS-grad", "Married", "Service", "Other", "Male", 60, 0]], [[47.0, "Private", "HS-grad", "Married", "Sales", "White", "Female", 40, 1], [34, "Private", "Bachelors", "Married", "Sales", "White", "Female", 40, 1], [63.0, "Private", "HS-grad", "Married", "Sales", "White", "Female", 40, 1], [34, "Private", "Masters", "Married", "Sales", "White", "Female", 40, 1], [34, "Private", "Masters", "Single", "Sales", "White", "Male", 40, 1], [75.0, "Private", "HS-grad", "Married", "Sales", "White", "Female", 40, 1], [68.0, "Private", "HS-grad", "Married", "Sales", "White", "Female", 40, 1], [51.0, "Private", "HS-grad", "Married", "Sales", "White", "Female", 40, 1], [37.0, "Private", "HS-grad", "Single", "Sales", "White", "Male", 40, 1], [34, "Private", "HS-grad", "Married", "Professional", "White", "Female", 40, 0]], [[88.0, "Private", "Masters", "Widowed", "Sales", "White", "Male", 51.0, 1], [33.0, "Private", "Bachelors", "Married", "Sales", "White", "Female", 69.0, 1], [75.0, "Government", "Some-college", "Married", "Sales", "White", "Female", 51.0, 1], [39.0, "Private", "Assoc", "Married", "Sales", "White", "Male", 53.0, 1], [34.0, "Private", "Bachelors", "Married", "White-Collar", "White", "Male", 12, 1], [67.0, "Private", "Bachelors", "Married", "Sales", "White", "Female", 12, 1], [67.0, "Self-Employed", "Bachelors", "Married", "Sales", "White", "Female", 12, 1], [46.0, "Government", "Assoc", "Married", "Sales", "White", "Female", 72.0, 1], [46.0, "Private", "Assoc", "Married", "Sales", "White", "Female", 72.0, 1], [64.0, "Private", "Some-college", "Married", "Sales", "White", "Female", 41.0, 1]], [[55, "Private", "Bachelors", "Separated", "Professional", "White", "Male", 82.0, 0], [28.0, "Private", "Bachelors", "Widowed", "Professional", "White", "Male", 40, 0], [87.0, "Private", "Bachelors", "Divorced", "Professional", "White", "Male", 40, 0], [55, "Private", "Bachelors", "Married", "Professional", "White", "Male", 5.0, 0], [55, "Other/Unknown", "Bachelors", "Married", "Other/Unknown", "White", "Male", 40, 0], [55, "Private", "Masters", "Married", "Service", "White", "Male", 40, 0], [55, "Government", "Bachelors", "Divorced", "Professional", "White", "Male", 40, 0], [27.0, "Private", "Bachelors", "Married", "Professional", "Other", "Male", 40, 0], [55, "Private", "Bachelors", "Single", "Professional", "White", "Male", 90.0, 0], [55, "Private", "HS-grad", "Married", "Professional", "White", "Male", 6.0, 0]], [[72, "Other/Unknown", "Doctorate", "Divorced", "Other/Unknown", "White", "Male", 56.0, 0], [72, "Other/Unknown", "Doctorate", "Married", "Other/Unknown", "White", "Male", 30, 1], [72, "Other/Unknown", "School", "Married", "Other/Unknown", "White", "Male", 56.0, 1], [72, "Other/Unknown", "Prof-school", "Married", "Other/Unknown", "White", "Male", 30, 1], [72, "Other/Unknown", "Masters", "Divorced", "Other/Unknown", "White", "Male", 78.0, 1], [72, "Other/Unknown", "Masters", "Divorced", "Other/Unknown", "White", "Male", 79.0, 1], [72, "Other/Unknown", "School", "Married", "Other/Unknown", "White", "Male", 58.0, 1], [72, "Other/Unknown", "Masters", "Divorced", "Other/Unknown", "White", "Male", 75.0, 1], [72, "Other/Unknown", "Doctorate", "Divorced", "Other/Unknown", "White", "Male", 61.0, 1], [72, "Other/Unknown", "Masters", "Divorced", "Other/Unknown", "White", "Male", 64.0, 1]], [[42, "Private", "Assoc", "Married", "Blue-Collar", "Other", "Male", 40, 0], [60.0, "Private", "HS-grad", "Widowed", "Blue-Collar", "Other", "Male", 40, 0], [42, "Other/Unknown", "HS-grad", "Married", "Blue-Collar", "Other", "Male", 7.0, 0], [42, "Private", "HS-grad", "Married", "Blue-Collar", "Other", "Male", 91.0, 0], [84.0, "Private", "HS-grad", "Married", "Blue-Collar", "Other", "Female", 40, 0], [42, "Other/Unknown", "Bachelors", "Married", "Blue-Collar", "Other", "Male", 40, 0], [68.0, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 40, 0], [25.0, "Private", "HS-grad", "Married", "Other/Unknown", "Other", "Male", 40, 0], [42, "Private", "HS-grad", "Married", "Blue-Collar", "Other", "Male", 16.0, 0], [42, "Private", "HS-grad", "Married", "Blue-Collar", "Other", "Male", 73.0, 0]], [[35, "Private", "Some-college", "Widowed", "Professional", "Other", "Male", 38, 0], [35, "Private", "Some-college", "Widowed", "Professional", "White", "Male", 56.0, 0], [35, "Private", "Some-college", "Married", "Other/Unknown", "White", "Male", 35.0, 0], [35, "Private", "School", "Married", "Professional", "Other", "Male", 38, 0], [17.0, "Private", "Some-college", "Married", "Professional", "White", "Male", 38, 0], [35, "Private", "Some-college", "Married", "Professional", "White", "Male", 91.0, 0], [18.0, "Private", "Some-college", "Married", "Professional", "White", "Male", 55.0, 0], [35, "Private", "Assoc", "Divorced", "Professional", "White", "Male", 38, 0], [35, "Private", "Some-college", "Married", "Professional", "White", "Male", 72.0, 0], [35, "Government", "Some-college", "Married", "Blue-Collar", "White", "Male", 38, 0]], [[58.0, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 45, 1], [36, "Private", "Assoc", "Married", "Blue-Collar", "White", "Female", 45, 1], [36, "Private", "School", "Married", "Blue-Collar", "White", "Male", 46.0, 1], [36, "Private", "Prof-school", "Married", "Blue-Collar", "White", "Female", 45, 1], [36, "Government", "Doctorate", "Married", "Blue-Collar", "White", "Male", 45, 1], [54.0, "Private", "HS-grad", "Married", "Service", "White", "Male", 45, 1], [66.0, "Private", "Doctorate", "Married", "Blue-Collar", "White", "Male", 45, 1], [36, "Private", "Doctorate", "Married", "Blue-Collar", "White", "Male", 45, 1], [45.0, "Private", "HS-grad", "Married", "Blue-Collar", "White", "Male", 45, 1], [36, "Private", "Doctorate", "Married", "White-Collar", "White", "Male", 45, 1]], [[82.0, "Government", "Some-college", "Married", "Service", "White", "Male", 47, 0], [17.0, "Private", "Prof-school", "Married", "Service", "White", "Male", 47, 0], [47, "Private", "Some-college", "Single", "Service", "White", "Male", 47, 0], [47, "Private", "Some-college", "Married", "Service", "Other", "Male", 66.0, 0], [47, "Private", "Some-college", "Separated", "Service", "White", "Female", 47, 0], [67.0, "Private", "Some-college", "Widowed", "Service", "White", "Male", 47, 0], [47, "Private", "Assoc", "Married", "Other/Unknown", "White", "Male", 47, 0], [47, "Other/Unknown", "Some-college", "Married", "Other/Unknown", "White", "Male", 47, 0], [47, "Private", "School", "Married", "Service", "White", "Male", 47, 0], [47, "Government", "Some-college", "Married", "Service", "White", "Male", 78.0, 0]], [[78.0, "Other/Unknown", "HS-grad", "Married", "Professional", "Other", "Female", 40, 1], [30, "Other/Unknown", "HS-grad", "Married", "Professional", "Other", "Female", 71.0, 1], [30, "Other/Unknown", "HS-grad", "Married", "Professional", "White", "Female", 40, 1], [30, "Other/Unknown", "HS-grad", "Married", "Professional", "Other", "Female", 10.0, 1], [30, "Other/Unknown", "Masters", "Married", "Professional", "Other", "Female", 40, 1], [30, "Self-Employed", "Masters", "Married", "Other/Unknown", "Other", "Female", 40, 1], [30, "Other/Unknown", "Masters", "Married", "Other/Unknown", "Other", "Female", 17.0, 1], [30, "Other/Unknown", "Masters", "Married", "Other/Unknown", "Other", "Female", 94.0, 1], [76.0, "Other/Unknown", "HS-grad", "Married", "Professional", "Other", "Female", 40, 1], [30, "Other/Unknown", "HS-grad", "Married", "Professional", "Other", "Female", 40, 1]]], "local_importance": [[0.4, 0.1, 0.1, 0.5, 0.4, 0.1, 0.0, 0.3], [0.6, 0.0, 0.3, 0.8, 0.1, 0.0, 0.2, 0.0], [1.0, 0.3, 1.0, 1.0, 0.1, 0.0, 0.3, 0.7], [0.3, 0.2, 0.2, 0.5, 0.2, 0.1, 0.0, 0.4], [0.0, 0.0, 0.8, 0.4, 0.0, 0.0, 0.0, 0.8], [0.4, 0.2, 0.2, 0.1, 0.1, 0.1, 0.1, 0.4], [0.2, 0.1, 0.2, 0.3, 0.2, 0.2, 0.0, 0.5], [0.4, 0.1, 0.7, 0.0, 0.2, 0.0, 0.2, 0.1], [0.3, 0.3, 0.3, 0.3, 0.2, 0.1, 0.1, 0.2], [0.2, 0.1, 0.4, 0.0, 0.7, 0.1, 0.0, 0.4]], "summary_importance": [0.38, 0.14, 0.42, 0.39, 0.22, 0.07, 0.09, 0.38], "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 | 40 | Private | HS-grad | Married | Sales | White | Male | 60 | 1 |
Counterfactual set (new outcome: 0.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 61.0 | - | - | - | - | - | - | 30.0 | 0 |
1 | - | - | - | Separated | - | - | - | 41.0 | 0 |
2 | - | - | - | Separated | - | - | - | - | 0 |
3 | - | - | - | Divorced | - | - | - | 26.0 | 0 |
4 | - | - | Bachelors | Single | - | - | - | - | 0 |
5 | 21.0 | Self-Employed | - | - | - | - | - | - | 0 |
6 | 46.0 | - | - | - | White-Collar | - | - | - | 0 |
7 | 20.0 | - | - | - | Service | - | - | - | 0 |
8 | - | - | - | Single | Blue-Collar | - | - | - | 0 |
9 | - | - | - | - | Service | Other | - | - | 0 |
Query instance (original outcome : 0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 34 | Private | HS-grad | Single | Sales | White | Female | 40 | 0 |
Counterfactual set (new outcome: 1.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 47.0 | - | - | Married | - | - | - | - | 1 |
1 | - | - | Bachelors | Married | - | - | - | - | 1 |
2 | 63.0 | - | - | Married | - | - | - | - | 1 |
3 | - | - | Masters | Married | - | - | - | - | 1 |
4 | - | - | Masters | - | - | - | Male | - | 1 |
5 | 75.0 | - | - | Married | - | - | - | - | 1 |
6 | 68.0 | - | - | Married | - | - | - | - | 1 |
7 | 51.0 | - | - | Married | - | - | - | - | 1 |
8 | 37.0 | - | - | - | - | - | Male | - | 1 |
9 | - | - | - | Married | Professional | - | - | - | - |
Query instance (original outcome : 0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 17 | Private | School | Single | Sales | White | Female | 12 | 0 |
Counterfactual set (new outcome: 1.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 88.0 | - | Masters | Widowed | - | - | Male | 51.0 | 1 |
1 | 33.0 | - | Bachelors | Married | - | - | - | 69.0 | 1 |
2 | 75.0 | Government | Some-college | Married | - | - | - | 51.0 | 1 |
3 | 39.0 | - | Assoc | Married | - | - | Male | 53.0 | 1 |
4 | 34.0 | - | Bachelors | Married | White-Collar | - | Male | - | 1 |
5 | 67.0 | - | Bachelors | Married | - | - | - | - | 1 |
6 | 67.0 | Self-Employed | Bachelors | Married | - | - | - | - | 1 |
7 | 46.0 | Government | Assoc | Married | - | - | - | 72.0 | 1 |
8 | 46.0 | - | Assoc | Married | - | - | - | 72.0 | 1 |
9 | 64.0 | - | Some-college | Married | - | - | - | 41.0 | 1 |
Query instance (original outcome : 1)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 55 | 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 | - | - | - | Separated | - | - | - | 82.0 | 0 |
1 | 28.0 | - | - | Widowed | - | - | - | - | 0 |
2 | 87.0 | - | - | Divorced | - | - | - | - | 0 |
3 | - | - | - | - | - | - | - | 5.0 | 0 |
4 | - | Other/Unknown | - | - | Other/Unknown | - | - | - | 0 |
5 | - | - | Masters | - | Service | - | - | - | 0 |
6 | - | Government | - | Divorced | - | - | - | - | 0 |
7 | 27.0 | - | - | - | - | Other | - | - | 0 |
8 | - | - | - | Single | - | - | - | 90.0 | 0 |
9 | - | - | HS-grad | - | - | - | - | 6.0 | 0 |
Query instance (original outcome : 0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 72 | Other/Unknown | School | Divorced | Other/Unknown | White | Male | 30 | 0 |
Counterfactual set (new outcome: 1.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | - | - | Doctorate | - | - | - | - | 56.0 | - |
1 | - | - | Doctorate | Married | - | - | - | - | 1 |
2 | - | - | - | Married | - | - | - | 56.0 | 1 |
3 | - | - | Prof-school | Married | - | - | - | - | 1 |
4 | - | - | Masters | - | - | - | - | 78.0 | 1 |
5 | - | - | Masters | - | - | - | - | 79.0 | 1 |
6 | - | - | - | Married | - | - | - | 58.0 | 1 |
7 | - | - | Masters | - | - | - | - | 75.0 | 1 |
8 | - | - | Doctorate | - | - | - | - | 61.0 | 1 |
9 | - | - | Masters | - | - | - | - | 64.0 | 1 |
Query instance (original outcome : 1)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 42 | Private | HS-grad | 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 | 60.0 | - | - | Widowed | - | - | - | - | 0 |
2 | - | Other/Unknown | - | - | - | - | - | 7.0 | 0 |
3 | - | - | - | - | - | - | - | 91.0 | 0 |
4 | 84.0 | - | - | - | - | - | Female | - | 0 |
5 | - | Other/Unknown | Bachelors | - | - | - | - | - | 0 |
6 | 68.0 | - | - | - | - | White | - | - | 0 |
7 | 25.0 | - | - | - | Other/Unknown | - | - | - | 0 |
8 | - | - | - | - | - | - | - | 16.0 | 0 |
9 | - | - | - | - | - | - | - | 73.0 | 0 |
Query instance (original outcome : 1)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 35 | Private | Some-college | Married | Professional | White | Male | 38 | 1 |
Counterfactual set (new outcome: 0.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | - | - | - | Widowed | - | Other | - | - | 0 |
1 | - | - | - | Widowed | - | - | - | 56.0 | 0 |
2 | - | - | - | - | Other/Unknown | - | - | 35.0 | 0 |
3 | - | - | School | - | - | Other | - | - | 0 |
4 | 17.0 | - | - | - | - | - | - | - | 0 |
5 | - | - | - | - | - | - | - | 91.0 | 0 |
6 | 18.0 | - | - | - | - | - | - | 55.0 | 0 |
7 | - | - | Assoc | Divorced | - | - | - | - | 0 |
8 | - | - | - | - | - | - | - | 72.0 | 0 |
9 | - | Government | - | - | Blue-Collar | - | - | - | 0 |
Query instance (original outcome : 0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 36 | Private | HS-grad | Married | Blue-Collar | White | Male | 45 | 0 |
Counterfactual set (new outcome: 1.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 58.0 | - | - | - | - | - | - | - | 1 |
1 | - | - | Assoc | - | - | - | Female | - | 1 |
2 | - | - | School | - | - | - | - | 46.0 | 1 |
3 | - | - | Prof-school | - | - | - | Female | - | 1 |
4 | - | Government | Doctorate | - | - | - | - | - | 1 |
5 | 54.0 | - | - | - | Service | - | - | - | 1 |
6 | 66.0 | - | Doctorate | - | - | - | - | - | 1 |
7 | - | - | Doctorate | - | - | - | - | - | 1 |
8 | 45.0 | - | - | - | - | - | - | - | 1 |
9 | - | - | Doctorate | - | White-Collar | - | - | - | 1 |
Query instance (original outcome : 1)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 47 | Private | Some-college | Married | Service | White | Male | 47 | 1 |
Counterfactual set (new outcome: 0.0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 82.0 | Government | - | - | - | - | - | - | 0 |
1 | 17.0 | - | Prof-school | - | - | - | - | - | 0 |
2 | - | - | - | Single | - | - | - | - | 0 |
3 | - | - | - | - | - | Other | - | 66.0 | 0 |
4 | - | - | - | Separated | - | - | Female | - | 0 |
5 | 67.0 | - | - | Widowed | - | - | - | - | 0 |
6 | - | - | Assoc | - | Other/Unknown | - | - | - | 0 |
7 | - | Other/Unknown | - | - | Other/Unknown | - | - | - | 0 |
8 | - | - | School | - | - | - | - | - | 0 |
9 | - | Government | - | - | - | - | - | 78.0 | 0 |
Query instance (original outcome : 0)
age | workclass | education | marital_status | occupation | race | gender | hours_per_week | income | |
---|---|---|---|---|---|---|---|---|---|
0 | 30 | Other/Unknown | HS-grad | Married | 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 | 78.0 | - | - | - | Professional | - | - | - | 1 |
1 | - | - | - | - | Professional | - | - | 71.0 | 1 |
2 | - | - | - | - | Professional | White | - | - | 1 |
3 | - | - | - | - | Professional | - | - | 10.0 | 1 |
4 | - | - | Masters | - | Professional | - | - | - | 1 |
5 | - | Self-Employed | Masters | - | - | - | - | - | 1 |
6 | - | - | Masters | - | - | - | - | 17.0 | 1 |
7 | - | - | Masters | - | - | - | - | 94.0 | 1 |
8 | 76.0 | - | - | - | Professional | - | - | - | 1 |
9 | - | - | - | - | Professional | - | - | - | 1 |
[None, None, None, None, None, None, None, None, None, None]
[{'marital_status': 0.5, 'age': 0.4, 'occupation': 0.4, 'hours_per_week': 0.3, 'workclass': 0.1, 'education': 0.1, 'race': 0.1, 'gender': 0.0}, {'marital_status': 0.8, 'age': 0.6, 'education': 0.3, 'gender': 0.2, 'occupation': 0.1, 'workclass': 0.0, 'race': 0.0, 'hours_per_week': 0.0}, {'age': 1.0, 'education': 1.0, 'marital_status': 1.0, 'hours_per_week': 0.7, 'workclass': 0.3, 'gender': 0.3, 'occupation': 0.1, 'race': 0.0}, {'marital_status': 0.5, 'hours_per_week': 0.4, 'age': 0.3, 'workclass': 0.2, 'education': 0.2, 'occupation': 0.2, 'race': 0.1, 'gender': 0.0}, {'education': 0.8, 'hours_per_week': 0.8, 'marital_status': 0.4, 'age': 0.0, 'workclass': 0.0, 'occupation': 0.0, 'race': 0.0, 'gender': 0.0}, {'age': 0.4, 'hours_per_week': 0.4, 'workclass': 0.2, 'education': 0.2, 'marital_status': 0.1, 'occupation': 0.1, 'race': 0.1, 'gender': 0.1}, {'hours_per_week': 0.5, 'marital_status': 0.3, 'age': 0.2, 'education': 0.2, 'occupation': 0.2, 'race': 0.2, 'workclass': 0.1, 'gender': 0.0}, {'education': 0.7, 'age': 0.4, 'occupation': 0.2, 'gender': 0.2, 'workclass': 0.1, 'hours_per_week': 0.1, 'marital_status': 0.0, 'race': 0.0}, {'age': 0.3, 'workclass': 0.3, 'education': 0.3, 'marital_status': 0.3, 'occupation': 0.2, 'hours_per_week': 0.2, 'race': 0.1, 'gender': 0.1}, {'occupation': 0.7, 'education': 0.4, 'hours_per_week': 0.4, 'age': 0.2, 'workclass': 0.1, 'race': 0.1, 'marital_status': 0.0, 'gender': 0.0}]
{'education': 0.42, 'marital_status': 0.39, 'age': 0.38, 'hours_per_week': 0.38, 'occupation': 0.22, 'workclass': 0.14, 'gender': 0.09, 'race': 0.07}