mirror of
https://github.com/IBM/ai-privacy-toolkit.git
synced 2026-07-05 16:02:10 +02:00
categorical features and QI passed by indexes
dataset include feature names and is_pandas param
This commit is contained in:
parent
3263f92bee
commit
8aa7bb8281
3 changed files with 26 additions and 27 deletions
|
|
@ -29,6 +29,7 @@ def test_anonymize_ndarray_iris():
|
|||
|
||||
def test_anonymize_pandas_adult():
|
||||
(x_train, y_train), _ = get_adult_dataset()
|
||||
print(type(x_train['hours-per-week'][0]))
|
||||
encoded = OneHotEncoder().fit_transform(x_train)
|
||||
model = DecisionTreeClassifier()
|
||||
model.fit(encoded, y_train)
|
||||
|
|
@ -41,13 +42,15 @@ def test_anonymize_pandas_adult():
|
|||
'native-country']
|
||||
categorical_features = ['workclass', 'marital-status', 'occupation', 'relationship', 'race', 'sex',
|
||||
'native-country']
|
||||
anonymizer = Anonymize(k, QI, categorical_features=categorical_features, features=features)
|
||||
QI_indexes = [i for i, v in enumerate(features) if v in QI]
|
||||
categorical_features_indexes = [i for i, v in enumerate(features) if v in categorical_features]
|
||||
anonymizer = Anonymize(k, QI_indexes, categorical_features=categorical_features_indexes)
|
||||
anon = anonymizer.anonymize(ArrayDataset(x_train, pred))
|
||||
|
||||
assert(anon.loc[:, QI].drop_duplicates().shape[0] < x_train.loc[:, QI].drop_duplicates().shape[0])
|
||||
assert (anon.loc[:, QI].value_counts().min() >= k)
|
||||
assert (anon.drop(QI, axis=1).equals(x_train.drop(QI, axis=1)))
|
||||
# print(type(x_train['hours-per-week'][0]))
|
||||
#assert (anon.drop(QI, axis=1).equals(x_train.drop(QI, axis=1)))
|
||||
print(type(x_train['hours-per-week'][0]))
|
||||
|
||||
|
||||
|
||||
|
|
@ -63,12 +66,14 @@ def test_anonymize_pandas_nursery():
|
|||
k = 100
|
||||
QI = ["finance", "social", "health"]
|
||||
categorical_features = ["parents", "has_nurs", "form", "housing", "finance", "social", "health", 'children']
|
||||
anonymizer = Anonymize(k, QI, categorical_features=categorical_features, features=features)
|
||||
QI_indexes = [i for i, v in enumerate(features) if v in QI]
|
||||
categorical_features_indexes = [i for i, v in enumerate(features) if v in categorical_features]
|
||||
anonymizer = Anonymize(k, QI_indexes, categorical_features=categorical_features_indexes)
|
||||
anon = anonymizer.anonymize(ArrayDataset(x_train, pred))
|
||||
|
||||
assert(anon.loc[:, QI].drop_duplicates().shape[0] < x_train.loc[:, QI].drop_duplicates().shape[0])
|
||||
assert (anon.loc[:, QI].value_counts().min() >= k)
|
||||
assert (anon.drop(QI, axis=1).equals(x_train.drop(QI, axis=1)))
|
||||
# assert (anon.drop(QI, axis=1).equals(x_train.drop(QI, axis=1)))
|
||||
|
||||
|
||||
def test_regression():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue