mstz commited on
Commit
76f8216
·
1 Parent(s): c6dab47

updated to datasets 4.*

Browse files
Files changed (7) hide show
  1. README.md +26 -14
  2. adult.py +0 -250
  3. adult_tr.csv +0 -0
  4. adult_ts.csv +0 -0
  5. income-no race/train.csv +0 -0
  6. income/train.csv +0 -0
  7. race/train.csv +0 -0
README.md CHANGED
@@ -1,23 +1,36 @@
1
  ---
2
- language:
3
- - en
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  tags:
5
- - adult
6
  - tabular_classification
7
  - binary_classification
8
  - multiclass_classification
9
- - UCI
10
- pretty_name: Adult
11
- size_categories:
12
- - 10K<n<100K
13
  task_categories:
14
  - tabular-classification
15
- configs:
16
- - encoding
17
- - income
18
- - income-no race
19
- - race
20
- license: cc
21
  ---
22
  # Adult
23
  The [Adult dataset](https://archive.ics.uci.edu/ml/datasets/Adult) from the [UCI ML repository](https://archive.ics.uci.edu/ml/datasets).
@@ -26,7 +39,6 @@ Census dataset including personal characteristic of a person, and their income t
26
  # Configurations and tasks
27
  | **Configuration** | **Task** | Description |
28
  |-------------------|---------------------------|-----------------------------------------------------------------|
29
- | encoding | | Encoding dictionary showing original values of encoded features.|
30
  | income | Binary classification | Classify the person's income as over or under the threshold. |
31
  | income-no race | Binary classification | As `income`, but the `race` feature is removed. |
32
  | race | Multiclass classification | Predict the race of the individual. |
 
1
  ---
2
+ configs:
3
+ - config_name: income
4
+ data_files:
5
+ - path: income/train.csv
6
+ split: train
7
+ - path: income/test.csv
8
+ split: test
9
+ default: true
10
+ - config_name: income-no race
11
+ data_files:
12
+ - path: income-no race/train.csv
13
+ split: train
14
+ - path: income-no race/test.csv
15
+ split: test
16
+ default: false
17
+ - config_name: race
18
+ data_files:
19
+ - path: race/train.csv
20
+ split: train
21
+ - path: race/test.csv
22
+ split: test
23
+ default: false
24
+ language: en
25
+ license: cc
26
+ pretty_name: Adult
27
+ size_categories: 1M<n<10M
28
  tags:
 
29
  - tabular_classification
30
  - binary_classification
31
  - multiclass_classification
 
 
 
 
32
  task_categories:
33
  - tabular-classification
 
 
 
 
 
 
34
  ---
35
  # Adult
36
  The [Adult dataset](https://archive.ics.uci.edu/ml/datasets/Adult) from the [UCI ML repository](https://archive.ics.uci.edu/ml/datasets).
 
39
  # Configurations and tasks
40
  | **Configuration** | **Task** | Description |
41
  |-------------------|---------------------------|-----------------------------------------------------------------|
 
42
  | income | Binary classification | Classify the person's income as over or under the threshold. |
43
  | income-no race | Binary classification | As `income`, but the `race` feature is removed. |
44
  | race | Multiclass classification | Predict the race of the individual. |
adult.py DELETED
@@ -1,250 +0,0 @@
1
- from typing import List
2
- from functools import partial
3
-
4
- import datasets
5
-
6
- import pandas
7
-
8
-
9
- VERSION = datasets.Version("1.0.0")
10
- _ORIGINAL_FEATURE_NAMES = [
11
- "age",
12
- "workclass",
13
- "final_weight",
14
- "education",
15
- "education-num",
16
- "marital_status",
17
- "occupation",
18
- "relationship",
19
- "race",
20
- "sex",
21
- "capital_gain",
22
- "capital_loss",
23
- "hours_per_week",
24
- "native_country",
25
- "threshold"
26
- ]
27
- _BASE_FEATURE_NAMES = [
28
- "age",
29
- "capital_gain",
30
- "capital_loss",
31
- "education",
32
- "final_weight",
33
- "hours_worked_per_week",
34
- "marital_status",
35
- "native_country",
36
- "occupation",
37
- "race",
38
- "relationship",
39
- "is_male",
40
- "workclass",
41
- "over_threshold",
42
- ]
43
- _ENCODING_DICS = {
44
- "is_male": {
45
- "Male": True,
46
- "Female": False
47
- }
48
- }
49
- _RACE_ENCODING = {
50
- "White": 0,
51
- "Black": 1,
52
- "Asian-Pac-Islander": 2,
53
- "Amer-Indian-Eskimo": 3,
54
- "Other": 4,
55
- }
56
- _EDUCATION_ENCODING = {
57
- "Preschool": 0,
58
- "1st-4th": 1,
59
- "5th-6th": 2,
60
- "7th-8th": 3,
61
- "9th": 4,
62
- "10th": 5,
63
- "11th": 6,
64
- "12th": 7,
65
- "HS-grad": 8,
66
- "Assoc-acdm": 9,
67
- "Assoc-voc": 10,
68
- "Some-college": 11,
69
- "Bachelors": 12,
70
- "Masters": 13,
71
- "Doctorate": 14,
72
- "Prof-school": 15
73
- }
74
-
75
- DESCRIPTION = "Adult dataset from the UCI ML repository."
76
- _HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Adult"
77
- _URLS = ("https://huggingface.co/datasets/mstz/adult/raw/adult.csv")
78
- _CITATION = """
79
- @inproceedings{DBLP:conf/kdd/Kohavi96,
80
- author = {Ron Kohavi},
81
- editor = {Evangelos Simoudis and
82
- Jiawei Han and
83
- Usama M. Fayyad},
84
- title = {Scaling Up the Accuracy of Naive-Bayes Classifiers: {A} Decision-Tree
85
- Hybrid},
86
- booktitle = {Proceedings of the Second International Conference on Knowledge Discovery
87
- and Data Mining (KDD-96), Portland, Oregon, {USA}},
88
- pages = {202--207},
89
- publisher = {{AAAI} Press},
90
- year = {1996},
91
- url = {http://www.aaai.org/Library/KDD/1996/kdd96-033.php},
92
- timestamp = {Mon, 05 Jun 2017 13:20:21 +0200},
93
- biburl = {https://dblp.org/rec/conf/kdd/Kohavi96.bib},
94
- bibsource = {dblp computer science bibliography, https://dblp.org}
95
- }"""
96
-
97
- # Dataset info
98
- urls_per_split = {
99
- "train": "https://huggingface.co/datasets/mstz/adult/raw/main/adult_tr.csv",
100
- "test": "https://huggingface.co/datasets/mstz/adult/raw/main/adult_ts.csv"
101
- }
102
- features_types_per_config = {
103
- "encoding": {
104
- "feature": datasets.Value("string"),
105
- "original_value": datasets.Value("string"),
106
- "encoded_value": datasets.Value("int64"),
107
- },
108
- "income": {
109
- "age": datasets.Value("int64"),
110
- "capital_gain": datasets.Value("float64"),
111
- "capital_loss": datasets.Value("float64"),
112
- "education": datasets.Value("int8"),
113
- "final_weight": datasets.Value("int64"),
114
- "hours_worked_per_week": datasets.Value("int64"),
115
- "marital_status": datasets.Value("string"),
116
- "native_country": datasets.Value("string"),
117
- "occupation": datasets.Value("string"),
118
- "race": datasets.Value("string"),
119
- "relationship": datasets.Value("string"),
120
- "is_male": datasets.Value("bool"),
121
- "workclass": datasets.Value("string"),
122
- "over_threshold": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
123
- },
124
- "income-no race": {
125
- "age": datasets.Value("int64"),
126
- "capital_gain": datasets.Value("float64"),
127
- "capital_loss": datasets.Value("float64"),
128
- "education": datasets.Value("int64"),
129
- "final_weight": datasets.Value("int64"),
130
- "hours_worked_per_week": datasets.Value("int64"),
131
- "marital_status": datasets.Value("string"),
132
- "native_country": datasets.Value("string"),
133
- "occupation": datasets.Value("string"),
134
- "relationship": datasets.Value("string"),
135
- "is_male": datasets.Value("bool"),
136
- "workclass": datasets.Value("string"),
137
- "over_threshold": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
138
- },
139
- "race": {
140
- "age": datasets.Value("int64"),
141
- "capital_gain": datasets.Value("float64"),
142
- "capital_loss": datasets.Value("float64"),
143
- "education": datasets.Value("int64"),
144
- "final_weight": datasets.Value("int64"),
145
- "hours_worked_per_week": datasets.Value("int64"),
146
- "marital_status": datasets.Value("string"),
147
- "native_country": datasets.Value("string"),
148
- "occupation": datasets.Value("string"),
149
- "relationship": datasets.Value("string"),
150
- "is_male": datasets.Value("bool"),
151
- "workclass": datasets.Value("string"),
152
- "over_threshold": datasets.Value("int8"),
153
- "race": datasets.ClassLabel(num_classes=5, names=["White", "Black", "Asian-Pac-Islander", "Amer-Indian-Eskimo", "Other"])
154
- }
155
- }
156
- features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
157
-
158
-
159
- class AdultConfig(datasets.BuilderConfig):
160
- def __init__(self, **kwargs):
161
- super(AdultConfig, self).__init__(version=VERSION, **kwargs)
162
- self.features = features_per_config[kwargs["name"]]
163
-
164
-
165
- class Adult(datasets.GeneratorBasedBuilder):
166
- # dataset versions
167
- DEFAULT_CONFIG = "income"
168
- BUILDER_CONFIGS = [
169
- AdultConfig(name="income",
170
- description="Adult for income threshold binary classification."),
171
- AdultConfig(name="income-no race",
172
- description="Adult for income threshold binary classification, race excluded from features."),
173
- AdultConfig(name="race",
174
- description="Adult for race (multiclass) classification."),
175
- AdultConfig(name="encoding",
176
- description="Encoding dictionaries for discrete features.")
177
- ]
178
-
179
-
180
- def _info(self):
181
- info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
182
- features=features_per_config[self.config.name])
183
-
184
- return info
185
-
186
- def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
187
- downloads = dl_manager.download_and_extract(urls_per_split)
188
-
189
- return [
190
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
191
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloads["test"]}),
192
- ]
193
-
194
- def _generate_examples(self, filepath: str):
195
- if self.config.name == "encoding":
196
- data = self.encodings()
197
-
198
- for row_id, row in data.iterrows():
199
- data_row = dict(row)
200
-
201
- yield row_id, data_row
202
-
203
- else:
204
- data = pandas.read_csv(filepath)
205
- data = self.preprocess(data, config=self.config.name)
206
-
207
- for row_id, row in data.iterrows():
208
- data_row = dict(row)
209
-
210
- yield row_id, data_row
211
-
212
- def encodings(self):
213
- data = pandas.DataFrame([("education", original_value, encoded_value)
214
- for original_value, encoded_value in _EDUCATION_ENCODING.items()],
215
- columns=["feature", "original_value", "encoded_value"])
216
-
217
- return data
218
-
219
-
220
- def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
221
- data.drop("education", axis="columns", inplace=True)
222
- data = data.rename(columns={"threshold": "over_threshold", "sex": "is_male"})
223
-
224
- data = data[["age", "capital_gain", "capital_loss", "education-num", "final_weight",
225
- "hours_per_week", "marital_status", "native_country", "occupation",
226
- "race", "relationship", "is_male", "workclass", "over_threshold"]]
227
- data.columns = _BASE_FEATURE_NAMES
228
-
229
- for feature in _ENCODING_DICS:
230
- encoding_function = partial(self.encode, feature)
231
- data.loc[:, feature] = data[feature].apply(encoding_function)
232
-
233
-
234
- if config == "income":
235
- return data[list(features_types_per_config["income"].keys())]
236
- elif config == "income-no race":
237
- return data[list(features_types_per_config["income-no race"].keys())]
238
- elif config =="race":
239
- data.loc[:, "race"] = data.race.apply(self.encode_race)
240
- data = data[list(features_types_per_config["race"].keys())]
241
-
242
- return data
243
-
244
- def encode(self, feature, value):
245
- if feature in _ENCODING_DICS:
246
- return _ENCODING_DICS[feature][value]
247
- raise ValueError(f"Unknown feature: {feature}")
248
-
249
- def encode_race(self, race):
250
- return _RACE_ENCODING[race]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adult_tr.csv DELETED
The diff for this file is too large to render. See raw diff
 
adult_ts.csv DELETED
The diff for this file is too large to render. See raw diff
 
income-no race/train.csv ADDED
The diff for this file is too large to render. See raw diff
 
income/train.csv ADDED
The diff for this file is too large to render. See raw diff
 
race/train.csv ADDED
The diff for this file is too large to render. See raw diff