Heart Attack Prediction with Artificial Neural Network

According to the American Heart Association, “between 2013 and 2016, 121.5 million American adults had some form of cardiovascular disease.”[1] One of the major factors is that doctors may misdiagnose the patients with heart attack and fail to prevent the progressive illness from worsening in the early stage. In this paper, we construct and evaluate an efficient artificial neural network model for analyzing patients’ feature data and predicting the probability of a patient to get a heart attack. With the help of our heart attack prediction model, doctors are able to discover the heart attack early. They can also prescribe medicine for the heart attack patients accurately with the aid of the feature analyzation function of our model. Our heart attack prediction model reaches a high accuracy of 88.51%, which is better than other models.


Introduction
Currently, a trend of suffering from a heart attack is on the rise. The increasing number of cardiac patients warns us that current ways to check patients' health status are ineffective in preventing patients from heart attack. Existing heart attack checking mainly depends on doctors' reporting and retrospective investigation. Since the 1990s, a large number of Chinese hospitals develop their checking software, which started from simple data analysis to mature hospital infection systems built from hospital information systems, improving the nosocomial infection control significantly. Additionally, a comprehensive system that can deal with a large amount of historical patient data and automatically analyze nosocomial infection not only can reduce the labor cost but also improve the efficiency and accuracy of the nosocomial infection checking. Therefore, to design an automatic hospital infection checking system is beneficial for our health. Current algorithms to diagnosis heart attacks make good use of machine learning methods. Jyoti Soni [2] utilized Naive Bayes, K-NN, and Decision List algorithm in the data mining stage to predict heart disease. Multi-layer Perceptron Neural Network with Back-propagation is being used as the training algorithm in his neural network system. The result turns out that his predication system reaches 88.3% accuracy in Classification via clustering, proving that his prediction model is effective in assisting the current hospital disease prediction system.
Apart from using K-NN as the classification method, we decided to use Artificial Neural Networks (ANN) and embedded patients' features into matrices, which contains basic health information of the patients. By labializing and re-classifying these matrices, we could predict the probability of each patient's chance to get a heart attack. The loss function should also be well-designed to make the prediction close to the sample. My goal is to compare the accuracy of different ANN structures and reach an optimal method to help predict the probability of getting a heart attack.

Related work
Palaniappan designed the CRISP-DM method, which is designed to predict the heart attack. [3] He utilized Naïve Bayes, Decision Trees, and Neural Network; the model can analyze patients' profiles more efficiently and make better predictions.
Another related work of heart disease prediction is Latha Parthiban and R.Subramanian's Intelligent Heart Disease Prediction System. Their model utilizes a CANFIS model, which "integrates adaptable fuzzy inputs with a modular neural network to rapidly and accurately approximate complex functions." [4] Additionally, to improve their model's performance, Latha Parthiban and R.Subramanian use genetic algorithms to find suitable parameters for learning rate and momentum coefficient. By using their model, doctors can make better decisions on patients' heart diseases.
In addition, Jyoti Soni and her team introduced a prediction system using weighted associative classifiers, which has numerous advantages compared to traditional classifiers approaches such as decision tree. [5] By utilizing Weighted Associative Classifier, their heart attack prediction system assigns each attribute a weight to reflect the importance. Additionally, they apply Weighted Association Rule Mining (WARM) algorithm [5] to generate useful patterns, facilitating class label prediction.
Besides, Hlaudi Daniel Masethe designed a heart disease prediction system using classification algorithms. [6] Their model successfully applies J48, Bayes Net, Naive Bayes, and many other algorithms to help diagnose heart attacks based on patient data set. Data mining techniques are used in their model to classify characteristics and predict possible heart attacks.

Heart Attack Prediction Model
Our heart attack prediction model consists of two parts: data analyzation and prediction. The dataset comes from the Kaggle website and collected by Andras Janosi M.D. et al. [7] The data contains three hundred and three records, and by utilizing test_size as 0.2, the model divides the whole data set to two hundred and forty-two training sets and sixty-one testing sets.

Data analyzation
In the data analyzation part, We draw two scatter diagrams to show the relationship between any two characteristics of cardiac patients and non-cardiac patients. These scatter diagrams help visualize the hidden connection between every two heart attack features, assisting for further data analyzation. We draw a heatmap(see Figure 1) to show the correlation of each pair of characteristics in a numeric way, and a large value reveals a strong relationship between characteristics.

Prediction
In the prediction part, the model first standardizes the dataset by removing the mean and scaling to unit variance in order to normalize features for further prediction. Then, a sequential model is constructed with three learned layers. Since the previous analyzation part shows nonlinear relationships between heart attack features, the model needs activation functions to prevent from becoming a linear regression model. We choose Rectified Linear units(ReLUs) as our activation functions in the first two layers, which significantly helps reduce vanishing gradient problems. However, ReLUs may result in exploding gradients or vanishing gradients. To solve these problems, we add a third layer with a sigmoid activation function. It is an activation function of form f(x) = 1 / 1 + exp(-x). We consider multiple alternatives to reach a better prediction model, which is discussed in the Experiment part.

Figure 2. epoch_accuracy and epoch_loss graphs
Additionally, to improve the accuracy of our model, we use Adam Optimizer to compile our sequential artificial neural network model. By updating network weights iterative, the Adam Optimizer can help resolve the vanishing gradient problems introduced by ReLU and sigmoid activation methods. The layer structure of our model is revealed in Figure 3.

Experiment
We evaluate the correctness of our models by comparing the accuracy scores of different layer structures. Some partial comparison results are summarized in Table 1. We altered our layer structure by using different activation functions and shifting the order of the layers. In Table 1, two different layer structures are listed. The major difference between these two structures is the activation function used in the second layer: the first one uses ReLU as its activation function, while the second one uses tanh as its activation function. The accuracy score is calculated based on the fraction of correctly classified sample. We discover that the first layer structure listed in Table 1 achieves better performance, and the average accuracy reaches 0.8851.

Conclusion
As a result, we reach a heart attack analyzation and prediction model, which can help predict the probability of patients to get a heart attack. In this way, doctors can discover the danger at a very early stage and take action effectively to stop the disease from getting worse.