mstz commited on
Commit
308c9b6
·
1 Parent(s): fb51cd1

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +27 -1
  2. data.csv +0 -0
  3. waveform_noise.py +104 -0
README.md CHANGED
@@ -1,3 +1,29 @@
1
  ---
2
- license: cc-by-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - waveformnoiseV1
6
+ - tabular_classification
7
+ - binary_classification
8
+ - multiclass_classification
9
+ pretty_name: WaveformNoiseV1
10
+ size_categories:
11
+ - 1K<n<5K
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
+ - waveformnoiseV1
16
+ - waveformnoiseV1_0
17
+ - waveformnoiseV1_1
18
+ - waveformnoiseV1_2
19
  ---
20
+ # WaveformNoiseV1
21
+ The [WaveformNoiseV1 dataset](https://archive-beta.ics.uci.edu/dataset/107/waveform+database+generator+version+1) from the [UCI repository](https://archive-beta.ics.uci.edu/).
22
+
23
+ # Configurations and tasks
24
+ | **Configuration** | **Task** | **Description** |
25
+ |-----------------------|---------------------------|-------------------------|
26
+ | waveformnoiseV1 | Multiclass classification.| |
27
+ | waveformnoiseV1_0 | Binary classification. | Is the image of class 0? |
28
+ | waveformnoiseV1_1 | Binary classification. | Is the image of class 1? |
29
+ | waveformnoiseV1_2 | Binary classification. | Is the image of class 2? |
data.csv ADDED
The diff for this file is too large to render. See raw diff
 
waveform_noise.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")