Datasets:
File size: 5,160 Bytes
b398694 e821496 b8aa4c5 b398694 |
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
"""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}}
}"""
# Dataset info
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):
# dataset versions
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)
features = list(features_types_per_config[self.config.name])
base_features = [features[-1]] + features[:-1]
data.columns = base_features
data = data[features]
for row_id, row in data.iterrows():
data_row = dict(row)
yield row_id, data_row
|