-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add heart disease dataset #2019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
acharles7
wants to merge
8
commits into
tensorflow:master
Choose a base branch
from
acharles7:heart_datasets
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4a1bada
added heart disease dataset
acharles7 07c669d
added license text
acharles7 f0cf64c
changed to splitlines
acharles7 b516801
Merge remote-tracking branch 'origin/master' into heart_datasets
acharles7 d8f05ec
feature seperated
acharles7 da4745c
added ClassLabel
acharles7 9e12a81
fake data changed
acharles7 720db2b
complexity simplified
acharles7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# coding=utf-8 | ||
# Copyright 2020 The TensorFlow Datasets Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Lint as: python3 | ||
"""Heart disease dataset.""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import tensorflow.compat.v2 as tf | ||
import tensorflow_datasets.public_api as tfds | ||
|
||
_CITATION = """\ | ||
@misc{Dua:2019 , | ||
author = "Janosi, Steinbrunn and Pfisterer, Detrano", | ||
year = "1988", | ||
title = "{UCI} Machine Learning Repository", | ||
url = "http://archive.ics.uci.edu/ml/datasets/Heart+Disease", | ||
institution = "University of California, Irvine, School of Information and Computer Sciences" | ||
} | ||
""" | ||
|
||
_DESCRIPTION = """\ | ||
This data set contain 13 attributes and labels of heart disease from \ | ||
303 participants from Cleveland since Cleveland data was most commonly\ | ||
used in modern research. | ||
|
||
Attribute by column index | ||
1. age : age in years | ||
2. sex : sex (1 = male; 0 = female) | ||
3. cp : chest pain type | ||
(1 = typical angina; 2 = atypical angina; 3 = non-anginal pain; 4 = asymptomatic) | ||
4. trestbps : resting blood pressure (in mm Hg on admission to the hospital) | ||
5. chol : serum cholestoral in mg/dl | ||
6. fbs : (fasting blood sugar > 120 mg/dl) (1 = true; 0 = false) | ||
7. restecg : resting electrocardiographic results | ||
8. thalach : maximum heart rate achieved | ||
9. exang : exercise induced angina (1 = yes; 0 = no) | ||
10. oldpeak : ST depression induced by exercise relative to rest | ||
11. slope : the slope of the peak exercise ST segment (1 = upsloping; 2 = flat; 3 = downsloping) | ||
12. ca : number of major vessels (0-3) colored by flourosopy | ||
13. thal : 3 = normal; 6 = fixed defect; 7 = reversable defect | ||
14. num (the predicted attribute): diagnosis of heart disease (angiographic disease status) | ||
(0 = < 50% diameter narrowing, no presence of heart disease; | ||
1 = > 50% diameter narrowing, with increasing severity) | ||
Dataset Homepage: http://archive.ics.uci.edu/ml/datasets/Heart+Disease | ||
""" | ||
|
||
_CP_NAMES = ['typical angina', 'atypical angina', | ||
'non-anginal pain', 'asymptomatic'] | ||
_SLOPE_NAMES = ['upsloping', 'flat', 'downsloping'] | ||
|
||
_DOWNLOAD_URL = 'http://archive.ics.uci.edu/ml/machine-learning-databases/heart-disease/processed.cleveland.data' | ||
|
||
_FEATURE_DICT = { | ||
"age": tf.int32, | ||
"sex": tfds.features.ClassLabel(names=['female', 'male']), | ||
"cp": tfds.features.ClassLabel(names=_CP_NAMES), | ||
"trestbps": tf.int32, | ||
"chol": tf.int32, | ||
"fbs": tfds.features.ClassLabel(names=['false', 'true']), | ||
"restecg": tf.int32, | ||
"thalach": tf.int32, | ||
"exang": tfds.features.ClassLabel(names=['no', 'yes']), | ||
"oldpeak": tf.float32, | ||
"slope": tfds.features.ClassLabel(names=_SLOPE_NAMES), | ||
"ca": tf.int32, | ||
"thal": tf.int32 | ||
} | ||
|
||
class HeartDisease(tfds.core.GeneratorBasedBuilder): | ||
"""Heart disease dataset with 13 attributes.""" | ||
|
||
VERSION = tfds.core.Version("0.0.1", "New split API (https://tensorflow.org/datasets/splits)") | ||
|
||
def _info(self): | ||
return tfds.core.DatasetInfo( | ||
builder=self, | ||
description=_DESCRIPTION, | ||
features=tfds.features.FeaturesDict({ | ||
"features": _FEATURE_DICT, | ||
"label": tfds.features.ClassLabel(names=['0', '1', '2', '3', '4']) | ||
}), | ||
supervised_keys=("features", "label"), | ||
homepage='http://archive.ics.uci.edu/ml/datasets/Heart+Disease', | ||
citation=_CITATION, | ||
) | ||
|
||
def _split_generators(self, dl_manager): | ||
"""Returns SplitGenerators.""" | ||
|
||
filepath = dl_manager.download(_DOWNLOAD_URL) | ||
|
||
# There is no predefined train/val/test split for this dataset. | ||
return [ | ||
tfds.core.SplitGenerator( | ||
name=tfds.Split.TRAIN, | ||
gen_kwargs={"filepath": filepath} | ||
), | ||
] | ||
|
||
def _generate_examples(self, filepath): | ||
"""Yields examples.""" | ||
|
||
with tf.io.gfile.GFile(filepath) as f: | ||
fieldnames = ["age", "sex", "cp", "trestbps", "chol", "fbs", | ||
"restecg", "thalach", "exang", "oldpeak", "slope", | ||
"ca", "thal", "label"] | ||
lines = f.read().splitlines() | ||
records = [line.replace('?', '-1') for line in lines] | ||
for i, features in enumerate(records): | ||
values = {k: float(v) for k, v in zip(fieldnames, features.split(','))} | ||
yield i, { | ||
"features": { | ||
"age": int(values['age']), | ||
"sex": int(values['sex']), | ||
"cp": int(values['cp'])-1, | ||
"trestbps": int(values['trestbps']), | ||
"chol": int(values['chol']), | ||
"fbs": int(values['fbs']), | ||
"restecg": int(values['restecg']), | ||
"thalach": int(values['thalach']), | ||
"exang": int(values['exang']), | ||
"oldpeak": values['oldpeak'], | ||
"slope": int(values['slope'])-1, | ||
"ca": int(values['ca']), | ||
"thal": int(values['thal']) | ||
}, | ||
"label": int(values['label']) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# coding=utf-8 | ||
# Copyright 2020 The TensorFlow Datasets Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Lint as: python3 | ||
"""Heart disease dataset.""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import tensorflow_datasets.public_api as tfds | ||
from tensorflow_datasets.structured import heart_disease | ||
|
||
class HeartDiseaseTest(tfds.testing.DatasetBuilderTestCase): | ||
"""test for heart disease dataset""" | ||
DATASET_CLASS = heart_disease.HeartDisease | ||
SPLITS = { | ||
"train": 2, # Number of fake train example | ||
} | ||
DL_EXTRACT_RESULT = 'processed.cleveland.data' | ||
|
||
if __name__ == "__main__": | ||
tfds.testing.test_main() |
2 changes: 2 additions & 0 deletions
2
tensorflow_datasets/testing/test_data/fake_examples/heart_disease/processed.cleveland.data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
63.0,1.0,1.0,145.0,233.0,1.0,2.0,150.0,0.0,2.3,3.0,0.0,6.0,0 | ||
53.0,1.0,2.0,140.0,145.0,1.0,2.0,113.0,0.0,4.1,2.0,0.0,6.0,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
http://archive.ics.uci.edu/ml/machine-learning-databases/heart-disease/processed.cleveland.data 18461 a74b7efa387bc9d108d7d0115d831fe9b414b29ae7124f331b622b4efa0427c8 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.