Differential Privacy#
In this notebook we will build differentially private EBMs and compare them to regular EBMs.
This notebook can be found in our examples folder on GitHub.
# install interpret if not already installed
try:
import interpret
except ModuleNotFoundError:
!pip install --quiet interpret pandas scikit-learn
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from interpret import set_visualize_provider
from interpret.provider import InlineProvider
set_visualize_provider(InlineProvider())
df = pd.read_csv(
"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data",
header=None)
df.columns = [
"Age", "WorkClass", "fnlwgt", "Education", "EducationNum",
"MaritalStatus", "Occupation", "Relationship", "Race", "Gender",
"CapitalGain", "CapitalLoss", "HoursPerWeek", "NativeCountry", "Income"
]
X = df.iloc[:, :-1]
y = df.iloc[:, -1]
# Set feature_types manually instead of relying on auto-detect
feature_types = ['continuous', 'nominal', 'continuous', 'nominal',
'continuous', 'nominal', 'nominal', 'nominal', 'nominal', 'nominal',
'continuous', 'continuous', 'continuous', 'nominal']
privacy_bounds = {"Age": (17, 90), "fnlwgt": (12285, 1484705),
"EducationNum": (1, 16), "CapitalGain": (0, 99999),
"CapitalLoss": (0, 4356), "HoursPerWeek": (1, 99)
}
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)
Fit and compare DP-EBM vs. standard EBM
from interpret.privacy import DPExplainableBoostingClassifier
from interpret.glassbox import ExplainableBoostingClassifier
from interpret import show
from sklearn.metrics import roc_auc_score
dpebm = DPExplainableBoostingClassifier(random_state=None, epsilon=1, delta=1e-6,
feature_types=feature_types, privacy_bounds=privacy_bounds)
dpebm.fit(X_train, y_train)
dp_auc = roc_auc_score(y_test, dpebm.predict_proba(X_test)[:, 1])
print("DPEBM AUC: {:.3f}".format(dp_auc))
ebm = ExplainableBoostingClassifier()
ebm.fit(X_train, y_train)
ebm_auc = roc_auc_score(y_test, ebm.predict_proba(X_test)[:, 1])
print("EBM AUC: {:.3f}".format(ebm_auc))
DPEBM AUC: 0.880
EBM AUC: 0.928
See differences in learned shape functions
show(dpebm.explain_global(name='DP EBM'))