The DiffPrivLib version of Decision Tree is giving me the wrong accuracy

IBM specifically designed their differential privacy library, DiffPrivLib, to work exactly like scikitlearn for ease of use. The tutorials on their github site state that if using epsilon = infinity (and, presumably, the same random state) with DiffPrivLib you should get an identical model to the non-private version from scikitlearn. Ref: github.com/IBM/differential-privacy-library/blob/main/notebooks/…

I’ve confirmed that this works with Gaussian Naiive Bayes, but when using almost identical code frameworks with the Decision Tree Classifier, I’m getting radically different values. Has anyone else encountered this? Can you see what’s wrong with my code?

This is the code to run a non differentially private Decision Tree using scikitlearn, this works fine.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Import necessary packages
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import confusion_matrix
import diffprivlib as dp
# Open and read the data into a dataframe
train = pd.read_csv('train.csv', index_col=0)
test = pd.read_csv('test.csv', index_col=0)
# X are the independent variables, y are the dependent variables.
X_train = train.drop(['is_fraud'], axis=1)
y_train = train['is_fraud']
X_test = test.drop(['is_fraud'], axis=1)
y_test = test['is_fraud']
# Build a Decision Tree Classifier
dt = DecisionTreeClassifier(random_state=42)
# Model training
dt.fit(X_train, y_train)
# Predict Output
y_pred_dt = dt.predict(X_test)
# Output metrics
print(confusion_matrix(y_test, y_pred_dt))
</code>
<code># Import necessary packages import pandas as pd import numpy as np from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import confusion_matrix import diffprivlib as dp # Open and read the data into a dataframe train = pd.read_csv('train.csv', index_col=0) test = pd.read_csv('test.csv', index_col=0) # X are the independent variables, y are the dependent variables. X_train = train.drop(['is_fraud'], axis=1) y_train = train['is_fraud'] X_test = test.drop(['is_fraud'], axis=1) y_test = test['is_fraud'] # Build a Decision Tree Classifier dt = DecisionTreeClassifier(random_state=42) # Model training dt.fit(X_train, y_train) # Predict Output y_pred_dt = dt.predict(X_test) # Output metrics print(confusion_matrix(y_test, y_pred_dt)) </code>
# Import necessary packages
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import confusion_matrix
import diffprivlib as dp

# Open and read the data into a dataframe
train = pd.read_csv('train.csv', index_col=0)
test = pd.read_csv('test.csv', index_col=0)

# X are the independent variables, y are the dependent variables.
X_train = train.drop(['is_fraud'], axis=1)
y_train = train['is_fraud']
X_test = test.drop(['is_fraud'], axis=1)
y_test = test['is_fraud']

# Build a Decision Tree Classifier
dt = DecisionTreeClassifier(random_state=42)

# Model training
dt.fit(X_train, y_train)

# Predict Output
y_pred_dt = dt.predict(X_test)

# Output metrics
print(confusion_matrix(y_test, y_pred_dt))

Note: I am working with synthetic data and I accidentally hacked the way the data has been simulated by adding in aggregates that the DT is branching on and giving me abnormal amounts of accuracy. But that’s an issue for another day. For now, my confusion matrix looks like this (perfect):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[[553574 0]
[ 0 2145]]
</code>
<code>[[553574 0] [ 0 2145]] </code>
[[553574      0]
 [     0   2145]]

Now for the problem area. With epsilon set to infinity and using the same random state as above I ‘should’ be getting the same values and I’m not. Here is my code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Build a Decision Tree Classifier
DPdt = dp.models.DecisionTreeClassifier(random_state=42, epsilon=np.inf)
# Model training
DPdt.fit(X_train, y_train)
# Predict Output
y_pred_DPdt = DPdt.predict(X_test)
# Output metrics
print(confusion_matrix(y_test, y_pred_DPdt))
</code>
<code># Build a Decision Tree Classifier DPdt = dp.models.DecisionTreeClassifier(random_state=42, epsilon=np.inf) # Model training DPdt.fit(X_train, y_train) # Predict Output y_pred_DPdt = DPdt.predict(X_test) # Output metrics print(confusion_matrix(y_test, y_pred_DPdt)) </code>
# Build a Decision Tree Classifier
DPdt = dp.models.DecisionTreeClassifier(random_state=42, epsilon=np.inf)

# Model training
DPdt.fit(X_train, y_train)

# Predict Output
y_pred_DPdt = DPdt.predict(X_test)

# Output metrics
print(confusion_matrix(y_test, y_pred_DPdt))

And this is giving me dramatically different classification

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[[553574 0]
[ 1787 358]]
</code>
<code>[[553574 0] [ 1787 358]] </code>
[[553574      0]
 [  1787    358]]

Can anyone see what I’ve done wrong?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật