Datasets:
Upload 3 files
Browse files- README.md +47 -1
- fertility.py +170 -0
- fertility_Diagnosis.txt +100 -0
README.md
CHANGED
@@ -1,3 +1,49 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
tags:
|
5 |
+
- fertility
|
6 |
+
- tabular_classification
|
7 |
+
- binary_classification
|
8 |
+
- multiclass_classification
|
9 |
+
pretty_name: Fertility
|
10 |
+
size_categories:
|
11 |
+
- 10K<n<100K
|
12 |
+
task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
|
13 |
+
- tabular-classification
|
14 |
+
configs:
|
15 |
+
- encoding
|
16 |
+
- fertility
|
17 |
---
|
18 |
+
# Fertility
|
19 |
+
The [Fertility dataset](https://archive.ics.uci.edu/ml/datasets/Fertility) from the [UCI ML repository](https://archive.ics.uci.edu/ml/datasets).
|
20 |
+
Classify fertility abnormalities of patients.
|
21 |
+
|
22 |
+
|
23 |
+
# Configurations and tasks
|
24 |
+
| **Configuration** | **Task** | **Description** |
|
25 |
+
|-------------------|---------------------------|------------------------------------------|
|
26 |
+
| encoding | | Encoding dictionary |
|
27 |
+
| fertility | Binary classification | Does the patient have fertility issues? |
|
28 |
+
|
29 |
+
|
30 |
+
# Usage
|
31 |
+
```python
|
32 |
+
from datasets import load_dataset
|
33 |
+
|
34 |
+
dataset = load_dataset("mstz/fertility", "fertility")["train"]
|
35 |
+
```
|
36 |
+
|
37 |
+
# Features
|
38 |
+
|**Feature** |**Type** |
|
39 |
+
|----------------------------------------|------------------|
|
40 |
+
| season_of_sampling | `[string]` |
|
41 |
+
| age_at_time_of_sampling | `[int8]` |
|
42 |
+
| has_had_childhood_diseases | `[bool]` |
|
43 |
+
| has_had_serious_trauma | `[bool]` |
|
44 |
+
| has_had_surgical_interventions | `[bool]` |
|
45 |
+
| has_had_high_fevers_in_the_past_year | `[string]` |
|
46 |
+
| frequency_of_alcohol_consumption | `[float16]` |
|
47 |
+
| smoking_frequency | `[string]` |
|
48 |
+
| number_of_sitting_hours_per_day | `[float16]` |
|
49 |
+
|
fertility.py
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Fertility"""
|
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 |
+
_BASE_FEATURE_NAMES = [
|
13 |
+
"season_of_sampling",
|
14 |
+
"age_at_time_of_sampling",
|
15 |
+
"has_had_childhood_diseases",
|
16 |
+
"has_had_serious_trauma",
|
17 |
+
"has_had_surgical_interventions",
|
18 |
+
"has_had_high_fevers_in_the_past_year",
|
19 |
+
"frequency_of_alcohol_consumption",
|
20 |
+
"smoking_frequency",
|
21 |
+
"number_of_sitting_hours_per_day",
|
22 |
+
"has_fertility_issues"
|
23 |
+
]
|
24 |
+
|
25 |
+
_ENCODING_DICS = {
|
26 |
+
"season_of_sampling" : {
|
27 |
+
-1: "winter",
|
28 |
+
-0.33: "spring",
|
29 |
+
+0.33: "summer",
|
30 |
+
+1: "fall",
|
31 |
+
},
|
32 |
+
"has_had_childhood_diseases" : {
|
33 |
+
"yes": True,
|
34 |
+
"no": False
|
35 |
+
},
|
36 |
+
"has_had_serious_trauma" : {
|
37 |
+
"yes": True,
|
38 |
+
"no": False
|
39 |
+
},
|
40 |
+
"has_had_surgical_interventions" : {
|
41 |
+
"yes": True,
|
42 |
+
"no": False
|
43 |
+
},
|
44 |
+
"has_had_high_fevers_in_the_past_year" : {
|
45 |
+
1: "no",
|
46 |
+
0: "more than three months ago",
|
47 |
+
-1: "less than three months ago"
|
48 |
+
},
|
49 |
+
"smoking_frequency" : {
|
50 |
+
1: "daily",
|
51 |
+
0: "occasionally",
|
52 |
+
-1: "never"
|
53 |
+
},
|
54 |
+
"has_fertility_issues": {
|
55 |
+
"N": 0,
|
56 |
+
"O": 1
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
DESCRIPTION = "Fertility dataset from the UCI ML repository."
|
61 |
+
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Fertility"
|
62 |
+
_URLS = ("https://archive.ics.uci.edu/ml/datasets/Fertility")
|
63 |
+
_CITATION = """
|
64 |
+
@misc{misc_fertility_244,
|
65 |
+
author = {Gil,David & Girela,Jose},
|
66 |
+
title = {{Fertility}},
|
67 |
+
year = {2013},
|
68 |
+
howpublished = {UCI Machine Learning Repository},
|
69 |
+
note = {{DOI}: \\url{10.24432/C5Z01Z}}
|
70 |
+
}"""
|
71 |
+
|
72 |
+
# Dataset info
|
73 |
+
urls_per_split = {
|
74 |
+
"train": "https://huggingface.co/datasets/mstz/fertility/raw/main/fertility_Diagnosis.txt"
|
75 |
+
}
|
76 |
+
features_types_per_config = {
|
77 |
+
"encoding": {
|
78 |
+
"feature": datasets.Value("string"),
|
79 |
+
"original_value": datasets.Value("string"),
|
80 |
+
"encoded_value": datasets.Value("int64"),
|
81 |
+
},
|
82 |
+
"fertility": {
|
83 |
+
"season_of_sampling": datasets.Value("string"),
|
84 |
+
"age_at_time_of_sampling": datasets.Value("int8"),
|
85 |
+
"has_had_childhood_diseases": datasets.Value("bool"),
|
86 |
+
"has_had_serious_trauma": datasets.Value("bool"),
|
87 |
+
"has_had_surgical_interventions": datasets.Value("bool"),
|
88 |
+
"has_had_high_fevers_in_the_past_year": datasets.Value("string"),
|
89 |
+
"frequency_of_alcohol_consumption": datasets.Value("float16"),
|
90 |
+
"smoking_frequency": datasets.Value("string"),
|
91 |
+
"number_of_sitting_hours_per_day": datasets.Value("float16"),
|
92 |
+
"has_fertility_issues": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
93 |
+
}
|
94 |
+
}
|
95 |
+
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
96 |
+
|
97 |
+
|
98 |
+
class FertilityConfig(datasets.BuilderConfig):
|
99 |
+
def __init__(self, **kwargs):
|
100 |
+
super(FertilityConfig, self).__init__(version=VERSION, **kwargs)
|
101 |
+
self.features = features_per_config[kwargs["name"]]
|
102 |
+
|
103 |
+
|
104 |
+
class Fertility(datasets.GeneratorBasedBuilder):
|
105 |
+
# dataset versions
|
106 |
+
DEFAULT_CONFIG = "fertility"
|
107 |
+
BUILDER_CONFIGS = [
|
108 |
+
FertilityConfig(name="encoding",
|
109 |
+
description="Encoding dictionaries for discrete features."),
|
110 |
+
FertilityConfig(name="fertility",
|
111 |
+
description="Fertility for binary classification.")
|
112 |
+
]
|
113 |
+
|
114 |
+
|
115 |
+
def _info(self):
|
116 |
+
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
117 |
+
features=features_per_config[self.config.name])
|
118 |
+
|
119 |
+
return info
|
120 |
+
|
121 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
122 |
+
downloads = dl_manager.download_and_extract(urls_per_split)
|
123 |
+
|
124 |
+
return [
|
125 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]})
|
126 |
+
]
|
127 |
+
|
128 |
+
def _generate_examples(self, filepath: str):
|
129 |
+
if self.config.name == "encoding":
|
130 |
+
data = self.encodings()
|
131 |
+
|
132 |
+
for row_id, row in data.iterrows():
|
133 |
+
data_row = dict(row)
|
134 |
+
|
135 |
+
yield row_id, data_row
|
136 |
+
|
137 |
+
else:
|
138 |
+
data = pandas.read_csv(filepath)
|
139 |
+
data = self.preprocess(data, config=self.config.name)
|
140 |
+
|
141 |
+
for row_id, row in data.iterrows():
|
142 |
+
data_row = dict(row)
|
143 |
+
|
144 |
+
yield row_id, data_row
|
145 |
+
|
146 |
+
def encodings(self):
|
147 |
+
data = [pandas.DataFrame([(feature, original_value, encoded_value)
|
148 |
+
for original_value, encoded_value in d.items()],
|
149 |
+
columns=["feature", "original_value", "encoded_value"])
|
150 |
+
for feature, d in _ENCODING_DICS.items()]
|
151 |
+
|
152 |
+
return data
|
153 |
+
|
154 |
+
|
155 |
+
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
|
156 |
+
data.columns = _BASE_FEATURE_NAMES
|
157 |
+
|
158 |
+
for feature in _ENCODING_DICS:
|
159 |
+
encoding_function = partial(self.encode, feature)
|
160 |
+
data.loc[:, feature] = data[feature].apply(encoding_function)
|
161 |
+
|
162 |
+
data = data[list(features_types_per_config[config].keys())]
|
163 |
+
|
164 |
+
return data
|
165 |
+
|
166 |
+
|
167 |
+
def encode(self, feature, value):
|
168 |
+
if feature in _ENCODING_DICS:
|
169 |
+
return _ENCODING_DICS[feature][value]
|
170 |
+
raise ValueError(f"Unknown feature: {feature}")
|
fertility_Diagnosis.txt
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-0.33,0.69,0,1,1,0,0.8,0,0.88,N
|
2 |
+
-0.33,0.94,1,0,1,0,0.8,1,0.31,O
|
3 |
+
-0.33,0.5,1,0,0,0,1,-1,0.5,N
|
4 |
+
-0.33,0.75,0,1,1,0,1,-1,0.38,N
|
5 |
+
-0.33,0.67,1,1,0,0,0.8,-1,0.5,O
|
6 |
+
-0.33,0.67,1,0,1,0,0.8,0,0.5,N
|
7 |
+
-0.33,0.67,0,0,0,-1,0.8,-1,0.44,N
|
8 |
+
-0.33,1,1,1,1,0,0.6,-1,0.38,N
|
9 |
+
1,0.64,0,0,1,0,0.8,-1,0.25,N
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