-
Notifications
You must be signed in to change notification settings - Fork 1
/
E06_stats_dataset.py
153 lines (102 loc) · 4.02 KB
/
E06_stats_dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import sys
import warnings
if not sys.warnoptions:
warnings.simplefilter("ignore")
import os
DATASET_DIRECTORY = os.path.join(os.path.curdir, "datasets")
def count_per_type(d):
attr_types = dict(d.dtypes)
cat = []
for a, t in attr_types.items():
if t == object:
cat.append(a)
cont = list(set(attr_types.keys()) - set(cat))
return (len(d), len(d.columns), len(cont), len(cat))
def dataset_descriptions(
name_output_dir="output",
dataset_dir=DATASET_DIRECTORY,
dataset_experiment=["adult", "artificial_10", "bank", "compas", "german", "heart"],
):
import numpy as np
import pandas as pd
import os
from pathlib import Path
out_table = {}
if "adult" in dataset_experiment:
dataset_name = "adult"
from import_datasets import import_process_adult
dfI, _ = import_process_adult(inputDir=dataset_dir)
attributes = dfI.columns.drop("class")
out_table[dataset_name] = count_per_type(dfI[attributes])
if "bank" in dataset_experiment:
dataset_name = "bank"
from import_datasets import import_process_bank
dfI, _ = import_process_bank(inputDir=dataset_dir)
attributes = dfI.columns.drop("class")
out_table[dataset_name] = count_per_type(dfI[attributes])
if "compas" in dataset_experiment:
dataset_name = "compas"
risk_class_type = True
# Probublica analysis https://www.propublica.org/article/how-we-analyzed-the-compas-recidivism-algorithm
from import_datasets import import_process_compas
dfI, _ = import_process_compas(risk_class=risk_class_type)
attributes = dfI.columns.drop(["class", "predicted"])
out_table[dataset_name] = count_per_type(dfI[attributes])
if "german" in dataset_experiment:
dataset_name = "german"
from import_datasets import import_process_german
dfI, _ = import_process_german(inputDir=dataset_dir)
attributes = dfI.columns.drop("class")
out_table[dataset_name] = count_per_type(dfI[attributes])
if "heart" in dataset_experiment:
dataset_name = "heart"
from import_datasets import import_process_heart
dfI, _ = import_process_heart(inputDir=dataset_dir)
attributes = dfI.columns.drop("class")
out_table[dataset_name] = count_per_type(dfI[attributes])
if "artificial_10" in dataset_experiment:
dataset_name = "artificial_10"
data = np.concatenate([np.full((25000, 10), 0), np.full((25000, 10), 1)])
out_table[dataset_name] = len(data), 10, 0, 10
out_table = pd.DataFrame(out_table).T.reset_index()
out_table.columns = [
"dataset",
"|D|",
"|A|",
"|A|_cont",
"|A|_cat",
]
print(out_table)
outputdir = os.path.join(os.path.curdir, name_output_dir, "tables")
print(f"Output in directory {outputdir}")
Path(outputdir).mkdir(parents=True, exist_ok=True)
filename = os.path.join(outputdir, "table_4.csv")
out_table.to_csv(filename, index=False)
caption_str = "Table 4: Dataset characteristics. A_cont is the set of continuous attributes, A_cat of categorical ones."
print(caption_str)
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--name_output_dir",
default="output",
help="specify the name of the output folder",
)
parser.add_argument(
"--dataset_experiment",
nargs="*",
type=str,
default=["adult", "artificial_10", "bank", "compas", "german", "heart"],
help='specify a list of dataset among ["adult", "artificial_10", "bank", "compas", "german", "heart"]',
)
parser.add_argument(
"--dataset_dir",
default=DATASET_DIRECTORY,
help="specify the dataset directory",
)
args = parser.parse_args()
dataset_descriptions(
name_output_dir=args.name_output_dir,
dataset_dir=args.dataset_dir,
dataset_experiment=args.dataset_experiment,
)