Datasets:
Upload 3 files
Browse files- README.md +53 -1
- agaricus-lepiota.data +0 -0
- mushroom.py +329 -0
README.md
CHANGED
@@ -1,3 +1,55 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
tags:
|
5 |
+
- adult
|
6 |
+
- tabular_classification
|
7 |
+
- binary_classification
|
8 |
+
- multiclass_classification
|
9 |
+
pretty_name: Adult
|
10 |
+
size_categories:
|
11 |
+
- 10K<n<100K
|
12 |
+
task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
|
13 |
+
- tabular-classification
|
14 |
+
configs:
|
15 |
+
- encoding
|
16 |
+
- income
|
17 |
+
- income-no race
|
18 |
+
- race
|
19 |
---
|
20 |
+
# Adult
|
21 |
+
The [Adult dataset](https://archive.ics.uci.edu/ml/datasets/Adult) from the [UCI ML repository](https://archive.ics.uci.edu/ml/datasets).
|
22 |
+
Census dataset including personal characteristic of a person, and their income threshold.
|
23 |
+
|
24 |
+
# Configurations and tasks
|
25 |
+
| **Configuration** | **Task** | **Description** |
|
26 |
+
|-------------------|---------------------------|---------------------------------------------------------------|
|
27 |
+
| encoding | | Encoding dictionary |
|
28 |
+
| income | Binary classification | Classify the person's income as over or under the threshold. |
|
29 |
+
| income-no race | Binary classification | As `income`, but the `race` feature is removed. |
|
30 |
+
| race | Multiclass classification | Predict the race of the individual. |
|
31 |
+
|
32 |
+
# Usage
|
33 |
+
```python
|
34 |
+
from datasets import load_dataset
|
35 |
+
|
36 |
+
dataset = load_dataset("mstz/adult", "income")["train"]
|
37 |
+
```
|
38 |
+
|
39 |
+
# Features
|
40 |
+
|**Feature** |**Type** | **Description** |
|
41 |
+
|-------------------|-----------|-----------------------------------------------------------|
|
42 |
+
|`age` |`[int64]` | Age of the person |
|
43 |
+
|`capital_gain` |`[float64]`| Capital gained by the person |
|
44 |
+
|`capital_loss` |`[float64]`| Capital lost by the person |
|
45 |
+
|`education` |`[int8]` | Education level: the higher, the more educated the person |
|
46 |
+
|`final_weight` |`[int64]` | |
|
47 |
+
|`hours_per_week` |`[int64]` | Hours worked per week |
|
48 |
+
|`marital_status` |`[string]` | Marital status of the person |
|
49 |
+
|`native_country` |`[string]` | Native country of the person |
|
50 |
+
|`occupation` |`[string]` | Job of the person |
|
51 |
+
|`race` |`[string]` | Race of the person |
|
52 |
+
|`relationship` |`[string]` | |
|
53 |
+
|`sex` |`[int8]` | Sex of the person |
|
54 |
+
|`workclass` |`[string]` | Type of job of the person |
|
55 |
+
|`over_threshold` |`int8` |`1` for income `>= 50k$`, `0` otherwise |
|
agaricus-lepiota.data
ADDED
The diff for this file is too large to render.
See raw diff
|
|
mushroom.py
ADDED
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
VERSION = datasets.Version("1.0.0")
|
12 |
+
_ORIGINAL_FEATURE_NAMES = [
|
13 |
+
"is_poisonous",
|
14 |
+
"cap_shape",
|
15 |
+
"cap_surface",
|
16 |
+
"cap_color",
|
17 |
+
"has_bruises",
|
18 |
+
"odor",
|
19 |
+
"gill_attachment",
|
20 |
+
"gill_spacing",
|
21 |
+
"gill_size",
|
22 |
+
"gill_color",
|
23 |
+
"stalk_shape",
|
24 |
+
"stalk_root",
|
25 |
+
"stalk_surface_above_ring",
|
26 |
+
"stalk_surface_belows_ring",
|
27 |
+
"stalk_color_above_ring",
|
28 |
+
"stalk_color_belows_ring",
|
29 |
+
"veil_type",
|
30 |
+
"veil_color",
|
31 |
+
"number_of_rings",
|
32 |
+
"ring_type",
|
33 |
+
"spore_print_color",
|
34 |
+
"population",
|
35 |
+
"habitat",
|
36 |
+
"is_poisonous"
|
37 |
+
]
|
38 |
+
_BASE_FEATURE_NAMES = [
|
39 |
+
"cap_shape",
|
40 |
+
"cap_surface",
|
41 |
+
"cap_color",
|
42 |
+
"has_bruises",
|
43 |
+
"odor",
|
44 |
+
"gill_attachment",
|
45 |
+
"gill_spacing",
|
46 |
+
"gill_size",
|
47 |
+
"gill_color",
|
48 |
+
"stalk_shape",
|
49 |
+
"stalk_surface_above_ring",
|
50 |
+
"stalk_surface_belows_ring",
|
51 |
+
"stalk_color_above_ring",
|
52 |
+
"stalk_color_belows_ring",
|
53 |
+
"veil_type",
|
54 |
+
"veil_color",
|
55 |
+
"number_of_rings",
|
56 |
+
"ring_type",
|
57 |
+
"spore_print_color",
|
58 |
+
"population",
|
59 |
+
"habitat"
|
60 |
+
]
|
61 |
+
|
62 |
+
_ENCODING_DICS = {
|
63 |
+
"is_poisonous": {
|
64 |
+
"p": 1,
|
65 |
+
"e": 0
|
66 |
+
},
|
67 |
+
"cap_shape": {
|
68 |
+
"b": "bell",
|
69 |
+
"c": "conical",
|
70 |
+
"x": "convex",
|
71 |
+
"f": "flat",
|
72 |
+
"k": "knobbed",
|
73 |
+
"s": "sunken",
|
74 |
+
},
|
75 |
+
"cap_surface": {
|
76 |
+
"f": "fibrous",
|
77 |
+
"g": "grooves",
|
78 |
+
"y": "scaly",
|
79 |
+
"s": "smooth"
|
80 |
+
},
|
81 |
+
"cap_color": {
|
82 |
+
"n": "brown",
|
83 |
+
"b": "buff",
|
84 |
+
"c": "cinnamon",
|
85 |
+
"g": "gray",
|
86 |
+
"r": "green",
|
87 |
+
"p": "pink",
|
88 |
+
"u": "purple",
|
89 |
+
"e": "red",
|
90 |
+
"w": "white",
|
91 |
+
"y": "yellow"
|
92 |
+
},
|
93 |
+
"has_bruises": {
|
94 |
+
"f": False,
|
95 |
+
"t": True
|
96 |
+
},
|
97 |
+
"odor": {
|
98 |
+
"a": "almond",
|
99 |
+
"l": "anise",
|
100 |
+
"c": "creosote",
|
101 |
+
"y": "fishy",
|
102 |
+
"f": "foul",
|
103 |
+
"m": "musty",
|
104 |
+
"n": "none",
|
105 |
+
"p": "pungent",
|
106 |
+
"s": "spicy"
|
107 |
+
},
|
108 |
+
"gill_attachment": {
|
109 |
+
"a": "attached",
|
110 |
+
"d": "descending",
|
111 |
+
"f": "free",
|
112 |
+
"n": "notched",
|
113 |
+
},
|
114 |
+
"gill_spacing": {
|
115 |
+
"c": "close",
|
116 |
+
"w": "crowded",
|
117 |
+
"d": "distant",
|
118 |
+
},
|
119 |
+
"gill_size": {
|
120 |
+
"b": "broad",
|
121 |
+
"n": "narrow"
|
122 |
+
},
|
123 |
+
"gill_color": {
|
124 |
+
"k": "black",
|
125 |
+
"n": "brown",
|
126 |
+
"b": "buff",
|
127 |
+
"h": "chocolate",
|
128 |
+
"g": "gray",
|
129 |
+
"r": "green",
|
130 |
+
"o": "orange",
|
131 |
+
"p": "pink",
|
132 |
+
"u": "purple",
|
133 |
+
"e": "red",
|
134 |
+
"w": "white",
|
135 |
+
"y": "yellow",
|
136 |
+
},
|
137 |
+
"stalk_shape": {
|
138 |
+
"e": "enlarging",
|
139 |
+
"t": "tapering",
|
140 |
+
},
|
141 |
+
"stalk_surface_above_ring": {
|
142 |
+
"f": "fibrous",
|
143 |
+
"y": "scaly",
|
144 |
+
"k": "silky",
|
145 |
+
"s": "smooth",
|
146 |
+
},
|
147 |
+
"stalk_surface_above_ring": {
|
148 |
+
"f": "fibrous",
|
149 |
+
"y": "scaly",
|
150 |
+
"k": "silky",
|
151 |
+
"s": "smooth",
|
152 |
+
},
|
153 |
+
"stalk_color_above_ring": {
|
154 |
+
"n": "brown",
|
155 |
+
"b": "buff",
|
156 |
+
"c": "cinnamon",
|
157 |
+
"g": "gray",
|
158 |
+
"o": "orange",
|
159 |
+
"p": "pink",
|
160 |
+
"e": "red",
|
161 |
+
"w": "white",
|
162 |
+
"y": "yellow",
|
163 |
+
},
|
164 |
+
"stalk_color_below_ring": {
|
165 |
+
"n": "brown",
|
166 |
+
"b": "buff",
|
167 |
+
"c": "cinnamon",
|
168 |
+
"g": "gray",
|
169 |
+
"o": "orange",
|
170 |
+
"p": "pink",
|
171 |
+
"e": "red",
|
172 |
+
"w": "white",
|
173 |
+
"y": "yellow",
|
174 |
+
},
|
175 |
+
"veil_type": {
|
176 |
+
"p": "partial",
|
177 |
+
"u": "universal",
|
178 |
+
},
|
179 |
+
"veil_color": {
|
180 |
+
"n": "brown",
|
181 |
+
"o": "orange",
|
182 |
+
"w": "white",
|
183 |
+
"y": "yellow",
|
184 |
+
},
|
185 |
+
"ring_number": {
|
186 |
+
"n": 0,
|
187 |
+
"o": 1,
|
188 |
+
"t": 2,
|
189 |
+
},
|
190 |
+
"ring_type": {
|
191 |
+
"c": "cobwebby",
|
192 |
+
"e": "evanescent",
|
193 |
+
"f": "flaring",
|
194 |
+
"l": "large",
|
195 |
+
"n": "none",
|
196 |
+
"p": "pendant",
|
197 |
+
"s": "sheathing",
|
198 |
+
"z": "zone",
|
199 |
+
},
|
200 |
+
"spore_print_color": {
|
201 |
+
"k": "black",
|
202 |
+
"n": "brown",
|
203 |
+
"b": "buff",
|
204 |
+
"h": "chocolate",
|
205 |
+
"r": "green",
|
206 |
+
"o": "orange",
|
207 |
+
"u": "purple",
|
208 |
+
"w": "white",
|
209 |
+
"y": "yellow",
|
210 |
+
},
|
211 |
+
"population": {
|
212 |
+
"a": "abundant",
|
213 |
+
"c": "clustered",
|
214 |
+
"n": "numerous",
|
215 |
+
"s": "scattered",
|
216 |
+
"v": "several",
|
217 |
+
"y": "solitary",
|
218 |
+
},
|
219 |
+
"habitat": {
|
220 |
+
"g": "grasses",
|
221 |
+
"l": "leaves",
|
222 |
+
"m": "meadows",
|
223 |
+
"p": "paths",
|
224 |
+
"u": "urban",
|
225 |
+
"w": "waste",
|
226 |
+
"d": "woods",
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
DESCRIPTION = "Mushroom dataset from the UCI ML repository."
|
231 |
+
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Mushroom"
|
232 |
+
_URLS = ("https://huggingface.co/datasets/mstz/mushroom/raw/mushroom.csv")
|
233 |
+
_CITATION = """
|
234 |
+
@misc{misc_mushroom_73,
|
235 |
+
title = {{Mushroom}},
|
236 |
+
year = {1987},
|
237 |
+
howpublished = {UCI Machine Learning Repository},
|
238 |
+
note = {{DOI}: \\url{10.24432/C5959T}}
|
239 |
+
}"""
|
240 |
+
|
241 |
+
# Dataset info
|
242 |
+
urls_per_split = {
|
243 |
+
"train": "https://huggingface.co/datasets/mstz/mushroom/raw/main/agaricus-lepiota.data"
|
244 |
+
}
|
245 |
+
features_types_per_config = {
|
246 |
+
"mushroom": {
|
247 |
+
"cap_shape",
|
248 |
+
"cap_surface",
|
249 |
+
"cap_color",
|
250 |
+
"has_bruises",
|
251 |
+
"odor",
|
252 |
+
"gill_attachment",
|
253 |
+
"gill_spacing",
|
254 |
+
"gill_size",
|
255 |
+
"gill_color",
|
256 |
+
"stalk_shape",
|
257 |
+
"stalk_root",
|
258 |
+
"stalk_surface_above_ring",
|
259 |
+
"stalk_surface_belows_ring",
|
260 |
+
"stalk_color_above_ring",
|
261 |
+
"stalk_color_belows_ring",
|
262 |
+
"veil_type",
|
263 |
+
"veil_color",
|
264 |
+
"number_of_rings",
|
265 |
+
"ring_type",
|
266 |
+
"spore_print_color",
|
267 |
+
"population",
|
268 |
+
"habitat",
|
269 |
+
"is_poisonous": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
270 |
+
}
|
271 |
+
}
|
272 |
+
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
273 |
+
|
274 |
+
|
275 |
+
class MushroomConfig(datasets.BuilderConfig):
|
276 |
+
def __init__(self, **kwargs):
|
277 |
+
super(MushroomConfig, self).__init__(version=VERSION, **kwargs)
|
278 |
+
self.features = features_per_config[kwargs["name"]]
|
279 |
+
|
280 |
+
|
281 |
+
class Mushroom(datasets.GeneratorBasedBuilder):
|
282 |
+
# dataset versions
|
283 |
+
DEFAULT_CONFIG = "mushroom"
|
284 |
+
BUILDER_CONFIGS = [
|
285 |
+
MushroomConfig(name="mushroom",
|
286 |
+
description="Mushroom for binary classification."),
|
287 |
+
]
|
288 |
+
|
289 |
+
def _info(self):
|
290 |
+
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
291 |
+
features=features_per_config[self.config.name])
|
292 |
+
|
293 |
+
return info
|
294 |
+
|
295 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
296 |
+
downloads = dl_manager.download_and_extract(urls_per_split)
|
297 |
+
|
298 |
+
return [
|
299 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]})
|
300 |
+
]
|
301 |
+
|
302 |
+
def _generate_examples(self, filepath: str):
|
303 |
+
data = pandas.read_csv(filepath)
|
304 |
+
data = self.preprocess(data, config=self.config.name)
|
305 |
+
|
306 |
+
for row_id, row in data.iterrows():
|
307 |
+
data_row = dict(row)
|
308 |
+
|
309 |
+
yield row_id, data_row
|
310 |
+
|
311 |
+
|
312 |
+
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
|
313 |
+
data.drop("stalk_root", axis="columns", inplace=True)
|
314 |
+
data = data[list(features_types_per_config[config].keys())]
|
315 |
+
|
316 |
+
for feature in _ENCODING_DICS:
|
317 |
+
encoding_function = partial(self.encode, feature)
|
318 |
+
data.loc[:, feature] = data[feature].apply(encoding_function)
|
319 |
+
data = data.infer_objects()
|
320 |
+
|
321 |
+
return
|
322 |
+
|
323 |
+
def encode(self, feature, value):
|
324 |
+
if feature in _ENCODING_DICS:
|
325 |
+
return _ENCODING_DICS[feature][value]
|
326 |
+
raise ValueError(f"Unknown feature: {feature}")
|
327 |
+
|
328 |
+
def encode_race(self, race):
|
329 |
+
return _RACE_ENCODING[race]
|