Datasets:
Upload heart.py
Browse files
heart.py
CHANGED
@@ -40,60 +40,9 @@ _CITATION = """
|
|
40 |
|
41 |
# Dataset info
|
42 |
urls_per_split = {
|
43 |
-
"cleveland": {"train": "https://huggingface.co/datasets/mstz/heart/raw/main/processed.cleveland.data"},
|
44 |
"hungary": {"train": "https://huggingface.co/datasets/mstz/heart/raw/main/processed.hungarian.data"},
|
45 |
-
"switzerland": {"train": "https://huggingface.co/datasets/mstz/heart/raw/main/processed.switzerland.data"},
|
46 |
-
"va": {"train": "https://huggingface.co/datasets/mstz/heart/raw/main/processed.va.data"}
|
47 |
}
|
48 |
features_types_per_config = {
|
49 |
-
"cleveland": {
|
50 |
-
"age": datasets.Value("int8"),
|
51 |
-
"is_male": datasets.Value("bool"),
|
52 |
-
"type_of_chest_pain": datasets.Value("string"),
|
53 |
-
"resting_blood_pressure": datasets.Value("float32"),
|
54 |
-
"serum_cholesterol": datasets.Value("float32"),
|
55 |
-
"fasting_blood_sugar": datasets.Value("float32"),
|
56 |
-
"rest_electrocardiographic_type": datasets.Value("string"),
|
57 |
-
"maximum_heart_rate": datasets.Value("float32"),
|
58 |
-
"has_exercise_induced_angina": datasets.Value("bool"),
|
59 |
-
"depression_induced_by_exercise": datasets.Value("float32"),
|
60 |
-
"slope_of_peak_exercise": datasets.Value("float32"),
|
61 |
-
"number_of_major_vessels_colored_by_flourosopy": datasets.Value("int16"),
|
62 |
-
"thal": datasets.Value("float32"),
|
63 |
-
"has_hearth_disease": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
64 |
-
},
|
65 |
-
"va": {
|
66 |
-
"age": datasets.Value("int8"),
|
67 |
-
"is_male": datasets.Value("bool"),
|
68 |
-
"type_of_chest_pain": datasets.Value("string"),
|
69 |
-
"resting_blood_pressure": datasets.Value("float32"),
|
70 |
-
"serum_cholesterol": datasets.Value("float32"),
|
71 |
-
"fasting_blood_sugar": datasets.Value("float32"),
|
72 |
-
"rest_electrocardiographic_type": datasets.Value("string"),
|
73 |
-
"maximum_heart_rate": datasets.Value("float32"),
|
74 |
-
"has_exercise_induced_angina": datasets.Value("bool"),
|
75 |
-
"depression_induced_by_exercise": datasets.Value("float32"),
|
76 |
-
"slope_of_peak_exercise": datasets.Value("float32"),
|
77 |
-
"number_of_major_vessels_colored_by_flourosopy": datasets.Value("int16"),
|
78 |
-
"thal": datasets.Value("float32"),
|
79 |
-
"has_hearth_disease": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
80 |
-
},
|
81 |
-
"switzerland": {
|
82 |
-
"age": datasets.Value("int8"),
|
83 |
-
"is_male": datasets.Value("bool"),
|
84 |
-
"type_of_chest_pain": datasets.Value("string"),
|
85 |
-
"resting_blood_pressure": datasets.Value("float32"),
|
86 |
-
"serum_cholesterol": datasets.Value("float32"),
|
87 |
-
"fasting_blood_sugar": datasets.Value("float32"),
|
88 |
-
"rest_electrocardiographic_type": datasets.Value("string"),
|
89 |
-
"maximum_heart_rate": datasets.Value("float32"),
|
90 |
-
"has_exercise_induced_angina": datasets.Value("bool"),
|
91 |
-
"depression_induced_by_exercise": datasets.Value("float32"),
|
92 |
-
"slope_of_peak_exercise": datasets.Value("float32"),
|
93 |
-
"number_of_major_vessels_colored_by_flourosopy": datasets.Value("int16"),
|
94 |
-
"thal": datasets.Value("float32"),
|
95 |
-
"has_hearth_disease": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
96 |
-
},
|
97 |
"hungary": {
|
98 |
"age": datasets.Value("int8"),
|
99 |
"is_male": datasets.Value("bool"),
|
@@ -127,14 +76,8 @@ class HeartConfig(datasets.BuilderConfig):
|
|
127 |
|
128 |
class Heart(datasets.GeneratorBasedBuilder):
|
129 |
# dataset versions
|
130 |
-
DEFAULT_CONFIG = "
|
131 |
BUILDER_CONFIGS = [
|
132 |
-
HeartConfig(name="cleveland",
|
133 |
-
description="Heart for binary classification, dataset."),
|
134 |
-
HeartConfig(name="va",
|
135 |
-
description="Heart for binary classification, va dataset."),
|
136 |
-
HeartConfig(name="switzerland",
|
137 |
-
description="Heart for binary classification, switzerland dataset."),
|
138 |
HeartConfig(name="hungary",
|
139 |
description="Heart for binary classification, hungary dataset.")
|
140 |
]
|
@@ -158,12 +101,6 @@ class Heart(datasets.GeneratorBasedBuilder):
|
|
158 |
data.columns = _BASE_FEATURE_NAMES
|
159 |
data = self.preprocess(data, self.config.name)
|
160 |
|
161 |
-
print(data.head())
|
162 |
-
print(data.dtypes)
|
163 |
-
for f in data.columns:
|
164 |
-
print(f)
|
165 |
-
print(data[f].unique())
|
166 |
-
|
167 |
for row_id, row in data.iterrows():
|
168 |
data_row = dict(row)
|
169 |
|
@@ -176,47 +113,26 @@ class Heart(datasets.GeneratorBasedBuilder):
|
|
176 |
|
177 |
data[["age"]].applymap(int)
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
print(f)
|
196 |
-
data = data.astype({"is_male": bool, "has_exercise_induced_angina": bool,
|
197 |
-
"serum_cholesterol": float, "maximum_heart_rate": float,
|
198 |
-
"resting_blood_pressure": float, "fasting_blood_sugar": float})
|
199 |
-
else:
|
200 |
-
data = data[data.thal != "?"]
|
201 |
-
data = data[data.number_of_major_vessels_colored_by_flourosopy != "?"]
|
202 |
-
data = data[data.resting_blood_pressure != "?"]
|
203 |
-
data = data[data.fasting_blood_sugar != "?"]
|
204 |
-
data = data[data.rest_electrocardiographic_type != "?"]
|
205 |
-
data = data[data.maximum_heart_rate != "?"]
|
206 |
-
data = data[data.has_exercise_induced_angina != "?"]
|
207 |
-
|
208 |
-
for f in data.columns:
|
209 |
-
if "?" in data[f].values:
|
210 |
-
print(f)
|
211 |
-
data = data.astype({"is_male": bool, "has_exercise_induced_angina": bool,
|
212 |
-
"serum_cholesterol": float, "maximum_heart_rate": float,
|
213 |
-
"resting_blood_pressure": float, "fasting_blood_sugar": float,
|
214 |
-
"thal": float, "number_of_major_vessels_colored_by_flourosopy": float})
|
215 |
-
|
216 |
|
217 |
return data
|
218 |
|
219 |
def encode(self, feature, value):
|
220 |
if feature in _ENCODING_DICS:
|
221 |
return _ENCODING_DICS[feature][value]
|
222 |
-
raise ValueError(f"Unknown feature: {feature}")
|
|
|
40 |
|
41 |
# Dataset info
|
42 |
urls_per_split = {
|
|
|
43 |
"hungary": {"train": "https://huggingface.co/datasets/mstz/heart/raw/main/processed.hungarian.data"},
|
|
|
|
|
44 |
}
|
45 |
features_types_per_config = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
"hungary": {
|
47 |
"age": datasets.Value("int8"),
|
48 |
"is_male": datasets.Value("bool"),
|
|
|
76 |
|
77 |
class Heart(datasets.GeneratorBasedBuilder):
|
78 |
# dataset versions
|
79 |
+
DEFAULT_CONFIG = "hungary"
|
80 |
BUILDER_CONFIGS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
HeartConfig(name="hungary",
|
82 |
description="Heart for binary classification, hungary dataset.")
|
83 |
]
|
|
|
101 |
data.columns = _BASE_FEATURE_NAMES
|
102 |
data = self.preprocess(data, self.config.name)
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
for row_id, row in data.iterrows():
|
105 |
data_row = dict(row)
|
106 |
|
|
|
113 |
|
114 |
data[["age"]].applymap(int)
|
115 |
|
116 |
+
data.drop("slope_of_peak_exercise", axis="columns", inplace=True)
|
117 |
+
data.drop("number_of_major_vessels_colored_by_flourosopy", axis="columns", inplace=True)
|
118 |
+
data.drop("thal", axis="columns", inplace=True)
|
119 |
+
data = data[data.serum_cholesterol != "?"]
|
120 |
+
|
121 |
+
data = data.infer_objects()
|
122 |
+
|
123 |
+
data = data[data.resting_blood_pressure != "?"]
|
124 |
+
data = data[data.fasting_blood_sugar != "?"]
|
125 |
+
data = data[data.rest_electrocardiographic_type != "?"]
|
126 |
+
data = data[data.maximum_heart_rate != "?"]
|
127 |
+
data = data[data.has_exercise_induced_angina != "?"]
|
128 |
+
|
129 |
+
data = data.astype({"is_male": bool, "has_exercise_induced_angina": bool,
|
130 |
+
"serum_cholesterol": float, "maximum_heart_rate": float,
|
131 |
+
"resting_blood_pressure": float, "fasting_blood_sugar": float})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
return data
|
134 |
|
135 |
def encode(self, feature, value):
|
136 |
if feature in _ENCODING_DICS:
|
137 |
return _ENCODING_DICS[feature][value]
|
138 |
+
raise ValueError(f"Unknown feature: {feature}")
|