Skip to content

Commit

Permalink
Add showcase for computing t-closeness (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
zinwang authored Jul 27, 2023
1 parent 3b1ac60 commit 2f425df
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,45 @@ $ python3 l-diversity.py
}
```

#### Compute the t-closeness

```python
from PETWorks import PETValidation, report
from PETWorks.attributetypes import (
SENSITIVE_ATTRIBUTE,
QUASI_IDENTIFIER,
)

anonymized = "data/patient_anonymized.csv"
dataHierarchy = "data/patient_hierarchy"

attributeTypes = {
"ZIPCode": QUASI_IDENTIFIER,
"Age": QUASI_IDENTIFIER,
"Disease": SENSITIVE_ATTRIBUTE,
}

result = PETValidation(
None,
anonymized,
"t-closeness",
dataHierarchy=dataHierarchy,
attributeTypes=attributeTypes,
tLimit=0.376,
)
report(result, "json")
```

Execution Result

```
$ python3 t-closeness.py
{
"t": 0.376,
"fulfill t-closeness": true
}
```

#### Anonymize with the k-anonymity

```python
Expand Down
10 changes: 10 additions & 0 deletions data/patient_anonymized.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ZIPCode;Age;Salary;Disease
4767*;<=40;3;gastric ulcer
4760*;<=40;4;gastritis
4767*;<=40;5;stomach cancer
4790*;>40;6;gastritis
4790*;>40;11;flu
4790*;>40;8;bronchitis
4760*;<=40;7;bronchitis
4767*;<=40;9;pneumonia
4760*;<=40;10;stomach cancer
9 changes: 9 additions & 0 deletions data/patient_hierarchy/patient_hierarchy_Age.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
29;[20,30[;*
22;[20,30[;*
27;[20,30[;*
43;>=40;*
52;>=40;*
47;>=40;*
30;[30,40[;*
36;[30,40[;*
32;[30,40[;*
6 changes: 6 additions & 0 deletions data/patient_hierarchy/patient_hierarchy_Disease.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gastric ulcer;stomach disease;digestive system disease;respiratory&digestive disease
gastritis;stomach disease;digestive system disease;respiratory&digestive disease
flu;respiratory infection;vascular lung disease;respiratory&digestive disease
bronchitis;respiratory infection;vascular lung disease;respiratory&digestive disease
pneumonia;respiratory infection;vascular lung disease;respiratory&digestive disease
stomach cancer;stomach disease;digestive system disease;respiratory&digestive disease
9 changes: 9 additions & 0 deletions data/patient_hierarchy/patient_hierarchy_ZIPCode.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
47677;4767*;476**;47***;4****;*****
47602;4760*;476**;47***;4****;*****
47678;4767*;476**;47***;4****;*****
47905;4790*;479**;47***;4****;*****
47909;4790*;479**;47***;4****;*****
47906;4790*;479**;47***;4****;*****
47605;4760*;476**;47***;4****;*****
47673;4767*;476**;47***;4****;*****
47607;4760*;476**;47***;4****;*****

0 comments on commit 2f425df

Please sign in to comment.