from typing import List import datasets import pandas VERSION = datasets.Version("1.0.0") DESCRIPTION = "House16 dataset from the OpenML repository." _HOMEPAGE = "https://www.openml.org/search?type=data&sort=runs&id=722&status=active" _URLS = ("https://www.openml.org/search?type=data&sort=runs&id=722&status=active") _CITATION = """""" # Dataset info urls_per_split = { "train": "https://huggingface.co/datasets/mstz/house16/raw/main/house_16H.csv" } features_types_per_config = { "house16": { "P1": datasets.Value("int64"), "P5p1": datasets.Value("float64"), "P6p2": datasets.Value("float64"), "P11p4": datasets.Value("float64"), "P14p9": datasets.Value("float64"), "P15p1": datasets.Value("float64"), "P15p3": datasets.Value("float64"), "P16p2": datasets.Value("float64"), "P18p2": datasets.Value("float64"), "P27p4": datasets.Value("float64"), "H2p2": datasets.Value("float64"), "H8p2": datasets.Value("float64"), "H10p1": datasets.Value("float64"), "H13p1": datasets.Value("float64"), "H18pA": datasets.Value("float64"), "H40p4": datasets.Value("float64"), "class": datasets.ClassLabel(num_classes=2, names=("no", "yes")) } } features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config} class House16Config(datasets.BuilderConfig): def __init__(self, **kwargs): super(House16Config, self).__init__(version=VERSION, **kwargs) self.features = features_per_config[kwargs["name"]] class House16(datasets.GeneratorBasedBuilder): # dataset versions DEFAULT_CONFIG = "house16" BUILDER_CONFIGS = [ House16Config(name="house16", description="House16 for binary classification.") ] def _info(self): 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"]}) ] def _generate_examples(self, filepath: str): data = pandas.read_csv(filepath) for row_id, row in data.iterrows(): data_row = dict(row) yield row_id, data_row