|
"""Spect""" |
|
|
|
from typing import List |
|
|
|
import datasets |
|
|
|
import pandas |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
DESCRIPTION = "Spect dataset from the UCI ML repository." |
|
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Spect" |
|
_URLS = ("https://archive.ics.uci.edu/ml/datasets/Spect") |
|
_CITATION = """ |
|
@misc{misc_spect_heart_95, |
|
author = {Cios,Krzysztof, Kurgan,Lukasz & Goodenday,Lucy}, |
|
title = {{SPECT Heart}}, |
|
year = {2001}, |
|
howpublished = {UCI Machine Learning Repository}, |
|
note = {{DOI}: \\url{10.24432/C5P304}} |
|
}""" |
|
|
|
|
|
urls_per_split = { |
|
"spect": { |
|
"train": "https://huggingface.co/datasets/mstz/spect/raw/main/SPECT.train", |
|
"test": "https://huggingface.co/datasets/mstz/spect/raw/main/SPECT.test" |
|
}, |
|
"spectf": { |
|
"train": "https://huggingface.co/datasets/mstz/spect/raw/main/SPECTF.train", |
|
"test": "https://huggingface.co/datasets/mstz/spect/raw/main/SPECTF.test" |
|
} |
|
} |
|
features_types_per_config = { |
|
"spect": { |
|
"feature_0": datasets.Value("bool"), |
|
"feature_1": datasets.Value("bool"), |
|
"feature_2": datasets.Value("bool"), |
|
"feature_3": datasets.Value("bool"), |
|
"feature_4": datasets.Value("bool"), |
|
"feature_5": datasets.Value("bool"), |
|
"feature_6": datasets.Value("bool"), |
|
"feature_7": datasets.Value("bool"), |
|
"feature_8": datasets.Value("bool"), |
|
"feature_9": datasets.Value("bool"), |
|
"feature_10": datasets.Value("bool"), |
|
"feature_11": datasets.Value("bool"), |
|
"feature_12": datasets.Value("bool"), |
|
"feature_13": datasets.Value("bool"), |
|
"feature_14": datasets.Value("bool"), |
|
"feature_15": datasets.Value("bool"), |
|
"feature_16": datasets.Value("bool"), |
|
"feature_17": datasets.Value("bool"), |
|
"feature_18": datasets.Value("bool"), |
|
"feature_19": datasets.Value("bool"), |
|
"feature_20": datasets.Value("bool"), |
|
"feature_21": datasets.Value("bool"), |
|
"is_emitted": datasets.ClassLabel(num_classes=2, names=("no", "yes")) |
|
}, |
|
"spectf": { |
|
"F1R": datasets.Value("int8"), |
|
"F1S": datasets.Value("int8"), |
|
"F2R": datasets.Value("int8"), |
|
"F2S": datasets.Value("int8"), |
|
"F3R": datasets.Value("int8"), |
|
"F3S": datasets.Value("int8"), |
|
"F4R": datasets.Value("int8"), |
|
"F4S": datasets.Value("int8"), |
|
"F5R": datasets.Value("int8"), |
|
"F5S": datasets.Value("int8"), |
|
"F6R": datasets.Value("int8"), |
|
"F6S": datasets.Value("int8"), |
|
"F7R": datasets.Value("int8"), |
|
"F7S": datasets.Value("int8"), |
|
"F8R": datasets.Value("int8"), |
|
"F8S": datasets.Value("int8"), |
|
"F9R": datasets.Value("int8"), |
|
"F9S": datasets.Value("int8"), |
|
"F10R": datasets.Value("int8"), |
|
"F10S": datasets.Value("int8"), |
|
"F11R": datasets.Value("int8"), |
|
"F11S": datasets.Value("int8"), |
|
"F12R": datasets.Value("int8"), |
|
"F12S": datasets.Value("int8"), |
|
"F13R": datasets.Value("int8"), |
|
"F13S": datasets.Value("int8"), |
|
"F14R": datasets.Value("int8"), |
|
"F14S": datasets.Value("int8"), |
|
"F15R": datasets.Value("int8"), |
|
"F15S": datasets.Value("int8"), |
|
"F16R": datasets.Value("int8"), |
|
"F16S": datasets.Value("int8"), |
|
"F17R": datasets.Value("int8"), |
|
"F17S": datasets.Value("int8"), |
|
"F18R": datasets.Value("int8"), |
|
"F18S": datasets.Value("int8"), |
|
"F19R": datasets.Value("int8"), |
|
"F19S": datasets.Value("int8"), |
|
"F20R": datasets.Value("int8"), |
|
"F20S": datasets.Value("int8"), |
|
"F21R": datasets.Value("int8"), |
|
"F21S": datasets.Value("int8"), |
|
"F22R": datasets.Value("int8"), |
|
"F22S": datasets.Value("int8"), |
|
"is_emitted": 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 SpectConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super(SpectConfig, self).__init__(version=VERSION, **kwargs) |
|
self.features = features_per_config[kwargs["name"]] |
|
|
|
|
|
class Spect(datasets.GeneratorBasedBuilder): |
|
|
|
DEFAULT_CONFIG = "spect" |
|
BUILDER_CONFIGS = [ |
|
SpectConfig(name="spect", |
|
description="Spect for binary classification."), |
|
SpectConfig(name="spectf", |
|
description="Spectf 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[self.config.name]["train"]}) |
|
] |
|
|
|
def _generate_examples(self, filepath: str): |
|
data = pandas.read_csv(filepath, header=None) |
|
data.columns = [list(features_types_per_config[self.config.name])] |
|
print(data.columns) |
|
|
|
for row_id, row in data.iterrows(): |
|
data_row = dict(row) |
|
|
|
yield row_id, data_row |
|
|