mstz commited on
Commit
b707e93
·
1 Parent(s): f74f2dc

First commit

Browse files
Files changed (4) hide show
  1. README.md +16 -0
  2. adult.py +191 -0
  3. adult_tr.csv +0 -0
  4. adult_ts.csv +0 -0
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - {en} # Example: fr
4
+ tags:
5
+ - {adult} # Example: audio
6
+ - {tabular_classification} # Example: bio
7
+ - {binary_classification} # Example: bio
8
+ pretty_name: {Adult} # Example: SQuAD
9
+ size_categories:
10
+ - {10K<n<100K} # Example: n<1K, 100K<n<1M, …
11
+ task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
12
+ - {tabular}
13
+ configs: # Optional for datasets with multiple configurations like glue.
14
+ - {income} # Example for glue: sst2
15
+ - {income-no race} # Example for glue: cola
16
+ - {race} # Example for glue: cola
adult.py ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Diva: A Fraud Detection Dataset"""
2
+
3
+ import datasets
4
+
5
+ import pandas
6
+
7
+
8
+ VERSION = datasets.Version("1.0.0")
9
+ __ORIGINAL_FEATURE_NAMES = [
10
+ "age",
11
+ "workclass",
12
+ "final_weight",
13
+ "education", "education-num",
14
+ "marital_status",
15
+ "occupation",
16
+ "relationship",
17
+ "race",
18
+ "sex",
19
+ "capital_gain",
20
+ "capital_loss",
21
+ "hours_per_week",
22
+ "native_country",
23
+ "threshold"
24
+ ]
25
+ __BASE_FEATURE_NAMES = [
26
+ "age",
27
+ "capital_gain",
28
+ "capital_loss",
29
+ "education",
30
+ "final_weight",
31
+ "hours_per_week",
32
+ "marital_status",
33
+ "native_country",
34
+ "occupation",
35
+ "race",
36
+ "relationship",
37
+ "sex",
38
+ "workclass",
39
+ "threshold",
40
+ ]
41
+ __DESCRIPTION = "Adult dataset from the UCI ML repository."
42
+ __HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Adult"
43
+ __URLS = ("https://huggingface.co/datasets/mstz/adult/raw/adult.csv")
44
+ __CITATION = """
45
+ @inproceedings{DBLP:conf/kdd/Kohavi96,
46
+ author = {Ron Kohavi},
47
+ editor = {Evangelos Simoudis and
48
+ Jiawei Han and
49
+ Usama M. Fayyad},
50
+ title = {Scaling Up the Accuracy of Naive-Bayes Classifiers: {A} Decision-Tree
51
+ Hybrid},
52
+ booktitle = {Proceedings of the Second International Conference on Knowledge Discovery
53
+ and Data Mining (KDD-96), Portland, Oregon, {USA}},
54
+ pages = {202--207},
55
+ publisher = {{AAAI} Press},
56
+ year = {1996},
57
+ url = {http://www.aaai.org/Library/KDD/1996/kdd96-033.php},
58
+ timestamp = {Mon, 05 Jun 2017 13:20:21 +0200},
59
+ biburl = {https://dblp.org/rec/conf/kdd/Kohavi96.bib},
60
+ bibsource = {dblp computer science bibliography, https://dblp.org}
61
+ }"""
62
+
63
+ # Dataset info
64
+ __urls_per_split = {
65
+ "train": "https://huggingface.co/datasets/mstz/adult/raw/adult_tr.csv",
66
+ "test": "https://huggingface.co/datasets/mstz/adult/raw/adult_ts.csv"
67
+ }
68
+ __features_per_config = {
69
+ "income": datasets.Features({"age": datasets.Value("int8"),
70
+ "capital_gain": datasets.Value("float16"),
71
+ "capital_loss": datasets.Value("float16"),
72
+ "education": datasets.Value("int8"),
73
+ "final_weight": datasets.Value("int16"),
74
+ "hours_per_week": datasets.Value("int16"),
75
+ "marital_status": datasets.Value("string"),
76
+ "native_country": datasets.Value("string"),
77
+ "occupation": datasets.Value("string"),
78
+ "race": datasets.Value("string"),
79
+ "relationship": datasets.Value("string"),
80
+ "sex": datasets.Value("binary"),
81
+ "workclass": datasets.Value("binary"),
82
+ "threshold": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
83
+ }),
84
+ "income-no race": datasets.Features({"age": datasets.Value("int8"),
85
+ "capital_gain": datasets.Value("float16"),
86
+ "capital_loss": datasets.Value("float16"),
87
+ "education": datasets.Value("int8"),
88
+ "final_weight": datasets.Value("int16"),
89
+ "hours_per_week": datasets.Value("int16"),
90
+ "marital_status": datasets.Value("string"),
91
+ "native_country": datasets.Value("string"),
92
+ "occupation": datasets.Value("string"),
93
+ "relationship": datasets.Value("string"),
94
+ "sex": datasets.Value("binary"),
95
+ "workclass": datasets.Value("binary"),
96
+ "threshold": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
97
+ }),
98
+ "race": datasets.Features({"age": datasets.Value("int8"),
99
+ "capital_gain": datasets.Value("float16"),
100
+ "capital_loss": datasets.Value("float16"),
101
+ "education": datasets.Value("int8"),
102
+ "final_weight": datasets.Value("int16"),
103
+ "hours_per_week": datasets.Value("int16"),
104
+ "marital_status": datasets.Value("string"),
105
+ "native_country": datasets.Value("string"),
106
+ "occupation": datasets.Value("string"),
107
+ "relationship": datasets.Value("string"),
108
+ "sex": datasets.Value("binary"),
109
+ "workclass": datasets.Value("binary"),
110
+ "over_threshold": datasets.Value("binary"),
111
+ "race": datasets.ClassLabel(num_classes=5, names=["White",
112
+ "Black",
113
+ "Asian-Pac-Islander",
114
+ "Amer-Indian-Eskimo",
115
+ "Other"]),
116
+ }),
117
+ }
118
+
119
+
120
+ class AdultConfig(datasets.BuilderConfig):
121
+ def __init__(self, features: datasets.Features, labels_names: datasets.ClassLabel, **kwargs):
122
+ super(AdultConfig, self).__init__(version = VERSION, **kwargs)
123
+ self.features = features
124
+ self.labels.names = labels_names
125
+
126
+
127
+ class Adult(datasets.GeneratorBasedBuilder):
128
+ # dataset versions
129
+ DEFAULT_CONFIG = "income"
130
+ BUILDER_CONFIGS = [
131
+ datasets.AdultConfig(name="income", version=VERSION,
132
+ description="Adult for income threshold binary classification."),
133
+ datasets.AdultConfig(name="income-no race", version=VERSION,
134
+ description="Adult for income threshold binary classification, race excluded from features."),
135
+ datasets.AdultConfig(name="race", version=VERSION,
136
+ description="Adult for race multiclass classification."),
137
+ ]
138
+
139
+ def _info(self):
140
+ if self.config_name not in __features_per_config:
141
+ raise ValueError(f"Unknown configuration: {self.config_name}")
142
+
143
+ info = datasets.DatasetInfo(description=__DESCRIPTION, citation=__CITATION, homepage=__HOMEPAGE,
144
+ features=__features_per_config[self.config_name])
145
+
146
+ return info
147
+
148
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
149
+ downloads = dl_manager.download_and_extract(__urls_per_split)
150
+
151
+ return [
152
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
153
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloads["test"]}),
154
+ ]
155
+
156
+ def _generate_examples(self, filepath: str):
157
+ data = pandas.read_csv(filepath)
158
+ data = self.preprocess(data, config=self.config_name)
159
+
160
+ for row in data.iterrows():
161
+ data_row = dict(row)
162
+ row_id = hash(str(data_row))
163
+
164
+ yield row_id, data_row
165
+
166
+ def preprocess(self, data: pandas.DataFrame, config: str = "income") -> pandas.DataFrame:
167
+ data.drop(["education"], inplace=True)
168
+ data = data[["age", "capital_gain", "capital_loss", "education", "final_weight",
169
+ "hours_per_week", "marital_status", "native_country", "occupation",
170
+ "race", "relationship", "sex", "workclass", "threshold"]]
171
+ data.columns = __BASE_FEATURE_NAMES
172
+
173
+ return data
174
+
175
+ def income_preprocessing(data: pandas.DataFrame) -> pandas.DataFrame:
176
+ data = data[__features_per_config["income"]]
177
+
178
+ return data
179
+
180
+ def income_norace_preprocessing(data: pandas.DataFrame) -> pandas.DataFrame:
181
+ data = data[__features_per_config["income-no race"]]
182
+
183
+ return data
184
+
185
+ def race_preprocessing(data: pandas.DataFrame) -> pandas.DataFrame:
186
+ data["over_threshold"] = df.threshold
187
+ data = data[__features_per_config["race"]]
188
+
189
+ return data
190
+
191
+ # TODO: add custom split?
adult_tr.csv ADDED
The diff for this file is too large to render. See raw diff
 
adult_ts.csv ADDED
The diff for this file is too large to render. See raw diff