Datasets:
Upload heart.py
Browse files
heart.py
CHANGED
@@ -112,6 +112,14 @@ features_types_per_config = {
|
|
112 |
}
|
113 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
class HeartConfig(datasets.BuilderConfig):
|
117 |
def __init__(self, **kwargs):
|
@@ -151,16 +159,27 @@ class Heart(datasets.GeneratorBasedBuilder):
|
|
151 |
data = pandas.read_csv(filepath, header=None)
|
152 |
data.columns = _BASE_FEATURE_NAMES
|
153 |
|
154 |
-
|
|
|
|
|
155 |
|
|
|
|
|
156 |
data = data[data.thal != "?"]
|
157 |
data = data[data.number_of_major_vessels_colored_by_flourosopy != "?"]
|
158 |
data = data.infer_objects()
|
159 |
|
160 |
print(data.head())
|
161 |
print(data.dtypes)
|
|
|
|
|
162 |
|
163 |
for row_id, row in data.iterrows():
|
164 |
data_row = dict(row)
|
165 |
|
166 |
yield row_id, data_row
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
114 |
|
115 |
+
_ENCODING_DICS = {
|
116 |
+
"type_of_chest_pain": {
|
117 |
+
1: "typical angina"
|
118 |
+
2: "atypical angina"
|
119 |
+
3: "non-anginal pain"
|
120 |
+
4: "asymptomatic"
|
121 |
+
}
|
122 |
+
}
|
123 |
|
124 |
class HeartConfig(datasets.BuilderConfig):
|
125 |
def __init__(self, **kwargs):
|
|
|
159 |
data = pandas.read_csv(filepath, header=None)
|
160 |
data.columns = _BASE_FEATURE_NAMES
|
161 |
|
162 |
+
for feature in _ENCODING_DICS:
|
163 |
+
encoding_function = partial(self.encode, feature)
|
164 |
+
data.loc[:, feature] = data[feature].apply(encoding_function)
|
165 |
|
166 |
+
data = data.astype({"is_male": bool, "has_exercise_induced_angina": bool})
|
167 |
+
data.age.applymap(int)
|
168 |
data = data[data.thal != "?"]
|
169 |
data = data[data.number_of_major_vessels_colored_by_flourosopy != "?"]
|
170 |
data = data.infer_objects()
|
171 |
|
172 |
print(data.head())
|
173 |
print(data.dtypes)
|
174 |
+
print(data.number_of_major_vessels_colored_by_flourosopy.unique())
|
175 |
+
print(data.thal.unique())
|
176 |
|
177 |
for row_id, row in data.iterrows():
|
178 |
data_row = dict(row)
|
179 |
|
180 |
yield row_id, data_row
|
181 |
+
|
182 |
+
def encode(self, feature, value):
|
183 |
+
if feature in _ENCODING_DICS:
|
184 |
+
return _ENCODING_DICS[feature][value]
|
185 |
+
raise ValueError(f"Unknown feature: {feature}")
|