acute_inflammation / acute_inflammation.py
mstz's picture
Upload 2 files
5a3b396
raw
history blame
3.46 kB
"""Acute_Inflammation"""
from typing import List
import datasets
import pandas
VERSION = datasets.Version("1.0.0")
_BASE_FEATURE_NAMES = [
"temperature",
"has_nausea",
"has_lumbar_pain",
"has_urine_pushing",
"has_micturition_pains",
"has_burnt_urethra",
"has_inflammed_bladder",
"has_nephritis_of_renal_pelvis"
]
DESCRIPTION = "Acute_Inflammation dataset from the UCI ML repository."
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Acute_Inflammation"
_URLS = ("https://huggingface.co./datasets/mstz/acute_inflammation/raw/main/diagnosis.csv")
_CITATION = """
@misc{misc_acute_inflammations_184,
author = {Czerniak,Jacek},
title = {{Acute Inflammations}},
year = {2009},
howpublished = {UCI Machine Learning Repository},
note = {{DOI}: \\url{10.24432/C5V59S}}
}"""
# Dataset info
urls_per_split = {
"train": "https://huggingface.co./datasets/mstz/acute_inflammation/raw/main/diagnosis.csv"
}
features_types_per_config = {
"inflammation": {
"temperature": datasets.Value("float64"),
"has_nausea": datasets.Value("bool"),
"has_lumbar_pain": datasets.Value("bool"),
"has_urine_pushing": datasets.Value("bool"),
"has_micturition_pains": datasets.Value("bool"),
"has_burnt_urethra": datasets.Value("bool"),
"has_inflammed_bladder": datasets.Value("bool"),
"has_nephritis_of_renal_pelvis": datasets.Value("int8")
}
}
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
class Acute_InflammationConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(Acute_InflammationConfig, self).__init__(version=VERSION, **kwargs)
self.features = features_per_config[kwargs["name"]]
class Acute_Inflammation(datasets.GeneratorBasedBuilder):
# dataset versions
DEFAULT_CONFIG = "inflammation"
BUILDER_CONFIGS = [
Acute_InflammationConfig(name="inflammation",
description="Binary classification of inflammation.")
]
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 = self.preprocess(data, config=self.config.name)
for row_id, row in data.iterrows():
data_row = dict(row)
yield row_id, data_row
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
data.columns = _BASE_FEATURE_NAMES
boolean_features = ["has_nausea", "has_lumbar_pain", "has_urine_pushing",
"has_micturition_pains", "has_burnt_urethra", "has_inflammed_bladder"]
for f in boolean_features:
data.loc[:, f] = data[f].apply(lambda x: True if x == "yes" else False)
data = data.astype({f: "bool" for f in boolean_features})
return data