ionosphere / ionosphere.py
mstz's picture
Rename ionoshpere.py to ionosphere.py
4648f26
"""Ionosphere"""
from typing import List
import datasets
import pandas
VERSION = datasets.Version("1.0.0")
DESCRIPTION = "Ionosphere dataset from the UCI ML repository."
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Ionosphere"
_URLS = ("https://huggingface.co/datasets/mstz/ionosphere/raw/ionosphere.data")
_CITATION = """
@misc{misc_ionosphere_52,
author = {Sigillito,V., Wing,S., Hutton,L. & Baker,K.},
title = {{Ionosphere}},
year = {1989},
howpublished = {UCI Machine Learning Repository},
note = {{DOI}: \\url{10.24432/C5W01B}}
}"""
# Dataset info
urls_per_split = {
"train": "https://huggingface.co/datasets/mstz/ionosphere/raw/main/ionosphere.data"
}
features_types_per_config = {
"ionosphere": {
"signal_0": datasets.Value("float64"),
"signal_1": datasets.Value("float64"),
"signal_2": datasets.Value("float64"),
"signal_3": datasets.Value("float64"),
"signal_4": datasets.Value("float64"),
"signal_5": datasets.Value("float64"),
"signal_6": datasets.Value("float64"),
"signal_7": datasets.Value("float64"),
"signal_8": datasets.Value("float64"),
"signal_9": datasets.Value("float64"),
"signal_10": datasets.Value("float64"),
"signal_11": datasets.Value("float64"),
"signal_12": datasets.Value("float64"),
"signal_13": datasets.Value("float64"),
"signal_14": datasets.Value("float64"),
"signal_15": datasets.Value("float64"),
"signal_16": datasets.Value("float64"),
"signal_17": datasets.Value("float64"),
"signal_18": datasets.Value("float64"),
"signal_19": datasets.Value("float64"),
"signal_20": datasets.Value("float64"),
"signal_21": datasets.Value("float64"),
"signal_22": datasets.Value("float64"),
"signal_23": datasets.Value("float64"),
"signal_24": datasets.Value("float64"),
"signal_25": datasets.Value("float64"),
"signal_26": datasets.Value("float64"),
"signal_27": datasets.Value("float64"),
"signal_28": datasets.Value("float64"),
"signal_29": datasets.Value("float64"),
"signal_30": datasets.Value("float64"),
"signal_31": datasets.Value("float64"),
"signal_32": datasets.Value("float64"),
"signal_33": datasets.Value("float64"),
"class": datasets.ClassLabel(num_classes=2)
}
}
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
class IonosphereConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(IonosphereConfig, self).__init__(version=VERSION, **kwargs)
self.features = features_per_config[kwargs["name"]]
class Ionosphere(datasets.GeneratorBasedBuilder):
# dataset versions
DEFAULT_CONFIG = "ionosphere"
BUILDER_CONFIGS = [
IonosphereConfig(name="ionosphere",
description="Ionosphere 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, header=None)
data.columns = [f"signal_{i}" for i in range(data.shape[1] - 1)] + ["class"]
data.loc[:, "class"] = data["class"].apply(lambda x: 1 if x == "g" else 0)
for row_id, row in data.iterrows():
data_row = dict(row)
yield row_id, data_row