Datasets:
Update heart_failure.py
Browse files- heart_failure.py +25 -13
heart_failure.py
CHANGED
@@ -36,16 +36,16 @@ urls_per_split = {
|
|
36 |
features_types_per_config = {
|
37 |
"death": {
|
38 |
"age": datasets.Value("int8"),
|
39 |
-
"has_anaemia": datasets.Value("
|
40 |
"creatinine_phosphokinase_concentration_in_blood": datasets.Value("float64"),
|
41 |
-
"has_diabetes": datasets.Value("
|
42 |
"heart_ejection_fraction": datasets.Value("float64"),
|
43 |
-
"has_high_blood_pressure": datasets.Value("
|
44 |
"platelets_concentration_in_blood": datasets.Value("float64"),
|
45 |
"serum_creatinine_concentration_in_blood": datasets.Value("float64"),
|
46 |
"serum_sodium_concentration_in_blood": datasets.Value("float64"),
|
47 |
-
"
|
48 |
-
"is_smoker": datasets.Value("
|
49 |
"days_in_study": datasets.Value("int64"),
|
50 |
"is_dead": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
51 |
}
|
@@ -85,18 +85,30 @@ class HeartFailure(datasets.GeneratorBasedBuilder):
|
|
85 |
]
|
86 |
|
87 |
def _generate_examples(self, filepath: str):
|
88 |
-
|
89 |
-
|
90 |
-
data = self.preprocess(data, config=self.config.name)
|
91 |
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
else:
|
97 |
-
raise ValueError(f"Unknown config: {config}")
|
98 |
|
99 |
def preprocess(self, data: pandas.DataFrame, config: str = "death") -> pandas.DataFrame:
|
100 |
data.columns = _BASE_FEATURE_NAMES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
return data
|
|
|
36 |
features_types_per_config = {
|
37 |
"death": {
|
38 |
"age": datasets.Value("int8"),
|
39 |
+
"has_anaemia": datasets.Value("bool"),
|
40 |
"creatinine_phosphokinase_concentration_in_blood": datasets.Value("float64"),
|
41 |
+
"has_diabetes": datasets.Value("bool"),
|
42 |
"heart_ejection_fraction": datasets.Value("float64"),
|
43 |
+
"has_high_blood_pressure": datasets.Value("bool"),
|
44 |
"platelets_concentration_in_blood": datasets.Value("float64"),
|
45 |
"serum_creatinine_concentration_in_blood": datasets.Value("float64"),
|
46 |
"serum_sodium_concentration_in_blood": datasets.Value("float64"),
|
47 |
+
"is_male": datasets.Value("bool"),
|
48 |
+
"is_smoker": datasets.Value("bool"),
|
49 |
"days_in_study": datasets.Value("int64"),
|
50 |
"is_dead": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
51 |
}
|
|
|
85 |
]
|
86 |
|
87 |
def _generate_examples(self, filepath: str):
|
88 |
+
data = pandas.read_csv(filepath)
|
89 |
+
data = self.preprocess(data, config=self.config.name)
|
|
|
90 |
|
91 |
+
for row_id, row in data.iterrows():
|
92 |
+
data_row = dict(row)
|
93 |
|
94 |
+
yield row_id, data_row
|
|
|
|
|
95 |
|
96 |
def preprocess(self, data: pandas.DataFrame, config: str = "death") -> pandas.DataFrame:
|
97 |
data.columns = _BASE_FEATURE_NAMES
|
98 |
+
data = data.astype({"has_anaemia": "bool", "has_diabetes": "bool", "has_high_blood_pressure": "bool", "is_male": "bool",
|
99 |
+
"is_smoker": "bool"})
|
100 |
+
"age": datasets.Value("int8"),
|
101 |
+
"has_anaemia": datasets.Value("bool"),
|
102 |
+
"creatinine_phosphokinase_concentration_in_blood": datasets.Value("float64"),
|
103 |
+
"has_diabetes": datasets.Value("bool"),
|
104 |
+
"heart_ejection_fraction": datasets.Value("float64"),
|
105 |
+
"has_high_blood_pressure": datasets.Value("bool"),
|
106 |
+
"platelets_concentration_in_blood": datasets.Value("float64"),
|
107 |
+
"serum_creatinine_concentration_in_blood": datasets.Value("float64"),
|
108 |
+
"serum_sodium_concentration_in_blood": datasets.Value("float64"),
|
109 |
+
"is_male": datasets.Value("bool"),
|
110 |
+
"is_smoker": datasets.Value("bool"),
|
111 |
+
"days_in_study": datasets.Value("int64"),
|
112 |
+
"is_dead": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
113 |
|
114 |
return data
|