Datasets:
Delete waveform_noise.py
Browse files- waveform_noise.py +0 -104
waveform_noise.py
DELETED
@@ -1,104 +0,0 @@
|
|
1 |
-
"""WaveformNoiseV1 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 = "WaveformNoiseV1 dataset."
|
16 |
-
_HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/78/page+blocks+classification"
|
17 |
-
_URLS = ("https://archive-beta.ics.uci.edu/dataset/78/page+blocks+classification")
|
18 |
-
_CITATION = """
|
19 |
-
@misc{misc_waveform_database_generator_(version_1)_107,
|
20 |
-
author = {Breiman,L. & Stone,C.J.},
|
21 |
-
title = {{Waveform Database Generator (Version 1)}},
|
22 |
-
year = {1988},
|
23 |
-
howpublished = {UCI Machine Learning Repository},
|
24 |
-
note = {{DOI}: \\url{10.24432/C5CS3C}}
|
25 |
-
}
|
26 |
-
"""
|
27 |
-
|
28 |
-
# Dataset info
|
29 |
-
urls_per_split = {
|
30 |
-
"train": "https://huggingface.co/datasets/mstz/waveformnoiseV1/raw/main/data.csv"
|
31 |
-
}
|
32 |
-
features_types_per_config = {
|
33 |
-
"waveformnoiseV1": {f"feature_{i}": datasets.Value("float64") for i in range(data.shape[1] - 1)},
|
34 |
-
"waveformnoiseV1_0": {f"feature_{i}": datasets.Value("float64") for i in range(data.shape[1] - 1)},
|
35 |
-
"waveformnoiseV1_1": {f"feature_{i}": datasets.Value("float64") for i in range(data.shape[1] - 1)},
|
36 |
-
"waveformnoiseV1_2": {f"feature_{i}": datasets.Value("float64") for i in range(data.shape[1] - 1)},
|
37 |
-
}
|
38 |
-
|
39 |
-
features_types_per_config["waveformnoiseV1"]["class"] = datasets.ClassLabel(num_classes=3)
|
40 |
-
features_types_per_config["waveformnoiseV1_0"]["class"] = datasets.ClassLabel(num_classes=2)
|
41 |
-
features_types_per_config["waveformnoiseV1_1"]["class"] = datasets.ClassLabel(num_classes=2)
|
42 |
-
features_types_per_config["waveformnoiseV1_2"]["class"] = datasets.ClassLabel(num_classes=2)
|
43 |
-
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
44 |
-
|
45 |
-
|
46 |
-
class WaveformNoiseV1Config(datasets.BuilderConfig):
|
47 |
-
def __init__(self, **kwargs):
|
48 |
-
super(WaveformNoiseV1Config, self).__init__(version=VERSION, **kwargs)
|
49 |
-
self.features = features_per_config[kwargs["name"]]
|
50 |
-
|
51 |
-
|
52 |
-
class WaveformNoiseV1(datasets.GeneratorBasedBuilder):
|
53 |
-
# dataset versions
|
54 |
-
DEFAULT_CONFIG = "waveformnoiseV1"
|
55 |
-
BUILDER_CONFIGS = [
|
56 |
-
WaveformNoiseV1Config(name="waveformnoiseV1", description="WaveformNoiseV1 for multiclass classification."),
|
57 |
-
WaveformNoiseV1Config(name="waveformnoiseV1_0", description="WaveformNoiseV1 for binary classification."),
|
58 |
-
WaveformNoiseV1Config(name="waveformnoiseV1_1", description="WaveformNoiseV1 for binary classification."),
|
59 |
-
WaveformNoiseV1Config(name="waveformnoiseV1_2", description="WaveformNoiseV1 for binary classification."),
|
60 |
-
|
61 |
-
]
|
62 |
-
|
63 |
-
|
64 |
-
def _info(self):
|
65 |
-
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
66 |
-
features=features_per_config[self.config.name])
|
67 |
-
|
68 |
-
return info
|
69 |
-
|
70 |
-
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
71 |
-
downloads = dl_manager.download_and_extract(urls_per_split)
|
72 |
-
|
73 |
-
return [
|
74 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
|
75 |
-
]
|
76 |
-
|
77 |
-
def _generate_examples(self, filepath: str):
|
78 |
-
data = pandas.read_csv(filepath, header=None)
|
79 |
-
data.columns = [f"feature_{i}" for i in range(data.shape[1] - 1)] + ["class"]
|
80 |
-
data = self.preprocess(data)
|
81 |
-
|
82 |
-
for row_id, row in data.iterrows():
|
83 |
-
data_row = dict(row)
|
84 |
-
|
85 |
-
yield row_id, data_row
|
86 |
-
|
87 |
-
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
88 |
-
if self.config.name == "waveformnoiseV1_0":
|
89 |
-
data["class"] = data["class"].apply(lambda x: 1 if x == 0 else 0)
|
90 |
-
elif self.config.name == "waveformnoiseV1_1":
|
91 |
-
data["class"] = data["class"].apply(lambda x: 1 if x == 1 else 0)
|
92 |
-
elif self.config.name == "waveformnoiseV1_2":
|
93 |
-
data["class"] = data["class"].apply(lambda x: 1 if x == 2 else 0)
|
94 |
-
|
95 |
-
for feature in _ENCODING_DICS:
|
96 |
-
encoding_function = partial(self.encode, feature)
|
97 |
-
data.loc[:, feature] = data[feature].apply(encoding_function)
|
98 |
-
|
99 |
-
return data[list(features_types_per_config[self.config.name].keys())]
|
100 |
-
|
101 |
-
def encode(self, feature, value):
|
102 |
-
if feature in _ENCODING_DICS:
|
103 |
-
return _ENCODING_DICS[feature][value]
|
104 |
-
raise ValueError(f"Unknown feature: {feature}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|