Datasets:
Upload 3 files
Browse files
README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
tags:
|
| 5 |
+
- hypo
|
| 6 |
+
- tabular_classification
|
| 7 |
+
- binary_classification
|
| 8 |
+
pretty_name: Hypo
|
| 9 |
+
task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
|
| 10 |
+
- tabular-classification
|
| 11 |
+
configs:
|
| 12 |
+
- hypo
|
| 13 |
---
|
| 14 |
+
# Hypo
|
| 15 |
+
The Hypo dataset.
|
| 16 |
+
|
| 17 |
+
# Configurations and tasks
|
| 18 |
+
| **Configuration** | **Task** | **Description**
|
| 19 |
+
|-----------------------|---------------------------|
|
| 20 |
+
| hypo | Multiclass classification.| What kind of hypothyroidism does the patient have? |
|
| 21 |
+
| has_hypo | Binary classification.| Does the patient hypothyroidism does the patient have? |
|
hypo.data
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hypo.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hypo Dataset"""
|
| 2 |
+
|
| 3 |
+
from typing import List
|
| 4 |
+
from functools import partial
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
|
| 8 |
+
import pandas
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
VERSION = datasets.Version("1.0.0")
|
| 12 |
+
|
| 13 |
+
_ENCODING_DICS = {
|
| 14 |
+
"negative": 0,
|
| 15 |
+
"compensated hypothyroid": 1,
|
| 16 |
+
"primary hypothyroid": 2
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
DESCRIPTION = "Hypo dataset."
|
| 20 |
+
_HOMEPAGE = ""
|
| 21 |
+
_URLS = ("")
|
| 22 |
+
_CITATION = """"""
|
| 23 |
+
|
| 24 |
+
# Dataset info
|
| 25 |
+
urls_per_split = {
|
| 26 |
+
"train": "https://huggingface.co/datasets/mstz/hypo/resolve/main/hypo.data"
|
| 27 |
+
}
|
| 28 |
+
features_types_per_config = {
|
| 29 |
+
"hypo": {
|
| 30 |
+
"age": datasets.Value("int8"),
|
| 31 |
+
"sex": datasets.Value("string"),
|
| 32 |
+
"on_thyroxine": datasets.Value("boolS"),
|
| 33 |
+
"query_on_thyroxine": datasets.Value("bool"),
|
| 34 |
+
"on_antithyroid_medication": datasets.Value("bool"),
|
| 35 |
+
"sick": datasets.Value("bool"),
|
| 36 |
+
"pregnant": datasets.Value("bool"),
|
| 37 |
+
"thyroid_surgery": datasets.Value("bool"),
|
| 38 |
+
"I131_treatment": datasets.Value("bool"),
|
| 39 |
+
"query_hypothyroid": datasets.Value("bool"),
|
| 40 |
+
"query_hyperthyroid": datasets.Value("bool"),
|
| 41 |
+
"lithium": datasets.Value("bool"),
|
| 42 |
+
"goitre": datasets.Value("bool"),
|
| 43 |
+
"tumor": datasets.Value("bool"),
|
| 44 |
+
"hypopituitary": datasets.Value("bool"),
|
| 45 |
+
"psych": datasets.Value("bool"),
|
| 46 |
+
"TSH_measured": datasets.Value("bool"),
|
| 47 |
+
"TSH": datasets.Value("string"),
|
| 48 |
+
"T3_measured": datasets.Value("bool"),
|
| 49 |
+
"T3": datasets.Value("float64"),
|
| 50 |
+
"TT4_measured": datasets.Value("bool"),
|
| 51 |
+
"TT4": datasets.Value("float64"),
|
| 52 |
+
"T4U_measured": datasets.Value("bool"),
|
| 53 |
+
"T4U": datasets.Value("float64"),
|
| 54 |
+
"FTI_measured": datasets.Value("bool"),
|
| 55 |
+
"FTI": datasets.Value("float64"),
|
| 56 |
+
"TBG_measured": datasets.Value("string"),
|
| 57 |
+
"referral_source": datasets.Value("string"),
|
| 58 |
+
"class": datasets.ClassLabel(num_classes=3, names=("negative", "compensated hypothyroid", "primary hypothyroid"))
|
| 59 |
+
},
|
| 60 |
+
"has_hypo": {
|
| 61 |
+
"age": datasets.Value("int8"),
|
| 62 |
+
"sex": datasets.Value("string"),
|
| 63 |
+
"on_thyroxine": datasets.Value("boolS"),
|
| 64 |
+
"query_on_thyroxine": datasets.Value("bool"),
|
| 65 |
+
"on_antithyroid_medication": datasets.Value("bool"),
|
| 66 |
+
"sick": datasets.Value("bool"),
|
| 67 |
+
"pregnant": datasets.Value("bool"),
|
| 68 |
+
"thyroid_surgery": datasets.Value("bool"),
|
| 69 |
+
"I131_treatment": datasets.Value("bool"),
|
| 70 |
+
"query_hypothyroid": datasets.Value("bool"),
|
| 71 |
+
"query_hyperthyroid": datasets.Value("bool"),
|
| 72 |
+
"lithium": datasets.Value("bool"),
|
| 73 |
+
"goitre": datasets.Value("bool"),
|
| 74 |
+
"tumor": datasets.Value("bool"),
|
| 75 |
+
"hypopituitary": datasets.Value("bool"),
|
| 76 |
+
"psych": datasets.Value("bool"),
|
| 77 |
+
"TSH_measured": datasets.Value("bool"),
|
| 78 |
+
"TSH": datasets.Value("string"),
|
| 79 |
+
"T3_measured": datasets.Value("bool"),
|
| 80 |
+
"T3": datasets.Value("string"),
|
| 81 |
+
"TT4_measured": datasets.Value("bool"),
|
| 82 |
+
"TT4": datasets.Value("float64"),
|
| 83 |
+
"T4U_measured": datasets.Value("bool"),
|
| 84 |
+
"T4U": datasets.Value("float64"),
|
| 85 |
+
"FTI_measured": datasets.Value("bool"),
|
| 86 |
+
"FTI": datasets.Value("float64"),
|
| 87 |
+
"TBG_measured": datasets.Value("string"),
|
| 88 |
+
"referral_source": datasets.Value("string"),
|
| 89 |
+
"class": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
| 90 |
+
},
|
| 91 |
+
}
|
| 92 |
+
features_types_per_config["hypo"]["class"] = datasets.ClassLabel(num_classes=2)
|
| 93 |
+
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class HypoConfig(datasets.BuilderConfig):
|
| 97 |
+
def __init__(self, **kwargs):
|
| 98 |
+
super(HypoConfig, self).__init__(version=VERSION, **kwargs)
|
| 99 |
+
self.features = features_per_config[kwargs["name"]]
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class Hypo(datasets.GeneratorBasedBuilder):
|
| 103 |
+
# dataset versions
|
| 104 |
+
DEFAULT_CONFIG = "hypo"
|
| 105 |
+
BUILDER_CONFIGS = [
|
| 106 |
+
HypoConfig(name="hypo", description="Hypo for multiclass classification."),
|
| 107 |
+
HypoConfig(name="has_hypo", description="Hypo for binary classification."),
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def _info(self):
|
| 112 |
+
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
| 113 |
+
features=features_per_config[self.config.name])
|
| 114 |
+
|
| 115 |
+
return info
|
| 116 |
+
|
| 117 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 118 |
+
downloads = dl_manager.download_and_extract(urls_per_split)
|
| 119 |
+
|
| 120 |
+
return [
|
| 121 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
def _generate_examples(self, filepath: str):
|
| 125 |
+
data = pandas.read_csv(filepath, header=None)
|
| 126 |
+
data = self.preprocess(data)
|
| 127 |
+
|
| 128 |
+
for row_id, row in data.iterrows():
|
| 129 |
+
data_row = dict(row)
|
| 130 |
+
|
| 131 |
+
yield row_id, data_row
|
| 132 |
+
|
| 133 |
+
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
| 134 |
+
data.drop("id", axid="columns", inplace=True)
|
| 135 |
+
data.drop("TBG", axid="columns", inplace=True)
|
| 136 |
+
|
| 137 |
+
data = data[data.age != "?"]
|
| 138 |
+
data = data[data.sex != "?"]
|
| 139 |
+
data = data[data.TSH != "?"]
|
| 140 |
+
|
| 141 |
+
data.loc[data.TT4 == "?", "T3"] = -1
|
| 142 |
+
data.loc[data.TT4 == "?", "TT4"] = -1
|
| 143 |
+
data.loc[data.TT4 == "?", "T4U"] = -1
|
| 144 |
+
data.loc[data.TT4 == "?", "FTI"] = -1
|
| 145 |
+
|
| 146 |
+
data = data.infer_objects()
|
| 147 |
+
|
| 148 |
+
for feature in _ENCODING_DICS:
|
| 149 |
+
encoding_function = partial(self.encode, feature)
|
| 150 |
+
data[feature] = data[feature].apply(encoding_function)
|
| 151 |
+
|
| 152 |
+
if self.config.name == "has_hypo":
|
| 153 |
+
data["class"] = data["class"].apply(lambda x: 0 if x == 0 else 1)
|
| 154 |
+
|
| 155 |
+
return data[list(features_types_per_config[self.config.name].keys())]
|
| 156 |
+
|
| 157 |
+
def encode(self, feature, value):
|
| 158 |
+
if feature in _ENCODING_DICS:
|
| 159 |
+
return _ENCODING_DICS[feature][value]
|
| 160 |
+
raise ValueError(f"Unknown feature: {feature}")
|