mstz commited on
Commit
4f20cc8
1 Parent(s): 1b3eddb

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +24 -1
  2. optdigits.data +0 -0
  3. optdigits.py +321 -0
README.md CHANGED
@@ -1,3 +1,26 @@
1
  ---
2
- license: cc-by-4.0
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - optdigits
6
+ - tabular_classification
7
+ - binary_classification
8
+ - multiclass_classification
9
+ - UCI
10
+ pretty_name: Optdigits
11
+ task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
12
+ - tabular-classification
13
+ configs:
14
+ - optdigits
15
  ---
16
+ # Optdigits
17
+ The [Optdigits dataset](https://archive-beta.ics.uci.edu/dataset/80/optical+recognition+of+handwritten+digits) from the [UCI repository](https://archive-beta.ics.uci.edu/).
18
+
19
+ # Configurations and tasks
20
+ | **Configuration** | **Task** | **Description** |
21
+ |-----------------------|---------------------------|-------------------------|
22
+ | optdigits | Multiclass classification.| |
23
+ | 0 | Binary classification. | Is this a 0? |
24
+ | 1 | Binary classification. | Is this a 1? |
25
+ | 2 | Binary classification. | Is this a 2? |
26
+ | ... | Binary classification. | ... |
optdigits.data ADDED
The diff for this file is too large to render. See raw diff
 
optdigits.py ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Optdigits Dataset"""
2
+
3
+ from typing import List
4
+ from functools import partial
5
+
6
+ import datasets
7
+
8
+ import pandas
9
+
10
+
11
+ VERSION = datasets.Version("1.0.0")
12
+
13
+ _ENCODING_DICS = {}
14
+ _BASE_FEATURE_NAMES = [
15
+ "att1",
16
+ "att2",
17
+ "att3",
18
+ "att4",
19
+ "att5",
20
+ "att6",
21
+ "att7",
22
+ "att8",
23
+ "att9",
24
+ "att10",
25
+ "att11",
26
+ "att12",
27
+ "att13",
28
+ "att14",
29
+ "att15",
30
+ "att16",
31
+ "att17",
32
+ "att18",
33
+ "att19",
34
+ "att20",
35
+ "att21",
36
+ "att22",
37
+ "att23",
38
+ "att24",
39
+ "att25",
40
+ "att26",
41
+ "att27",
42
+ "att28",
43
+ "att29",
44
+ "att30",
45
+ "att31",
46
+ "att32",
47
+ "att33",
48
+ "att34",
49
+ "att35",
50
+ "att36",
51
+ "att37",
52
+ "att38",
53
+ "att39",
54
+ "att40",
55
+ "att41",
56
+ "att42",
57
+ "att43",
58
+ "att44",
59
+ "att45",
60
+ "att46",
61
+ "att47",
62
+ "att48",
63
+ "att49",
64
+ "att50",
65
+ "att51",
66
+ "att52",
67
+ "att53",
68
+ "att54",
69
+ "att55",
70
+ "att56",
71
+ "att57",
72
+ "att58",
73
+ "att59",
74
+ "att60",
75
+ "att61",
76
+ "att62",
77
+ "att63",
78
+ "att64",
79
+ "class",
80
+ ]
81
+
82
+ DESCRIPTION = "Optdigits dataset."
83
+ _HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/80/optical+recognition+of+handwritten+digits"
84
+ _URLS = ("https://archive-beta.ics.uci.edu/dataset/80/optical+recognition+of+handwritten+digits")
85
+ _CITATION = """
86
+ @misc{misc_optical_recognition_of_handwritten_digits_80,
87
+ author = {Alpaydin,E. & Kaynak,C.},
88
+ title = {{Optical Recognition of Handwritten Digits}},
89
+ year = {1998},
90
+ howpublished = {UCI Machine Learning Repository},
91
+ note = {{DOI}: \\url{10.24432/C50P49}}
92
+ }
93
+ """
94
+
95
+ # Dataset info
96
+ urls_per_split = {
97
+ "train": "https://huggingface.co/datasets/mstz/optdigits/resolve/main/optdigits.data"
98
+ }
99
+ features_types_per_config = {
100
+ "optdigits": {
101
+ "att1": datasets.Value("int64"),
102
+ "att2": datasets.Value("int64"),
103
+ "att3": datasets.Value("int64"),
104
+ "att4": datasets.Value("int64"),
105
+ "att5": datasets.Value("int64"),
106
+ "att6": datasets.Value("int64"),
107
+ "att7": datasets.Value("int64"),
108
+ "att8": datasets.Value("int64"),
109
+ "att9": datasets.Value("int64"),
110
+ "att10": datasets.Value("int64"),
111
+ "att11": datasets.Value("int64"),
112
+ "att12": datasets.Value("int64"),
113
+ "att13": datasets.Value("int64"),
114
+ "att14": datasets.Value("int64"),
115
+ "att15": datasets.Value("int64"),
116
+ "att16": datasets.Value("int64"),
117
+ "att17": datasets.Value("int64"),
118
+ "att18": datasets.Value("int64"),
119
+ "att19": datasets.Value("int64"),
120
+ "att20": datasets.Value("int64"),
121
+ "att21": datasets.Value("int64"),
122
+ "att22": datasets.Value("int64"),
123
+ "att23": datasets.Value("int64"),
124
+ "att24": datasets.Value("int64"),
125
+ "att25": datasets.Value("int64"),
126
+ "att26": datasets.Value("int64"),
127
+ "att27": datasets.Value("int64"),
128
+ "att28": datasets.Value("int64"),
129
+ "att29": datasets.Value("int64"),
130
+ "att30": datasets.Value("int64"),
131
+ "att31": datasets.Value("int64"),
132
+ "att32": datasets.Value("int64"),
133
+ "att33": datasets.Value("int64"),
134
+ "att34": datasets.Value("int64"),
135
+ "att35": datasets.Value("int64"),
136
+ "att36": datasets.Value("int64"),
137
+ "att37": datasets.Value("int64"),
138
+ "att38": datasets.Value("int64"),
139
+ "att39": datasets.Value("int64"),
140
+ "att40": datasets.Value("int64"),
141
+ "att41": datasets.Value("int64"),
142
+ "att42": datasets.Value("int64"),
143
+ "att43": datasets.Value("int64"),
144
+ "att44": datasets.Value("int64"),
145
+ "att45": datasets.Value("int64"),
146
+ "att46": datasets.Value("int64"),
147
+ "att47": datasets.Value("int64"),
148
+ "att48": datasets.Value("int64"),
149
+ "att49": datasets.Value("int64"),
150
+ "att50": datasets.Value("int64"),
151
+ "att51": datasets.Value("int64"),
152
+ "att52": datasets.Value("int64"),
153
+ "att53": datasets.Value("int64"),
154
+ "att54": datasets.Value("int64"),
155
+ "att55": datasets.Value("int64"),
156
+ "att56": datasets.Value("int64"),
157
+ "att57": datasets.Value("int64"),
158
+ "att58": datasets.Value("int64"),
159
+ "att59": datasets.Value("int64"),
160
+ "att60": datasets.Value("int64"),
161
+ "att61": datasets.Value("int64"),
162
+ "att62": datasets.Value("int64"),
163
+ "att63": datasets.Value("int64"),
164
+ "att64": datasets.Value("int64"),
165
+ "class": datasets.ClassLabel(num_classes=10)
166
+ }
167
+ }
168
+ for i in range(10):
169
+ features_types_per_config[str(i)] = {
170
+ "att1": datasets.Value("int64"),
171
+ "att2": datasets.Value("int64"),
172
+ "att3": datasets.Value("int64"),
173
+ "att4": datasets.Value("int64"),
174
+ "att5": datasets.Value("int64"),
175
+ "att6": datasets.Value("int64"),
176
+ "att7": datasets.Value("int64"),
177
+ "att8": datasets.Value("int64"),
178
+ "att9": datasets.Value("int64"),
179
+ "att10": datasets.Value("int64"),
180
+ "att11": datasets.Value("int64"),
181
+ "att12": datasets.Value("int64"),
182
+ "att13": datasets.Value("int64"),
183
+ "att14": datasets.Value("int64"),
184
+ "att15": datasets.Value("int64"),
185
+ "att16": datasets.Value("int64"),
186
+ "att17": datasets.Value("int64"),
187
+ "att18": datasets.Value("int64"),
188
+ "att19": datasets.Value("int64"),
189
+ "att20": datasets.Value("int64"),
190
+ "att21": datasets.Value("int64"),
191
+ "att22": datasets.Value("int64"),
192
+ "att23": datasets.Value("int64"),
193
+ "att24": datasets.Value("int64"),
194
+ "att25": datasets.Value("int64"),
195
+ "att26": datasets.Value("int64"),
196
+ "att27": datasets.Value("int64"),
197
+ "att28": datasets.Value("int64"),
198
+ "att29": datasets.Value("int64"),
199
+ "att30": datasets.Value("int64"),
200
+ "att31": datasets.Value("int64"),
201
+ "att32": datasets.Value("int64"),
202
+ "att33": datasets.Value("int64"),
203
+ "att34": datasets.Value("int64"),
204
+ "att35": datasets.Value("int64"),
205
+ "att36": datasets.Value("int64"),
206
+ "att37": datasets.Value("int64"),
207
+ "att38": datasets.Value("int64"),
208
+ "att39": datasets.Value("int64"),
209
+ "att40": datasets.Value("int64"),
210
+ "att41": datasets.Value("int64"),
211
+ "att42": datasets.Value("int64"),
212
+ "att43": datasets.Value("int64"),
213
+ "att44": datasets.Value("int64"),
214
+ "att45": datasets.Value("int64"),
215
+ "att46": datasets.Value("int64"),
216
+ "att47": datasets.Value("int64"),
217
+ "att48": datasets.Value("int64"),
218
+ "att49": datasets.Value("int64"),
219
+ "att50": datasets.Value("int64"),
220
+ "att51": datasets.Value("int64"),
221
+ "att52": datasets.Value("int64"),
222
+ "att53": datasets.Value("int64"),
223
+ "att54": datasets.Value("int64"),
224
+ "att55": datasets.Value("int64"),
225
+ "att56": datasets.Value("int64"),
226
+ "att57": datasets.Value("int64"),
227
+ "att58": datasets.Value("int64"),
228
+ "att59": datasets.Value("int64"),
229
+ "att60": datasets.Value("int64"),
230
+ "att61": datasets.Value("int64"),
231
+ "att62": datasets.Value("int64"),
232
+ "att63": datasets.Value("int64"),
233
+ "att64": datasets.Value("int64"),
234
+ "class": datasets.ClassLabel(num_classes=2)
235
+ }
236
+
237
+
238
+
239
+ features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
240
+
241
+
242
+ class OptdigitsConfig(datasets.BuilderConfig):
243
+ def __init__(self, **kwargs):
244
+ super(OptdigitsConfig, self).__init__(version=VERSION, **kwargs)
245
+ self.features = features_per_config[kwargs["name"]]
246
+
247
+
248
+ class Optdigits(datasets.GeneratorBasedBuilder):
249
+ # dataset versions
250
+ DEFAULT_CONFIG = "optdigits"
251
+ BUILDER_CONFIGS = [
252
+ OptdigitsConfig(name="optdigits", description="Optdigits for multiclass classification."),
253
+ OptdigitsConfig(name="0", description="Optdigits for binary classification: is this a 0?."),
254
+ OptdigitsConfig(name="1", description="Optdigits for binary classification: is this a 1?."),
255
+ OptdigitsConfig(name="2", description="Optdigits for binary classification: is this a 2?."),
256
+ OptdigitsConfig(name="3", description="Optdigits for binary classification: is this a 3?."),
257
+ OptdigitsConfig(name="4", description="Optdigits for binary classification: is this a 4?."),
258
+ OptdigitsConfig(name="5", description="Optdigits for binary classification: is this a 5?."),
259
+ OptdigitsConfig(name="6", description="Optdigits for binary classification: is this a 6?."),
260
+ OptdigitsConfig(name="7", description="Optdigits for binary classification: is this a 7?."),
261
+ OptdigitsConfig(name="8", description="Optdigits for binary classification: is this a 8?."),
262
+ OptdigitsConfig(name="9", description="Optdigits for binary classification: is this a 9?.")
263
+ ]
264
+
265
+
266
+ def _info(self):
267
+ info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
268
+ features=features_per_config[self.config.name])
269
+
270
+ return info
271
+
272
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
273
+ downloads = dl_manager.download_and_extract(urls_per_split)
274
+
275
+ return [
276
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
277
+ ]
278
+
279
+ def _generate_examples(self, filepath: str):
280
+ data = pandas.read_csv(filepath, header=None)
281
+ data.columns = _BASE_FEATURE_NAMES
282
+
283
+ data = self.preprocess(data)
284
+
285
+ for row_id, row in data.iterrows():
286
+ data_row = dict(row)
287
+
288
+ yield row_id, data_row
289
+
290
+ def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
291
+ for feature in _ENCODING_DICS:
292
+ encoding_function = partial(self.encode, feature)
293
+ data.loc[:, feature] = data[feature].apply(encoding_function)
294
+
295
+ if self.config.name == "0":
296
+ data["class"] = data["class"].apply(lambda x: 1 if x == 0 else 0)
297
+ if self.config.name == "1":
298
+ data["class"] = data["class"].apply(lambda x: 1 if x == 1 else 0)
299
+ if self.config.name == "2":
300
+ data["class"] = data["class"].apply(lambda x: 1 if x == 2 else 0)
301
+ if self.config.name == "3":
302
+ data["class"] = data["class"].apply(lambda x: 1 if x == 3 else 0)
303
+ if self.config.name == "4":
304
+ data["class"] = data["class"].apply(lambda x: 1 if x == 4 else 0)
305
+ if self.config.name == "5":
306
+ data["class"] = data["class"].apply(lambda x: 1 if x == 5 else 0)
307
+ if self.config.name == "6":
308
+ data["class"] = data["class"].apply(lambda x: 1 if x == 6 else 0)
309
+ if self.config.name == "7":
310
+ data["class"] = data["class"].apply(lambda x: 1 if x == 7 else 0)
311
+ if self.config.name == "8":
312
+ data["class"] = data["class"].apply(lambda x: 1 if x == 8 else 0)
313
+ if self.config.name == "9":
314
+ data["class"] = data["class"].apply(lambda x: 1 if x == 9 else 0)
315
+
316
+ return data[list(features_types_per_config[self.config.name].keys())]
317
+
318
+ def encode(self, feature, value):
319
+ if feature in _ENCODING_DICS:
320
+ return _ENCODING_DICS[feature][value]
321
+ raise ValueError(f"Unknown feature: {feature}")