mstz commited on
Commit
0643aba
1 Parent(s): 85b550d

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +24 -1
  2. page_blocks.data +0 -0
  3. page_blocks.py +119 -0
README.md CHANGED
@@ -1,3 +1,26 @@
1
  ---
2
- license: cc-by-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - page_blocks
6
+ - tabular_classification
7
+ - binary_classification
8
+ - multiclass_classification
9
+ pretty_name: Page Blocks
10
+ size_categories:
11
+ - 1K<n<10K
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
+ - page_blocks
16
+ - page_blocks_binary
17
  ---
18
+ # PageBlocks
19
+ The [PageBlocks dataset](https://archive-beta.ics.uci.edu/dataset/76/page_blocks) from the [UCI repository](https://archive-beta.ics.uci.edu/).
20
+ How many transitions does the page block have?
21
+
22
+ # Configurations and tasks
23
+ | **Configuration** | **Task** |
24
+ |-------------------|---------------------------|
25
+ | page_blocks | Multiclass classification |
26
+ | page_blocks_binary| Binary classification |
page_blocks.data ADDED
The diff for this file is too large to render. See raw diff
 
page_blocks.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PageBlocks 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
+ "is_family_financially_stable": {
15
+ "convenient": True,
16
+ "inconvenient": False
17
+ }
18
+ }
19
+
20
+ DESCRIPTION = "PageBlocks dataset."
21
+ _HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/78/page+blocks+classification"
22
+ _URLS = ("https://archive-beta.ics.uci.edu/dataset/78/page+blocks+classification")
23
+ _CITATION = """
24
+ @misc{misc_page_blocks_classification_78,
25
+ author = {Malerba,Donato},
26
+ title = {{Page Blocks Classification}},
27
+ year = {1995},
28
+ howpublished = {UCI Machine Learning Repository},
29
+ note = {{DOI}: \\url{10.24432/C5J590}}
30
+ }
31
+ """
32
+
33
+ # Dataset info
34
+ urls_per_split = {
35
+ "train": "https://huggingface.co/datasets/mstz/page_blocks/raw/main/page_blocks.data"
36
+ }
37
+ features_types_per_config = {
38
+ "page_blocks": {
39
+ "height": datasets.Value("float64"),
40
+ "lenght": datasets.Value("float64"),
41
+ "area": datasets.Value("float64"),
42
+ "eccentricity": datasets.Value("float64"),
43
+ "percentage_black_pixels": datasets.Value("float64"),
44
+ "percentage_black_pixels_after_rlsa_and": datasets.Value("float64"),
45
+ "mean_numer_of_transitions": datasets.Value("float64"),
46
+ "number_of_black_pixels": datasets.Value("float64"),
47
+ "number_of_black_pixels_after_rlsa": datasets.Value("float64"),
48
+ "number_of_transitions": datasets.Value("int8")
49
+ },
50
+ "page_blocks_binary": {
51
+ "height": datasets.Value("float64"),
52
+ "lenght": datasets.Value("float64"),
53
+ "area": datasets.Value("float64"),
54
+ "eccentricity": datasets.Value("float64"),
55
+ "percentage_black_pixels": datasets.Value("float64"),
56
+ "percentage_black_pixels_after_rlsa_and": datasets.Value("float64"),
57
+ "mean_numer_of_transitions": datasets.Value("float64"),
58
+ "number_of_black_pixels": datasets.Value("float64"),
59
+ "number_of_black_pixels_after_rlsa": datasets.Value("float64"),
60
+ "has_multiple_transitions": datasets.ClassLabelS(num_classes=2)
61
+ }
62
+ }
63
+ features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
64
+
65
+
66
+ class PageBlocksConfig(datasets.BuilderConfig):
67
+ def __init__(self, **kwargs):
68
+ super(PageBlocksConfig, self).__init__(version=VERSION, **kwargs)
69
+ self.features = features_per_config[kwargs["name"]]
70
+
71
+
72
+ class PageBlocks(datasets.GeneratorBasedBuilder):
73
+ # dataset versions
74
+ DEFAULT_CONFIG = "page_blocks"
75
+ BUILDER_CONFIGS = [
76
+ PageBlocksConfig(name="page_blocks",
77
+ description="PageBlocks for regression."),
78
+ PageBlocksConfig(name="page_blocks_binary",
79
+ description="PageBlocks for binary classification.")
80
+ ]
81
+
82
+
83
+ def _info(self):
84
+ info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
85
+ features=features_per_config[self.config.name])
86
+
87
+ return info
88
+
89
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
90
+ downloads = dl_manager.download_and_extract(urls_per_split)
91
+
92
+ return [
93
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
94
+ ]
95
+
96
+ def _generate_examples(self, filepath: str):
97
+ data = pandas.read_csv(filepath)
98
+ data = self.preprocess(data)
99
+
100
+ for row_id, row in data.iterrows():
101
+ data_row = dict(row)
102
+
103
+ yield row_id, data_row
104
+
105
+ def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
106
+ if self.config.name == "page_blocks_binary":
107
+ data["number_of_transitions"] = data["number_of_transitions"].apply(lambda x: 1 if x > 1 else 0)
108
+ data = data.rename(columns={"number_of_transitions": "has_multiple_transitions"})
109
+
110
+ for feature in _ENCODING_DICS:
111
+ encoding_function = partial(self.encode, feature)
112
+ data.loc[:, feature] = data[feature].apply(encoding_function)
113
+
114
+ return data[list(features_types_per_config[self.config.name].keys())]
115
+
116
+ def encode(self, feature, value):
117
+ if feature in _ENCODING_DICS:
118
+ return _ENCODING_DICS[feature][value]
119
+ raise ValueError(f"Unknown feature: {feature}")