Datasets:
File size: 2,642 Bytes
95fb2a6 38deb92 95fb2a6 d8c8fab 95fb2a6 901a0ce 95fb2a6 18c19a1 95fb2a6 52c284e 7469572 95fb2a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from typing import List
import datasets
import pandas
VERSION = datasets.Version("1.0.0")
DESCRIPTION = "Madelon dataset from the UCI ML repository."
_HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/3/madelon"
_URLS = ("https://archive-beta.ics.uci.edu/dataset/3/madelon")
_CITATION = """"""
# Dataset info
urls_per_split = {
"train": "https://huggingface.co/datasets/mstz/madelon/raw/main/madelon_train.csv",
"validation": "https://huggingface.co/datasets/mstz/madelon/raw/main/madelon_valid.csv"
}
features_types_per_config = {
"madelon": {str(i): datasets.Value("int16") for i in range(500)}
}
features_types_per_config["madelon"]["500"] = datasets.ClassLabel(num_classes=2)
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
class MadelonConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(MadelonConfig, self).__init__(version=VERSION, **kwargs)
self.features = features_per_config[kwargs["name"]]
class Madelon(datasets.GeneratorBasedBuilder):
# dataset versions
DEFAULT_CONFIG = "madelon"
BUILDER_CONFIGS = [
MadelonConfig(name="madelon",
description="Madelon for multiclass classification.")
]
def _info(self):
if self.config.name not in features_per_config:
raise ValueError(f"Unknown configuration: {self.config.name}")
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
features=features_per_config[self.config.name])
return info
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
downloads = dl_manager.download_and_extract(urls_per_split)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloads["validation"]})
]
def _generate_examples(self, filepath: str):
data = pandas.read_csv(filepath)
data = self.preprocess(data, config=self.config.name)
for row_id, row in data.iterrows():
data_row = dict(row)
yield row_id, data_row
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
data["500"] = data["500"].apply(lambda x: max(0, x)).astype(int)
if "0.1" in data:
data.drop("0.1", axis="columns", inplace=True)
return data
|