Datasets:
Upload heart.py
Browse files
heart.py
CHANGED
@@ -105,9 +105,6 @@ features_types_per_config = {
|
|
105 |
"maximum_heart_rate": datasets.Value("float32"),
|
106 |
"has_exercise_induced_angina": datasets.Value("bool"),
|
107 |
"depression_induced_by_exercise": datasets.Value("float32"),
|
108 |
-
"slope_of_peak_exercise": datasets.Value("float32"),
|
109 |
-
"number_of_major_vessels_colored_by_flourosopy": datasets.Value("int16"),
|
110 |
-
"thal": datasets.Value("float32"),
|
111 |
"has_hearth_disease": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
112 |
},
|
113 |
}
|
@@ -159,7 +156,19 @@ class Heart(datasets.GeneratorBasedBuilder):
|
|
159 |
def _generate_examples(self, filepath: str):
|
160 |
data = pandas.read_csv(filepath, header=None)
|
161 |
data.columns = _BASE_FEATURE_NAMES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
|
|
|
|
|
|
163 |
for feature in _ENCODING_DICS:
|
164 |
encoding_function = partial(self.encode, feature)
|
165 |
data.loc[:, feature] = data[feature].apply(encoding_function)
|
@@ -168,17 +177,17 @@ class Heart(datasets.GeneratorBasedBuilder):
|
|
168 |
data[["age"]].applymap(int)
|
169 |
data = data[data.thal != "?"]
|
170 |
data = data[data.number_of_major_vessels_colored_by_flourosopy != "?"]
|
171 |
-
data = data.infer_objects()
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
|
178 |
-
|
179 |
-
|
|
|
180 |
|
181 |
-
|
182 |
|
183 |
def encode(self, feature, value):
|
184 |
if feature in _ENCODING_DICS:
|
|
|
105 |
"maximum_heart_rate": datasets.Value("float32"),
|
106 |
"has_exercise_induced_angina": datasets.Value("bool"),
|
107 |
"depression_induced_by_exercise": datasets.Value("float32"),
|
|
|
|
|
|
|
108 |
"has_hearth_disease": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
109 |
},
|
110 |
}
|
|
|
156 |
def _generate_examples(self, filepath: str):
|
157 |
data = pandas.read_csv(filepath, header=None)
|
158 |
data.columns = _BASE_FEATURE_NAMES
|
159 |
+
data = self.process(data, self.config.name)
|
160 |
+
|
161 |
+
print(data.head())
|
162 |
+
print(data.dtypes)
|
163 |
+
print(data.number_of_major_vessels_colored_by_flourosopy.unique())
|
164 |
+
print(data.thal.unique())
|
165 |
+
|
166 |
+
for row_id, row in data.iterrows():
|
167 |
+
data_row = dict(row)
|
168 |
|
169 |
+
yield row_id, data_row
|
170 |
+
|
171 |
+
def preprocess(self, data, config):
|
172 |
for feature in _ENCODING_DICS:
|
173 |
encoding_function = partial(self.encode, feature)
|
174 |
data.loc[:, feature] = data[feature].apply(encoding_function)
|
|
|
177 |
data[["age"]].applymap(int)
|
178 |
data = data[data.thal != "?"]
|
179 |
data = data[data.number_of_major_vessels_colored_by_flourosopy != "?"]
|
|
|
180 |
|
181 |
+
if config == "hungary":
|
182 |
+
data.drop("slope_of_peak_exercise", axis="columns", inplace=True)
|
183 |
+
data.drop("number_of_major_vessels_colored_by_flourosopy", axis="columns", inplace=True)
|
184 |
+
data.drop("thal", axis="columns", inplace=True)
|
185 |
|
186 |
+
data = data[data.serum_cholesterol != "?"]
|
187 |
+
|
188 |
+
data = data.infer_objects()
|
189 |
|
190 |
+
return data
|
191 |
|
192 |
def encode(self, feature, value):
|
193 |
if feature in _ENCODING_DICS:
|