Datasets:
Tasks:
Tabular Classification
Languages:
English
Delete gisette.py
Browse files- gisette.py +0 -85
gisette.py
DELETED
@@ -1,85 +0,0 @@
|
|
1 |
-
"""Gisette 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 |
-
|
15 |
-
DESCRIPTION = "Gisette dataset."
|
16 |
-
_HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/170/gisette"
|
17 |
-
_URLS = ("https://archive-beta.ics.uci.edu/dataset/170/gisette")
|
18 |
-
_CITATION = """
|
19 |
-
@misc{misc_gisette_170,
|
20 |
-
author = {Guyon,Isabelle, Gunn,Steve, Ben-Hur,Asa & Dror,Gideon},
|
21 |
-
title = {{Gisette}},
|
22 |
-
year = {2008},
|
23 |
-
howpublished = {UCI Machine Learning Repository},
|
24 |
-
note = {{DOI}: \\url{10.24432/C5HP5B}}
|
25 |
-
}
|
26 |
-
"""
|
27 |
-
|
28 |
-
# Dataset info
|
29 |
-
urls_per_split = {
|
30 |
-
"train": "https://huggingface.co/datasets/mstz/gisette/resolve/main/gisette.data"
|
31 |
-
}
|
32 |
-
features_types_per_config = {
|
33 |
-
"gisette": {f"feature_{i}": datasets.Value("int64") for i in range(5000)}
|
34 |
-
}
|
35 |
-
features_types_per_config["class"] = datasets.ClassLabel(num_classes=2)
|
36 |
-
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
37 |
-
|
38 |
-
|
39 |
-
class GisetteConfig(datasets.BuilderConfig):
|
40 |
-
def __init__(self, **kwargs):
|
41 |
-
super(GisetteConfig, self).__init__(version=VERSION, **kwargs)
|
42 |
-
self.features = features_per_config[kwargs["name"]]
|
43 |
-
|
44 |
-
|
45 |
-
class Gisette(datasets.GeneratorBasedBuilder):
|
46 |
-
# dataset versions
|
47 |
-
DEFAULT_CONFIG = "gisette"
|
48 |
-
BUILDER_CONFIGS = [
|
49 |
-
GisetteConfig(name="gisette", description="Gisette for multiclass classification.")
|
50 |
-
]
|
51 |
-
|
52 |
-
|
53 |
-
def _info(self):
|
54 |
-
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
55 |
-
features=features_per_config[self.config.name])
|
56 |
-
|
57 |
-
return info
|
58 |
-
|
59 |
-
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
60 |
-
downloads = dl_manager.download_and_extract(urls_per_split)
|
61 |
-
|
62 |
-
return [
|
63 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
|
64 |
-
]
|
65 |
-
|
66 |
-
def _generate_examples(self, filepath: str):
|
67 |
-
data = pandas.read_csv(filepath, header=None)
|
68 |
-
data = self.preprocess(data)
|
69 |
-
|
70 |
-
for row_id, row in data.iterrows():
|
71 |
-
data_row = dict(row)
|
72 |
-
|
73 |
-
yield row_id, data_row
|
74 |
-
|
75 |
-
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
76 |
-
for feature in _ENCODING_DICS:
|
77 |
-
encoding_function = partial(self.encode, feature)
|
78 |
-
data.loc[:, feature] = data[feature].apply(encoding_function)
|
79 |
-
|
80 |
-
return data[list(features_types_per_config[self.config.name].keys())]
|
81 |
-
|
82 |
-
def encode(self, feature, value):
|
83 |
-
if feature in _ENCODING_DICS:
|
84 |
-
return _ENCODING_DICS[feature][value]
|
85 |
-
raise ValueError(f"Unknown feature: {feature}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|