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("float32") for i in range(500)} } 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) print(f"loading {filepath}") data = self.preprocess(data, config=self.config.name) print("\n\n\npreprocessed\n\n\n") print(data.head()) print(data.columns) print(data["500"]) 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: print("data.columns") print(data.columns) print("'500' in data.columns") print("500" in data.columns) print(data["499"]) print(data["500"]) data["500"].apply(lambda x: max(0, x)) data.loc[:, "500"] data.loc[:, "500"] = data["500"].apply(lambda x: max(0, x)) features_types_per_config["madelon"].update({"500": datasets.ClassLabel(num_classes=2)}) return data