mstz commited on
Commit
a6320cc
·
1 Parent(s): 3d01535

updated to datasets 4.*

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