Code Monkey home page Code Monkey logo

heart_disease_prediction's Introduction

Heart Disease Prediction

Simple project to determine the degree of narrowing blood vessel walls based on the features of the patient

Tools used:

Language: Python
Libraries: Numpy, Pandas, Seaborn
Frameworks: Tensorflow, Keras, Scikit-Learn, Flask

Dataset:

The dataset is taken from UCI
Features:

  • age: age in years
  • sex: sex (1 = male; 0 = female)
  • cp: chest pain type (1 = typical angina; 2 = atypical angina; 3 = non-anginal pain; 4 = asymptomatic)
  • trestbps: resting blood pressure (in mm Hg on admission to the hospital)
  • chol: serum cholestoral in mg/dl
  • fbs: fasting blood sugar > 120 mg/dl (1 = true; 0 = false)
  • restecg: resting electrocardiographic results (0 = normal; 1 = having ST-T wave abnormality; 2 = showing probable or definite left ventricular hypertrophy by Estes' criteria)
  • thalach: maximum heart rate achieved
  • exang: exercise induced angina (1 = yes; 0 = no)
  • oldpeak: ST depression induced by exercise relative to rest
  • slope: the slope of the peak exercise ST segment (1 = upsloping; 2 = flat; 3 = downsloping)
  • ca: number of major vessels (0-3) colored by flourosopy
  • thal: (3 = normal; 6 = fixed defect; 7 = reversable defect)
  • target: diagnosis of heart disease (angiographic disease status) (0 = < 50% diameter narrowing; 1 = > 50% diameter narrowing)

Analysis:

  • SOURCE
  • The dataset has 13 features. The target variable is the last one
  • There are 1025 entities in the dataset, each with their own feature values. Each entity represents a patient
  • The dataset is already cleaned, with no null values
  • Using the pandas correlation matrix and seaborn heatmap, we see:
    • oldpeak and exang are negatively correlated
    • cp and thalach are positively correlated
  • From the above observation, it becomes clear that:
    • The chance of diameter narrowing reduces with exercise
    • Higher heart rate and chest pain indicates diameter narrowing
  • Exercising regularly and maintaining a healthy heart rate can clearly reduce the chances of diameter narrowing

Training:

  • SOURCE
  • We drop the target variable from the dataset and use the remaining features to predict the target variable
  • We will use 80% of the dataset for training the neural network
  • The model we used is a simple sequential model, consisting of only 1 hidden layer
  • The structure of the model is as follows:
    • Input layer: 64 neurons, ReLU activation
    • Hidden layer: 32 neurons, ReLU activation
    • Output layer: 1 neuron, Sigmoid activation
  • Since the target is binary, we have used Sigmoid as the activation function of the output layer, and the optimizer is Adam
  • Since the dataset is relatively small, we have created this simple NN structure and also are dropping 10% training data while leaving each layer. All this has been done to avoid overfitting
  • Training accuracy is 83%
  • Validation accuracy is 78%
  • I have tried tweaking the hyper-parameters multiple times, but this seems to be the most optimal. I did not increase the complexity of the model just for the sake of improving it's accuracy, since it will come at a cost of overfitting
  • The model is saved in the file heart_model.h5
  • As shown in the notebook, we can load the model and use it to predict the target variable for any new entity
  • The model throws result in floating point numbers, while the target should be integer (binary)
  • We converted the output to integer and then tested against an unseen dataset. The accuracy was 78%
  • The model seems to have been properly trained

Deployment:

  • SOURCE
  • We use Flask to deploy the model
  • The HTML templates used have been stored in templates directory
  • The steps to use the model is as follows:
    • Run the Flask app:
      python app.py
    • Open the link (shown in the terminal) in the browser
    • Upload the .csv file containing the features of the patient (except the target variable ofcourse)
    • Click on the Predict button
    • You will be redirected to a new webpage that contains the result
    • NOTE: The predicted csv file is displayed in the webpage, i.e., in HTML form. You can manually download the predicted csv file by using pandas to convert the data dataframe present in app.py to a csv file and then saving it

heart_disease_prediction's People

Contributors

aishik999 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.