-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sttack class and Add receipt test
- Loading branch information
glassonion1
committed
Nov 10, 2021
1 parent
532f121
commit b0c764d
Showing
7 changed files
with
14,295 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Female,30.0,Hispanic,College,Parther,26.6,0,0,0,0,Q4,0 | ||
Male,67.0,Black,Graduate,Widowed,28.8,0,0,0,0,Q3,1 | ||
Female,57.0,Hispanic,9th,Separated,35.4,1,1,0,0,Q3,1 | ||
Female,24.0,Other,Graduate,Never,25.3,0,1,0,0,Q1,0 | ||
Male,33.0,Japanese,11th,Never,25.3,0,1,0,0,Q1,0 | ||
Female,27.0,Black,College,Never,38.0,0,0,0,0,Q1,0 | ||
Male,49.0,Other,11th,Married,25.0,0,0,0,0,Q1,0 | ||
Female,69.0,Hispanic,9th,Separated,30.3,0,1,0,0,Q4,0 | ||
Male,56.0,Other,11th,Married,25.0,1,0,0,0,Q2,1 | ||
Male,22.0,Hispanic,College,Never,25.3,0,0,0,0,Q4,0 | ||
Female,60.0,Hispanic,Graduate,Divorced,35.9,1,0,0,0,Q2,1 | ||
Male,10.0,Japanese,AAA,Nver,35.9,1,0,0,0,Q2,1 | ||
Female,51.0,Other,hoge,Divorced,35.9,1,0,0,0,Q2,1 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
setup( | ||
name="anonypy", | ||
version="0.1.4", | ||
version="0.1.7", | ||
packages=find_packages(), | ||
author="glassonion1", | ||
author_email="[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import anonypy | ||
import pandas as pd | ||
from datetime import datetime, date | ||
|
||
|
||
def calculate_age(born): | ||
born = datetime.strptime(born, "%Y/%m") | ||
today = date.today() | ||
return today.year - born.year - ((today.month, today.day) < (born.month, born.day)) | ||
|
||
|
||
def test_receipt(): | ||
path = "data/receipt.csv" | ||
df = pd.read_csv(path) | ||
|
||
# カテゴリ属性の設定 | ||
categorical = set( | ||
( | ||
"r_type", | ||
"sex", | ||
"family", | ||
"icd10", | ||
) | ||
) | ||
for name in categorical: | ||
df[name] = df[name].astype("category") | ||
|
||
print(len(df)) | ||
print(df.head()) | ||
|
||
df["birth_ym"] = df["birth_ym"].map(lambda x: calculate_age(x)) | ||
|
||
feature_columns = ["sex", "family", "birth_ym"] | ||
sensitive_column = "iid" | ||
|
||
p = anonypy.Preserver(df, feature_columns, sensitive_column) | ||
rows = p.anonymize_k_anonymity(k=2) | ||
|
||
dfn = pd.DataFrame(rows) | ||
print(len(dfn)) | ||
print(dfn.head()) |