from typing import List import datasets import pandas VERSION = datasets.Version("1.0.0") DESCRIPTION = "Electricity dataset from the UCI ML repository." _HOMEPAGE = "ttps://www.openml.org/search?type=data&sort=runs&id=151&status=active" _URLS = ("ttps://www.openml.org/search?type=data&sort=runs&id=151&status=active") _CITATION = """""" # Dataset info urls_per_split = { "train": "https://huggingface.co/datasets/mstz/electricity/raw/main/electricity-normalized.csv" } features_types_per_config = { "electricity": { "date": datasets.Value("float64"), "day": datasets.Value("int8"), "period": datasets.Value("float64"), "nswprice": datasets.Value("float64"), "nswdemand": datasets.Value("float64"), "vicprice": datasets.Value("float64"), "vicdemand": datasets.Value("float64"), "transfer": datasets.Value("float64"), "is_up": 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 ElectricityConfig(datasets.BuilderConfig): def __init__(self, **kwargs): super(ElectricityConfig, self).__init__(version=VERSION, **kwargs) self.features = features_per_config[kwargs["name"]] class Electricity(datasets.GeneratorBasedBuilder): # dataset versions DEFAULT_CONFIG = "electricity" BUILDER_CONFIGS = [ ElectricityConfig(name="electricity", description="Electricity 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