0% found this document useful (0 votes)
28 views114 pages

Heart Disease Prediction Using ML

This document discusses the implementation of a heart disease prediction system using machine learning, specifically the Random Forest algorithm, to analyze medical data and predict heart disease at early stages. It highlights the significance of heart disease as a leading cause of death globally and emphasizes the use of data mining techniques to assist in decision-making. The study utilizes the Cleveland Heart Disease dataset to train various classification models, achieving high accuracy rates in predictions.

Uploaded by

dhanumb1983
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views114 pages

Heart Disease Prediction Using ML

This document discusses the implementation of a heart disease prediction system using machine learning, specifically the Random Forest algorithm, to analyze medical data and predict heart disease at early stages. It highlights the significance of heart disease as a leading cause of death globally and emphasizes the use of data mining techniques to assist in decision-making. The study utilizes the Cleveland Heart Disease dataset to train various classification models, achieving high accuracy rates in predictions.

Uploaded by

dhanumb1983
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ABSTRACT

Heart attack disease is one of the leading causes of the death worldwide. In today’s common
modern life, deaths due to the heart disease had become one of major issues, that roughly one
person lost his or her life per minute due to heart illness. Predicting the occurrence of disease
at early stages is a major challenge nowadays. Machine learning when implemented in health
care is capable of early and accurate detection of disease. In this work, the arising situations of
heart disease illness are calculated. Datasets used have attributes of medical parameters. The
datasets are been processed in python using ML Algorithm i.e., Random Forest Algorithm. This
technique uses the past old patient records for getting prediction of new one at early stages
preventing the loss of lives. In this work, reliable heart disease prediction system is
implemented using strong Machine Learning algorithm which is the Random Forest algorithm.
Which read patient record data set in the form of CSV file. After accessing dataset, the
operation is performed and effective heart attack level is produced. Advantages of proposed
system are High performance and accuracy rate and it is very flexible and high rates of success
are achieved.
TABLE OF CONTENTS

Chapter 1: Introduction

1.1 Project Description

1.2 Company Profile

1.3 Dissertation Organization

Chapter 2: Literature Review

2.1 Existing and Proposed System

2.2 Tools and Technologies used

2.3 Hardware and Software Requirements

Chapter 3: Software Requirement Specifications

3.1 Software Requirement Specifications

3.2 Algorithms used


3.3 Non-Functional Requirement

Chapter 4: Implementation

4.1 Implementation

Chapter 5: Conclusion

Chapter 6: Future Enhancements

Bibliography

CHAPTER 1: INTRODUCTION

1.1 Project description


The system can discover and extract hidden knowledge associated with diseases from a
historical heart data set.
Heart disease prediction system aims to exploit data mining techniques on medical data set
to assist in the prediction of the heart diseases.

Specific Objectives.

Provides new approach to concealed patterns in the data.

Helps avoid human biasness.


1.2 Company profile
“Acranton technologies pvt. ltd. was started in the year 2018 in Davangere by the software
engineers who were dreamed to become entrepreneurs. “We love people and everything
about them thus; our product will simply be an extension or an expression of oneself. Our
business is to change the way things work around us and not settle for anything less than
revolutionary". We work with dedication and determination to provide best IT solutions to
our clients and also help students in achieving their career goals”.
Acranton technologies pvt. ltd. is a global services provider, delivering technology driven
business solutions that meet the strategic objectives of the clients. Acranton technologies
pvt. ltd has Centres of Excellence that create solutions around specific needs of industries.
Acranton technologies pvt. ltd delivers unmatched business value to customers through a
combination of process excellence, quality frameworks and service delivery
Innovation remains a key focus for companies seeking to spur growth. In this age of
constant change, Collaborative Innovation has strategically emerged amongst a network of
companies to help, solicit and harness external talent, expertise, and ideas worldwide,
identify and capture global collaborative opportunities, and maximize profitability through
new ventures. The aim is to establish mutually beneficial relationships through which new
products and services are developed. In short, firms increasingly seek superior performance
in innovation through collaboration.

1.2.1 Services
We believe in Customer Satisfaction. Here we are offering wide range of services
starting with simple web design to enterprise architecture.

1.2.2 Project
• Online entrance exam and admission process
• SRMS Ayurveda billing software
• UNIFIED EDU info
• E-Learning resource locator
• House locator
• Advance restaurant management system
• Advanced hospital management system
• Master PC remote control using Bluetooth
• Website for Karnataka municipal union

1.3 Dissertation Organization


Scranton technologies pvt. ltd. offers a full life cycle software development because its
services span includes product development, testing, technical support, implementation
and maintenances. Our Custom Software Developments include techniques and programs
like .NET Programming / Java, application re-engineering, PHP, software re factoring.
Internet/Intranet web design services include services like CRM, Client/Server application
development, Web development and Knowledge Management systems. Acranton
technologies pvt. ltd. is a Comprehensive Human Resources Solutions provider and it is
extended to service Recruitment, Website Designing and Hosting, Software Development
and Maintenance. It maintains the highest standards of Honesty and Integrity. Its priori is to
look after the Customers, Corporate and the Employees in every possible way. It always
believes in establishing long term relationship which transforms into business and therefore
transparent in dealings with company.

Vision
“Creating the premier technological pivot and stare down the impossible until it blinks”
Mission
• To provide superior quality product service; we will radically shift the global economy
toward small business by empowering products confidently grow and successfully their own
ventures.
• Solving people problems and difficulties by adoption of technologies.
• To promote technical ideas into reality through applications for better future.
• Endeavoring the digital technology.
• Providing ocean of opportunities by sharing the trending technology to the seeking
personnel

Introduction

Heart disease describes a range of conditions that affect your heart.


Diseases under the heart disease umbrella include blood vessel diseases,
such as coronary artery disease, heart rhythm problems (arrhythmias) and
heart defects you’re born with (congenital heart defects), among others.

The term “heart disease” is often used interchangeably with the term
“cardiovascular disease”. Cardiovascular disease generally refers to
conditions that involve narrowed or blocked blood vessels that can lead to a
heart attack, chest pain (angina) or stroke. Other heart conditions, such as
those that affect your heart’s muscle, valves or rhythm, also are considered
forms of heart disease.

Heart disease is one of the biggest causes of morbidity and mortality among
the population of the world. Prediction of cardiovascular disease is regarded
as one of the most important subjects in the section of clinical data analysis.
The amount of data in the healthcare industry is huge. Data mining turns the
large collection of raw healthcare data into information that can help to
make informed decisions and predictions.

According to a news article, heart disease proves to be the leading cause of


death for both women and men. The article states the following :

About 610,000 people die of heart disease in the India every year–that’s 1 in every 4
deaths.1

Heart disease is the leading cause of death for both men and women. More than half of
the deaths due to heart disease in 2009 were in men.1

Coronary Heart Disease(CHD) is the most common type of heart disease, killing over
370,000 people annually.

Every year about 735,000 Americans have a heart attack. Of these, 525,000 are a first
heart attack and 210,000 happen in people who have already had a heart attack.

This makes heart disease a major concern to be dealt with. But it is difficult
to identify heart disease because of several contributory risk factors such as
diabetes, high blood pressure, high cholesterol, abnormal pulse rate, and
many other factors. Due to such constraints, scientists have turned towards
modern approaches like Data Mining and Machine Learning for predicting
the disease.

Machine learning (ML) proves to be effective in assisting in making


decisions and predictions from the large quantity of data produced by the
healthcare industry.

The Data

The dataset used in this article is the Cleveland Heart Disease dataset taken
from the UCI repository.

The dataset consists of 303 individuals data. There are 14 columns in the
dataset, which are described below.

1. Age: displays the age of the individual.


2. Sex: displays the gender of the individual using the following format :
1 = male
0 = female

3. Chest-pain type: displays the type of chest-pain experienced by the


individual using the following format :
1 = typical angina
2 = atypical angina
3 = non — anginal pain
4 = asymptotic

4. Resting Blood Pressure: displays the resting blood pressure value of


an individual in mmHg (unit)

5. Serum Cholestrol: displays the serum cholesterol in mg/dl (unit)

6. Fasting Blood Sugar: compares the fasting blood sugar value of an


individual with 120mg/dl.
If fasting blood sugar > 120mg/dl then : 1 (true)
else : 0 (false)

7. Resting ECG : displays resting electrocardiographic results


0 = normal
1 = having ST-T wave abnormality
2 = left ventricular hyperthrophy

8. Max heart rate achieved : displays the max heart rate achieved by an
individual.

9. Exercise induced angina :


1 = yes
0 = no
10. ST depression induced by exercise relative to rest: displays the
value which is an integer or float.

11. Peak exercise ST segment :


1 = upsloping
2 = flat
3 = downsloping

12. Number of major vessels (0–3) colored by flourosopy : displays


the value as integer or float.

13. Thal : displays the thalassemia :


3 = normal
6 = fixed defect
7 = reversible defect

14. Diagnosis of heart disease : Displays whether the individual is


suffering from heart disease or not :
0 = absence
1, 2, 3, 4 = present.

Why these parameters:

In the actual dataset, we had 76 features but for our study, we chose only
the above 14 because :

1. Age: Age is the most important risk factor in developing cardiovascular


or heart diseases, with approximately a tripling of risk with each decade
of life. Coronary fatty streaks can begin to form in adolescence. It is
estimated that 82 percent of people who die of coronary heart disease
are 65 and older. Simultaneously, the risk of stroke doubles every
decade after age 55.
2. Sex: Men are at greater risk of heart disease than pre-menopausal
women. Once past menopause, it has been argued that a woman’s risk is
similar to a man’s although more recent data from the WHO and UN
disputes this. If a female has diabetes, she is more likely to develop heart
disease than a male with diabetes.

3. Angina (Chest Pain): Angina is chest pain or discomfort caused when


your heart muscle doesn’t get enough oxygen-rich blood. It may feel like
pressure or squeezing in your chest. The discomfort also can occur in
your shoulders, arms, neck, jaw, or back. Angina pain may even feel like
indigestion.

4. Resting Blood Pressure: Over time, high blood pressure can damage
arteries that feed your heart. High blood pressure that occurs with other
conditions, such as obesity, high cholesterol or diabetes, increases your
risk even more.

5. Serum Cholesterol: A high level of low-density lipoprotein (LDL)


cholesterol (the “bad” cholesterol) is most likely to narrow arteries. A
high level of triglycerides, a type of blood fat related to your diet, also
ups your risk of a heart attack. However, a high level of high-density
lipoprotein (HDL) cholesterol (the “good” cholesterol) lowers your risk of
a heart attack.

6. Fasting Blood Sugar: Not producing enough of a hormone secreted by


your pancreas (insulin) or not responding to insulin properly causes your
body’s blood sugar levels to rise, increasing your risk of a heart attack.

7. Resting ECG: For people at low risk of cardiovascular disease, the


USPSTF concludes with moderate certainty that the potential harms of
screening with resting or exercise ECG equal or exceed the potential
benefits. For people at intermediate to high risk, current evidence is
insufficient to assess the balance of benefits and harms of screening.

8. Max heart rate achieved: The increase in cardiovascular risk,


associated with the acceleration of heart rate, was comparable to the
increase in risk observed with high blood pressure. It has been shown
that an increase in heart rate by 10 beats per minute was associated
with an increase in the risk of cardiac death by at least 20%, and this
increase in the risk is similar to the one observed with an increase in
systolic blood pressure by 10 mm Hg.

9. Exercise induced angina: The pain or discomfort associated with


angina usually feels tight, gripping or squeezing, and can vary from mild
to severe. Angina is usually felt in the center of your chest but may
spread to either or both of your shoulders, or your back, neck, jaw or
arm. It can even be felt in your hands. o Types of Angina a. Stable
Angina / Angina Pectoris b. Unstable Angina c. Variant (Prinzmetal)
Angina d. Microvascular Angina.

10. Peak exercise ST segment: A treadmill ECG stress test is considered


abnormal when there is a horizontal or down-sloping ST-segment
depression ≥ 1 mm at 60–80 ms after the J point. Exercise ECGs with up-
sloping ST-segment depressions are typically reported as an ‘equivocal’
test. In general, the occurrence of horizontal or down-sloping ST-
segment depression at a lower workload (calculated in METs) or heart
rate indicates a worse prognosis and higher likelihood of multi-vessel
disease. The duration of ST-segment depression is also important, as
prolonged recovery after peak stress is consistent with a positive
treadmill ECG stress test. Another finding that is highly indicative of
significant CAD is the occurrence of ST-segment elevation > 1 mm (often
suggesting transmural ischemia); these patients are frequently referred
urgently for coronary angiography.
The Approach

The code is implemented in Python and different classification models are


applied.

In this article I will be using the following classification models for


classification :

 SVM

 Naive Bayes

 Logistic Regression

 Decision Tree

 Random Forest

 LightGBM

 XGboost

Data Analysis

Let us look at the people’s age who are suffering from the disease or not.
Here, target = 1 implies that the person is suffering from heart disease and
target = 0 implies the person is not suffering.
We see that most people who are suffering are of the age of 58, followed by
57.
Majorly, people belonging to the age group 50+ are suffering from the
disease.

Next, let us look at the distribution of age and gender for each target class.

We see that for females who are suffering from the disease are older than
males.
Data Pre-Processing

The dataset contains 14 columns and 303 rows.


Let us check the null values

null values in each column of the data

We see that there are only 6 cells with null values with 4 belonging to
attribute ca and 2 to thal.
As the null values are very less we can either drop them or impute them. I
have imputed the mean in place of the null values however one can also
delete these rows entirely.

Now let us divide the data in the test and train set.
In this project, I have divided the data into an 80: 20 ratio. That is, the
training size is 80% and testing size is 20% of the whole data.

Training

All the models discussed above are applied to get the results.
The evaluation metric used is the confusion matrix.

confusion matrix

The confusion matrix displays the correctly predicted as well as incorrectly


predicted values by a classifier.
The sum of TP and TN, from the confusion matrix, is the number of correctly
classified entries by the classifier.

SVM
Accuracy for SVM for training set = ((124+100)/(5+13+124+100))*100 =
92.51%
Accuracy for SVM for test set = 80.32%

Similarly let us look at all the confusion matrices for each classifier.

Naive Bayes

Logistic Regression
Decision Tree

Random Forest

LightGBM
XGBoost

To sum up, here are all the accuracies at once for all the classifiers.
We see that the highest accuracy for the test set is achieved by Logistic
Regression and SVM which is equal to 80.32%.
The highest accuracy for the training set is 100% achieved by Decision Tree.

The algorithms are implemented with the default parameters only.

Methodology
The dataset used for this research purpose was the Public Health Dataset
and it is dating from 1988 and consists of four databases: Cleveland,
Hungary, Switzerland, and Long Beach V. It contains 76 attributes,
including the predicted attribute, but all published experiments refer to
using a subset of 14 of them. The “target” field refers to the presence of
heart disease in the patient. It is integer-valued 0 = no disease and 1 =
disease. The first four rows and all the dataset features are shown in
Table without any preprocessing. Now the attributes which are used in
this research purpose are described as follows and for what they are used
or resemble:

Age—age of patient in years, sex—(1 = male; 0 = female).


Cp—chest pain type.
Trestbps—resting blood pressure (in mm Hg on admission to the hospital).
The normal range is 120/80 (if you have a normal blood pressure reading,
it is fine, but if it is a little higher than it should be, you should try to lower
it. Make healthy changes to your lifestyle).
Chol—serum cholesterol shows the amount of triglycerides present.
Triglycerides are another lipid that can be measured in the blood. It
should be less than 170 mg/dL (may differ in different Labs).
Fbs—fasting blood sugar larger than 120 mg/dl (1 true). Less than 100
mg/dL (5.6 mmol/L) is normal, and 100 to 125 mg/dL (5.6 to 6.9 mmol/L) is
considered prediabetes.
Restecg—resting electrocardiographic results.
Thalach—maximum heart rate achieved. The maximum heart rate is 220
minus your age.
Exang—exercise-induced angina (1 yes). Angina is a type of chest pain
caused by reduced blood flow to the heart. Angina is a symptom of
coronary artery disease.
Oldpeak—ST depression induced by exercise relative to rest.
Slope—the slope of the peak exercise ST segment.
Ca—number of major vessels (0–3) colored by fluoroscopy.
Thal—no explanation provided, but probably thalassemia (3 normal; 6
fixed defects; 7 reversible defects).
Target (T)—no disease = 0 and disease = 1, (angiographic disease status).

Preprocessing of the Dataset

The dataset does not have any null values. But many outliers needed to
be handled properly, and also the dataset is not properly distributed. Two
approaches were used. One without outliers and feature selection process
and directly applying the data to the machine learning algorithms, and
the results which were achieved were not promising. But after using the
normal distribution of dataset for overcoming the overfitting problem and
then applying Isolation Forest for the outlier’s detection, the results
achieved are quite promising. Various plotting techniques were used for
checking the skewness of the data, outlier detection, and the distribution
of the data. All these preprocessing techniques play an important role
when passing the data for classification or prediction purposes.

Checking the Distribution of the Data


The distribution of the data plays an important role when the prediction or
classification of a problem is to be done. We see that the heart disease
occurred 54.46% of the time in the dataset, whilst 45.54% was the no
heart disease. So, we need to balance the dataset or otherwise it might
get overfit. This will help the model to find a pattern in the dataset that
contributes to heart disease

Checking the Skewness of the Data


For checking the attribute values and determining the skewness of the
data (the asymmetry of a distribution), many distribution plots are plotted
so that some interpretation of the data can be seen. Different plots are
shown, so an overview of the data could be analyzed. The distribution of
age and sex, the distribution of chest pain and trestbps, the distribution of
cholesterol and fasting blood, the distribution of ecg resting electrode and
thalach, the distribution of exang and oldpeak, the distribution of slope
and ca, and the distribution of thal and target all are analyzed and the
conclusion is drawn as shown in Figures
By analyzing the distribution plots, it is visible that thal and fasting blood
sugar is not uniformly distributed and they needed to be handled;
otherwise, it will result in overfitting or underfitting of the data.

Checking Stats of the Normal Distribution of Data


Checking the features which are important for heart disease and not
important for heart disease is shown in Figures
Feature Selection
For selecting the features and only choosing the important feature, the
Lasso algorithm is used which is a part of embedded methods while
performing feature selection. It shows better predictive accuracy than
filter methods. It renders good feature subsets for the used algorithm.
And then for selecting the selected features, select from the model which
is a part of feature selection in the scikit-learn library.

Checking Duplicate Values in the Data


The duplicates should be tackled down safely or otherwise would affect
the generalization of the model. There might be a chance if duplicates are
not dealt with properly; they might show up in the test dataset which is
also in the training dataset.

Machine Learning Classifiers Proposed

The proposed approach was applied to the dataset in which firstly the
dataset was properly analyzed and then different machine learning
algorithms consisting of linear model selection in which Logistic
Regression was used. For focusing on neighbor selection technique
KNeighborsClassifier was used, then tree-based technique like
DecisionTreeClassifier was used, and then a very popular and most
popular technique of ensemble methods RandomForestClassifier was
used. Also for checking the high dimensionality of the data and handling
it, Support Vector Machine was used. Another approach which also works
on ensemble method and Decision Tree method combination is XGBoost
classifier
Deep Learning Pseudocode

Dataset of training
Dataset of testing
Checking the shape/features of the input
The procedure of initiating the sequential layer
Adding dense layers with dropout layers and ReLU activation functions
Adding a last dense layer with one output and binary activation function
End repeat
L (output)
End procedure

Deep Learning Proposed

There are two ways a deep learning approach can be applied. One is
using a sequential model and another is a functional deep learning
approach. In this particular research, the first one is used. A sequential
model with a fully connected dense layer is used, with the flatten and
dropout layers to prevent the overfitting and the results are compared of
the machine learning and deep learning and variations in the learning
including computational time and accuracy can be analyzed and can be
seen in the figures further discussed in the Results section.

Evaluation Process Used

For the evaluation process, confusion matrix, accuracy score, precision,


recall, sensitivity, and F1 score are used. A confusion matrix is a table-like
structure in which there are true values and predicted values, called true
positive and true negative. It is defined in four parts: the first one is true
positive (TP) in which the values are identified as true and, in reality, it
was true also. The second one is false positive (FP) in which the values
identified are false but are identified as true. The third one is false
negative (FN) in which the value was true but was identified as negative.
The fourth one is true negative (TN) in which the value was negative and
was truly identified as negative
CHAPTER 2:
Literature review

In recent years, the healthcare industry has seen a significant advancement in the
field of data mining and machine learning. These techniques have been widely adopted
and have demonstrated efficacy in various healthcare applications, particularly in the
field of medical cardiology. The rapid accumulation of medical data has presented
researchers with an unprecedented opportunity to develop and test new algorithms in
this field. Heart disease remains a leading cause of mortality in developing nations, and
identifying risk factors and early signs of the disease has become an important area of
research. The utilization of data mining and machine learning techniques in this field
can potentially aid in the early detection and prevention of heart disease.

The purpose of the study described by Narain et al. (2016) is to create an


innovative machine-learning-based cardiovascular disease (CVD) prediction system in
order to increase the precision of the widely used Framingham risk score (FRS). With
the help of data from 689 individuals who had symptoms of CVD and a validation
dataset from the Framingham research, the proposed system—which uses a quantum
neural network to learn and recognize patterns of CVD—was experimentally validated
and compared with the FRS. The suggested system’s accuracy in forecasting CVD risk
was determined to be 98.57%, which is much greater than the FRS’s accuracy of
19.22% and other existing techniques. According to the study’s findings, the suggested
approach could be a useful tool for doctors in forecasting CVD risk, assisting in the
creation of better treatment plans, and facilitating early diagnosis.

In a study conducted by Shah et al. (2020), the authors aimed to develop a model
for predicting cardiovascular disease using machine learning techniques. The data used
for this purpose were obtained from the Cleveland heart disease dataset, which
consisted of 303 instances and 17 attributes, and were sourced from the UCI machine
learning repository. The authors employed a variety of supervised classification
methods, including naive Bayes, decision tree, random forest, and k-nearest neighbor
(KKN). The results of the study indicated that the KKN model exhibited the highest level
of accuracy, at 90.8%. The study highlights the potential utility of machine learning
techniques in predicting cardiovascular disease, and emphasizes the importance of
selecting appropriate models and techniques to achieve optimal results.

In a study by Drod et al. (2022), the objective was to use machine learning (ML)
techniques to identify the most significant risk variables for cardiovascular disease
(CVD) in patients with metabolic-associated fatty liver disease (MAFLD). Blood
biochemical analysis and subclinical atherosclerosis assessment were performed on
191 MAFLD patients. A model to identify those with the highest risk of CVD was built
using ML approaches, such as multiple logistic regression classifier, univariate feature
ranking, and principal component analysis (PCA). According to the study,
hypercholesterolemia, plaque scores, and duration of diabetes were the most crucial
clinical characteristics. The ML technique performed well, correctly identifying 40/47
(85.11%) high-risk patients and 114/144 (79.17%) low-risk patients with an AUC of 0.87.
According to the study’s findings, an ML method is useful for detecting MAFLD patients
with widespread CVD based on simple patient criteria.

In a study published by Alotalibi (2019), the author aimed to investigate the utility of
machine learning (ML) techniques for predicting heart failure disease. The study utilized
a dataset from the Cleveland Clinic Foundation, and implemented various ML
algorithms, such as decision tree, logistic regression, random forest, naive Bayes, and
support vector machine (SVM), to develop prediction models. A 10-fold cross-validation
approach was employed during the model development process. The results indicated
that the decision tree algorithm achieved the highest accuracy in predicting heart
disease, with a rate of 93.19%, followed by the SVM algorithm at 92.30%. This study
provides insight into the potential of ML techniques as an effective tool for predicting
heart failure disease and highlights the decision tree algorithm as a potential option for
future research.

Through a comparison of multiple algorithms, Hasan and Bao (2020) carried out a
study with the main objective of identifying the most efficient feature selection approach
for anticipating cardiovascular illness. The three well-known feature selection methods
(filter, wrapper, and embedding) were first taken into account, and then a feature subset
was recovered from these three algorithms using a Boolean process-based common
“True” condition. This technique involved retrieving feature subsets in two stages. A
number of models, including random forest, support vector classifier, k-nearest
neighbors, naive Bayes, and XGBoost, were taken into account in order to justify the
comparative accuracy and identify the best predictive analytics. As a standard for
comparison with all features, the artificial neural network (ANN) was used. The findings
demonstrated that the most accurate prediction results for cardiovascular illness were
provided by the XGBoost classifier coupled with the wrapper technique. XGBoost
delivered an accuracy of 73.74%, followed by SVC with 73.18% and ANN with 73.20%.

The primary drawback of the prior research is its limited dataset, resulting in a high
risk of overfitting. The models developed may not be appropriate for large datasets. In
contrast, we utilized a cardiovascular disease dataset consisting of 70,000 patients and
11 features, thereby reducing the chance of overfitting presents a concise review of
cardiovascular disease prediction studies performed on large datasets, further
reinforcing the effectiveness of using a substantial dataset.

Methodology

This study aims to predict the probability of heart disease through computerized
heart disease prediction, which can be beneficial for medical professionals and
patients. To achieve this objective, we employed various machine learning
algorithms on a dataset and present the results in this study report. To enhance the
methodology, we plan to clean the data, eliminate irrelevant information, and
incorporate additional features such as MAP and BMI. Next, we will separate the
dataset based on gender and implement k-modes clustering. Finally, we will train the
model with the processed data. The improved methodology will produce more
accurate results and superior model performance,
Clustering
Clustering is a machine learning technique where a group of instances is grouped
based on similarity measures. One common algorithm used for clustering is the k-
means algorithm, but it is not effective when working with categorical data. To overcome
this limitation, the k-modes algorithm was developed. The k-modes algorithm,
introduced by Huang in 1997, is similar to the k-means algorithm but utilizes dissimilarity
measures for categorical data and replaces the means of the clusters with modes. This
allows the algorithm to work effectively with categorical data.

Since our data have been converted to categorical data, we will use k-modes
analysis. To find the optimal number of clusters, we will first use the elbow curve with
Huang initialization. An elbow curve creates a k-modes model with that number of
clusters, fits the model to the data, and then calculates the cost (distance between the
attribute modes of each cluster and the data points assigned to the cluster). The costs
are then plotted on a graph using the “elbow method” to determine the optimal number
of clusters. The elbow method looks for a “knee” or inflection point in the plot of costs,
which is often interpreted as the point where the addition of more clusters is not
significantly improving the fit of the model.

Splitting the dataset on the basis of gender can be advantageous for prediction due
to the existence of significant biological disparities between men and women that can
impact the manifestation and progression of diseases. For instance, men tend to
develop heart disease at an earlier age than women, and their symptoms and risk
factors may differ. Studies have shown that men have a higher risk of coronary artery
disease (CAD) compared with women, and that the CAD risk factors and presentations
may differ between the sexes. By analyzing the data separately for men and women, it
is possible to identify unique risk factors and patterns of disease progression that may
not be discernible when the data are consolidated. Additionally, heart disease has a
varying prevalence rate among men and women.

Subsequently, we utilized the elbow curve method to determine the optimal number
of clusters for both the male and female datasets. the knee point was located at 2.0 in
both cases, indicating that 2 was the optimal number of clusters for both the male and
female datasets.

Correlation Table
Further, a correlation table is prepared to determine the correlation between different
categories. mean arterial pressure (MAP_Class), cholesterol, and age were highly
correlated factors. Intra-feature dependency can also be looked upon with the help
of this matrix.
Modeling
A training dataset (80%) and a testing dataset (20%) are created from the dataset. A
model is trained using the training dataset, and its performance is assessed using
the testing dataset. Different classifiers, such as decision tree classifier, random
forest classifier, multilayer perceptron, and XGBoost, are applied to the clustered
dataset to assess their performance. The performance of each classifier is then
evaluated using accuracy, precision, recall, and F-measure scores.

Decision Tree Classifier


Decision trees are treelike structures that are used to manage large datasets. They
are often depicted as flowcharts, with outer branches representing the results and
inner nodes representing the properties of the dataset. Decision trees are popular
because they are efficient, reliable, and easy to understand. The projected class
label for a decision tree originates from the tree’s root. The following steps in the tree
are decided by comparing the value of the root attribute with the information in the
record. Following a jump on the next node, the matching branch is followed to the
value shown by the comparison result. Entropy changes when training examples are
divided into smaller groups using a decision tree node. The measurement of this
change in entropy is information gain.
An accuracy of 73.0% has been achieved by the decision tree. In a research by,
72.77% accuracy was achieved by the decision tree classifier.

Random Forest
The random forest algorithm belongs to a category of supervised classification
technique that consists of multiple decision trees working together as a group. The
class with the most votes become the prediction made by our model. Each tree in
the random forest makes a class prediction, which eliminates the limitations of the
decision tree algorithm. This improves accuracy and reduces overfitting of the
dataset. When used on large datasets, the random forest approach may still provide
the same results even if a significant portion of record values are missing. The
samples produced by the decision tree may be saved and used with various data
types. In the research in, random forest achieved a test accuracy of 73% and a
validation accuracy of 72% with 500 estimators, 4 maximum depths, and 1 random
state.

Multilayer Perceptron
The multilayer perceptron (MLP) is a type of artificial neural network that consists of
multiple layers. Single perceptron can only solve linear problems, but MLP is better
suited for nonlinear examples. MLP is used to tackle complex issues. A feedforward
neural network with many layers is an example of an MLP.

Other activation functions beyond the step function are usually used by MLP. The
buried layer neurons often perform sigmoid functions. As with step functions, smooth
transitions rather than rigid decision limits are produced using sigmoid functions. In
MLPs, learning also comprises adjusting the perceptron’s weights to obtain the lowest
possible error. This is accomplished via the backpropagation technique, which reduces
the MSE.

XGBoost
XGBoost is a version of gradient boosted decision trees. This algorithm involves
creating decision trees in a sequential manner. All the independent variables are
allocated weights, which are subsequently used to produce predictions by the
decision tree. If the tree makes a wrong prediction, the importance of the relevant
variables is increased and used in the next decision tree. The output of each of
these classifiers/predictors is then merged to produce a more robust and accurate
model. In a study by, the XGBoost model achieved 73% accuracy with the
parameters ‘learning_rate’: 0.1, ‘max_depth’: 4, ‘n_estimators’: 100, ‘cross-
validation’: 10 folds including 49,000 training and 21,000 testing data instances on
70,000 CVD dataset.

2.1 Existing and Proposed System


EXISTING SYSTEM
Heart disease is even being highlighted as a silent killer which leads to the death of a person
without obvious symptoms. The nature of the disease is the cause of growing anxiety about
the disease & its consequences. Hence continued efforts are being done to predict the
possibility of this deadly disease in prior. So that various tools & techniques are regularly
being experimented with to suit the present-day health needs. Machine Learning
techniques can be a boon in this regard. Even though heart disease can occur in different
forms, there is a common set of core risk factors that influence whether someone will
ultimately be at risk for heart disease or not. By collecting the data from various sources,
classifying them under suitable headings & finally analyzing to extract the desired data we
can conclude. This technique can be very well adapted to the do the prediction of heart
disease. As the well-known quote says “Prevention is better than cure”, early prediction &
its control can be helpful to prevent & decrease the death rates due to heart disease.

PROPOSED SYSTEM
The working of the system starts with the collection of data and selecting the important
attributes. Then the required data is preprocessed into the required format. The data is
then divided into two parts training and testing data. The algorithms are applied and the
model is trained using the training data. The accuracy of the system is obtained by testing
the system using the testing data. This system is implemented using the following modules.
1) Collection of Dataset
2) Selection of attributes
3) Data Pre-Processing
4) Balancing of Data
5) Disease Prediction

2.2 Tools and Technologies used


2.2.1 Tools used:
PyCharm
PyCharm is an integrated development environment (IDE) used for programming in Python.
It provides code analysis, a graphical debugger, an integrated unit tester, integration with
version control systems, and supports web development with Django. PyCharm is
developed by the Czech company JetBrains.

It is cross-platform, working on Microsoft Windows, macOS and Linux. PyCharm has a


Professional Edition, released under a proprietary license and a Community Edition released
under the Apache License. PyCharm Community Edition is less extensive than the
Professional Edition.

PyCharm was released to the market of the Python-focused IDEs to compete with PyDev
(for Eclipse) or the more broadly focused Komodo IDE by ActiveState.

The beta version of the product was released in July 2010, with the 1.0 arriving 3 months
later. Version 2.0 was released on 13 December 2011, version 3.0 was released on 24
September 2013, and version 4.0 was released on November 19, 2014.

PyCharm became Open Source on 22 October 2013. The Open Source variant is released
under the name Community Edition – while the commercial variant, Professional Edition,
contains closed-source modules

Libraries used:
Pandas:
Pandas is a software library written for the Python programming language for data
manipulation and analysis. In particular, it offers data structures and operations for
manipulating numerical tables and time series. It is free software released under the three
clause. The name is derived from the term "data”, an econometrics term for data sets that
include observations over multiple time periods for the same individuals. Its name is a play
on the phrase "Python data analysis" itself.

NumPy:
NumPy is a library for the Python programming language, adding support for large,
multidimensional arrays and matrices, along with a large collection of high level
mathematical functions to operate on these arrays. The ancestor of NumPy, Numeric, was
originally created by Jim Hugunin with contributions from several other developers. In 2005,
Travis Oliphant created NumPy by incorporating features of the competing Numarray into
Numeric, with extensive modifications. NumPy is open-source software and has many
contributors.

Seaborn:
Seaborn is an open-source Python library built on top of matplotlib. It is used for data
visualization and exploratory data analysis. Seaborn works easily with data frames and the
Pandas library. The graphs created can also be customized easily

Below are a few benefits of Data Visualization.


Graphs can help us find data trends that are useful in any machine learning or forecasting
project.
• Graphs make it easier to explain your data to non-technical people.
• Visually attractive graphs can make presentations and reports much more appealing to
the reader.

Matplotlib:
Matplotlib is a cross-platform, data visualization and graphical plotting library for Python
and its numerical extension NumPy. As such, it offers a viable open source alternative to
MATLAB. Developers can also use matplotlib's APIs (Application Programming Interfaces) to
embed plots in GUI applications.
A Python matplotlib script is structured so that a few lines of code are all that is required in
most instances to generate a visual data plot. The matplotlib scripting layer overlays two
APIs:

The pyplot API is a hierarchy of Python code objects topped by [Link] An OO


(Object-Oriented) API collection of objects that can be assembled with greater flexibility
than pyplot. This API provides direct access to Matplotlib’s backend layers.

2.2.2 Technologies used


Python is an interpreted high-level general-purpose programming language. Python's design
philosophy emphasizes code readability with its notable use of significant indentation. Its
language constructs as well as its object-oriented approach aim to help programmers write
clear, logical code for small and large-scale projects.
• Python is a general-purpose programming language hence, python-based projects are
used for developing both desktop and web applications. Nevon Projects possesses a wide
list of python programming projects ideas for beginners, engineers, students and
researches. Python is dynamically-typed and garbage-collected. It supports multiple
programming paradigms, including structured (particularly, procedural), object-oriented
and functional programming. Python is often described as a "batteries included" language
due to its comprehensive standard library
Machine learning is the study of computer algorithms that improve automatically through
experience and by the use of data. It is seen as a part of artificial intelligence. Machine
learning algorithms build a model based on sample data, known as "training data", in order
to make predictions or decisions without being explicitly programmed to do so. Machine
learning algorithms are used in a wide variety of applications, such as in medicine, email
filtering, and computer vision, where it is difficult or unfeasible to develop conventional
algorithms to perform the needed tasks.
Hardware and Software Requirements

REQUIREMENT ANALYSIS

HARDWARE REQUIREMENTS

 Hardware :Processor Intel dual core and above


 Clock speed :3.0 GHz
 RAM size :512 MB
 Hard Disk capacity :400 GB
 Monitor type :15 inch color monitor

SOFTWARE REQUIREMENTS

 Operating System :Windows XP, Windows 7, Windows


8,Windows 10
 Application :HTML, CSS, JS, Python, Flask
 Browser :Google chrome, Firefox
 Database :MySQL.
 Documentation :MS-Office

3.2 Algorithms used


K Nearest Neighbors or KNN Algorithm is a simple algorithm which uses the entire dataset
in its training phase. Whenever a prediction is required for an unseen data instance, it
searches through the entire training dataset for k-most similar instances and the data with
the most similar instance is finally returned as the prediction. KNN is often used in search
applications where you are looking for similar items, like find items similar to this one.
Logistic regression is a statistical model that in its basic form uses a logistic function to
model a binary dependent variable, although many more complex extensions exist. In
regression analysis, logistic regression is estimating the parameters of a logistic model (a
form of binary regression). Mathematically, a binary logistic model has a dependent variable
with two possible values, such as pass/fail which is represented by an indicator variable,
where the two values are labelled “0” and “1”

Linear Regression is one of the supervised Machine learning algorithms in Python that
observes continuous features and predicts an outcome. Depending on whether it runs on a
single variable or on many features, we can call it simple linear regression or multiple linear
regression. This is one of the most popular Python ML algorithms and often under-
appreciated. It assigns optimal weights to variables to create a line ax+b to predict the
output. We often use linear regression to estimate real values like a number of calls and
costs of houses based on continuous variables. The regression line is the best line that fits
Y=a*X+b to denote a relationship between independent and dependent variables

A Decision tree falls under supervised Machine Learning Algorithms in Python and comes of
use for both classification and regression- although mostly for classification. This model
takes an instance, traverses the tree, and compares important features with a determined
conditional statement. Whether it descends to the left child branch or the right depends on
the result. Usually, more important features are closer to the root. Decision Tree, a Machine
Learning algorithm in Python can work on both categorical and continuous dependent
variables. Here, we split a Machine Learning with Python Department of ISE, SCE 2020-2021
Page 14 population into two or more homogeneous sets. Tree models where the target
variable can take a discrete set of values are called classification trees; in these tree
structures, leaves represent class labels and branches represent conjunctions of features
that lead to those class labels. Decision trees where the target variable can take continuous
values (typically real numbers) are called regression trees

In the field of machine learning and specifically the problem of statistical classification, a
confusion matrix, also known as an error matrix, is a specific table layout that allows
visualization of the performance of an algorithm.
OpenCV is a huge open-source library for computer vision, machine learning, and image
processing. OpenCV supports a wide variety of programming languages like Python, C++,
Java, etc. It can process images and videos to identify objects, faces, or even the
handwriting of a human.

3.3 Non-Functional Requirements


Non-Functional Requirements provides criteria that are used to decide the operations of the
system. The following are the non-functional requirement:
1. Scalability: The proposed system can extend to various density of human crowd.
2. Reliability: Our proposed system is reliable. There will be no false data and lesser loss of
information as it ensures increased data utility.
3. Flexibility: The proposed system is more flexible to the user as it uses simple techniques
and also less complexity so that everyone can understand easily.
4. Performance: Our proposed system accurately classifies the abnormal human activity
than the legacy system.
Cost: Lesser cost compare to existing technique

Chapter 4: Implementation
4.1 Implementation
Here are the steps to build an application in Python that can detect heart disease:
The project folder contains 2 files:
• heart_disease_prediction.ipynb – main source code of our project.
• [Link] – a file that contains our dataset.

The Dataset To predict Whether a person has heart disease or not, we are using the dataset
called [Link] in which contains 1026 rows. This dataset contains some attributes, they
are Age, Sex, cp, trestbp, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal, target.
Using this dataset, we are going to predict the heart disease of a person.

Machine learning research methods

In the digital world, electronic health records have taken over to gather health data
digitally which made it easier to collect data and allowed for data to become cheaper
and more accessible in terms of availability. However, along with the easy availability of
the data, there is also the issue of unstructured data which contains a lot of issues
including redundancy, noise, heterogeneity, and diversity in scale.

Health care and diseases comprise of different outcomes including binary i.e., 0 or 1
which means 0 as ‘death’ or any other events, and 1 as continuous outcomes i.e.,
staying duration. Other outcomes include ordinal ones such as tumor grading, life
quality, survival outcomes i.e., any clinical trials or survival from cancer, etc.

ML provides versatility in analyzing these data and providing some more precise results.
Highlights

 - ML is an effective way to optimize the prediction of heart disease and the related
effects.
 - A good understanding of the required parameters for the diagnosis of the disease can
be highly helpful in making precise and accurate predictions.
 - Cardiovascular (CV) disease research and treatment coupled with some high-
performance tools for analysis can improve the knowledge about the domain.

Literature survey

A thorough search has been done of the previous work on the domain of the heart
disease using different algorithms. The previous 21 years of work has been
considered for study and their shortcomings are noted down to further extend our
research. A total of 50 papers from Web of science, Science direct, and Scopus
were collected from which 27 were selected for final study after removal of
duplicates and same domain-based papers.

Search Strategy

The literature survey has been started from January 1, 2021 until December 31,
2021 from Scopus, Web of Science, and Science Direct and thorough analysis has
been performed on the collected papers. The analysis is done to understand the
challenges in the field of heart disease prediction. Collected papers were studied
and pros and cons of the work were being observed on the basis of the evaluation
parameters, methodology, and utilization of algorithms.
The inclusion criteria was based on identifying the papers which are of related
domain, utilization of latest machine learning algorithms, challenging area in domain
of heart disease. Search terms for identifying papers are “machine learning based
health disease prediction”, “optimization of Health disease prediction”, “Challenges
in identifying health disease”. The exclusion criteria included removing duplicate
papers, papers which presented inferior work in terms of evaluation parameter
values, and obsolete work.

In one study, an electronic health record (ehr) model based on sequential modeling
was designed with the utilization of a neural network. The EHR was applied for
experiment conduction and predicting of heart disease. Researchers in this work
used word vectors and hot encryption for modeling diagnostic situations and
predicting cardiac failure. Along with the same approach, an extended memory
model based on the network was utilized. The work stated that it is very necessary
for taking care of the sequential character of healthcare with the help of results
analysis. The sequential character of healthcare includes tracking of a behavior of
person like his/her health-based activities, change in healthcare providers during
sickness, exercise routine, diet routine etc.

The artificial neural network (ANN), random forest, K-Nearest Neighbor (KNN), and
support vector machine techniques were used in another work. It stated that ANN
produced the highest accuracy for heart disease predictions compared to the earlier
classification algorithms. The work presented highly efficient results in terms of
accuracy and other evaluation measures included in the study.
Another work stated that PCA as a dimensionality reduction technique can be
utilized to deal with data having high dimensions and variance. More information can
be stored utilizing this approach in new components. When working with data with
high dimensionality, many researchers choose to employ PCA. Five unsupervised
(linear and nonlinear) dimensionality reduction techniques were utilized, as well as
NN as a classifier, to classify cardiac arrhythmia. With a minimum of 10 components,
an F1 score of 99.83% was achieved with fast independent component analysis
(FastICA) which was used for the ICA for breast cancer diagnosis.

Another researcher employed the AdaBoost algorithm, based on PCA. A combination of


uncorrelated discriminant analysis and PCA was applied to select the optimal features
for controlling upper limb motions.
Using PCA approaches to time-frequency representations, another researcher
attempted to minimize heart sounds to improve performance. A scale-invariant feature,
Principle Component Analysis-K-Nearest Neighbor (PCA-KNN), was used in medical
pictures for scaling to develop a new approach for diverse medical images that
achieved an 83.6% accuracy with 200 images used for training the machine. A gray-
level threshold of 150 was utilized as a result of PCA and Return on Investment (ROI),
all of which were used to reduce X-ray picture characteristics.

Diabetics are more likely to suffer from cardiovascular (CV)disease. In determining CV


risk-assessment methods, both fasting glucose levels and glycosylated hemoglobin
have been used. The evidence that these components are being used is inconclusive.
According to the cardiovascular heart study, the relationship between fasting blood
glucose and CV risk is relatively weakly associated. Similarly, multiple studies were
done by other researchers which have shown a correlation between glycosylated
hemoglobin and CV risk, as well as postprandial glucose levels.

Because of our genetic diversity, cultures, dietary habits, and social and behavioral
features, available risk-assessment measures are not universal. In a review of the
worldwide burden of CV illness, researchers discovered that various populations have
varied disease burdens as well as different main Rheumatic fever (RFs) that contribute
to this burden. The Asia Pacific Cohort studies sought to compare the Asian and
Framingham cohorts in terms of risk factors and illness incidence and discovered that
the Framingham group had greater systolic blood pressure, total cholesterol, and CV
events, whereas the Asian cohort had higher smoking rates. There has been no
consensus on the risk-assessment tools to employ in Asian populations for risk
stratification. As a result, clinicians are perplexed and are unable to use risk
stratification to prioritize individuals for primary prevention strategies. So, it has been
stated that it will be beneficial to develop a predictive equation from the population-
based on gathered data on a contemporary and representative basis. The current
mixture of known and unknown RF based on genetic traits has been considered. As a
result, we must be aware of the limits of each of these risk-assessment techniques and
interpret the results with caution.
Another work presented on different ML classifiers on which later comparative analysis
is also performed. This work was performed on data mining approaches like Sequential
minimal optimization (SMO), naïve Bayes, and J48 decision trees.

The maximum accuracy has been achieved with SMO with 89%. The J48 decision tree
experiment provided an accuracy of 86% and naïve bayes classifier gave an accuracy
of 87%.

Methods

Study design

Each step of this study is outlined below. Exploratory data analysis (EDA) is used for
mistake detection, finding appropriate data, and checking the relationship between
variables of exploratory analysis. In this work the heart disease-based risk factors
are taken into consideration and ultimately the prediction of the heart attack. The ML
classifiers utilized for the work are logistic regression, support vector machines,
naïve Bayes, and XGBoost. A detailed literature survey has been performed
considering the previous experiments conducted to predict the heart disease and the
classifiers SVM, Logistic Regression, Naïve Bayes, and XGBoost are taken into
consideration on the basis of their performance attributes. The experiment is carried
out on a Cleveland dataset which contains 294 tuples having 14 attributes

1. The first step is gathering data which is represented as ‘acquisition’. This included
evaluating physical conditions and considering the numeric data by converting the
samples which will be utilized by the computer to manipulate.

a. The data collected is taken from the UCI ML repository as outlined in the data
collection section, having multiple attributes to study the risk factors for heart disease.

b. All experiments in this study are performed on Python 3.8.3.

2. The second step is ‘pre-processing’ where we tackled issues in the data such as
missing values, outlier detection, and redundancy removal to clean the dataset.
Predictive analysis has been performed for the uniform environment which also takes
the application towards EDA.

a. The collected data has been cleaned using pre-processing techniques including
missing values replacement, outlier detection, and duplicacy removal.

b. Missing values (if any) are being replaced with Mean values.

c. Outliers in the data has been detected using Boxplots by understanding minimum,
maximum, and interquartile ranges of data.

d. Duplicacy removal in the data was performed by using a function dict() for generating
dictionary to remove the duplicates.

3. The third step is ‘integration’ where libraries and different subsets were combined by
importing independent modules in python and merging them to perform necessary
experiments.

a. First part of the experiment was to have the preprocessed data.

b. The cleaned data was then integrated to apply ML algorithms.

4. The fourth step is ‘analysis’ where EDA was done to understand the relationship
between different attributes of data

a. Analysis works on the concept of learning from data, pattern identification and making
decisions with least intervention of human beings.

b. EDA is being utilized to understand the relationship between attributes.

c. Variable were compared to understand the correlation and the same variables were
analyzed using boxplots and heatmaps.

5. The fifth step was ‘intervention’ to get into the decision-making policies i.e., search
strategy for understanding previous experimental studies to determine when it becomes
efficient to utilize models for real-world problems effectively.
a. A detailed literature survey was done to know the utilization of ML models for the
same domain and to understand which are the most promising ones to optimize our
results. The most promising papers were selected on the basis of their performance in
previously implemented work in the similar domains for heart disease.

6. The sixth step was’application’ of ML algorithms in making the predictions. In this


work, four machine learning models were utilized i.e., SVM, Naïve Bayes, Logistic
Regression, and XGBoost.

a. SVM was applied on the data utilizing scikit learn with svm extension of python.

b. Naïve Bayes classifier is being applied by using Scikit learn library of neighbors in
python.

c. Logistic regression was utilized with linear model class of sklearn in python.

d. XGBoost is a boosting algorithm which utilizes weak classifications and provide


optimized results.

The work is conducted step wise starting from gathering the data. Pre-processing has
been done on the data to clean it including duplicacy removal, detection of Outliers, and
filling up missing values with mean. Then the four machine learning classifiers has been
applied i.e., Support Vector machines, Naïve Bayes, Logistic Regression and XGBoost
to further classify the outputs.

Data collection

The dataset utilized is composed of four parts or sub-databases i.e., Hungary,


Switzerland, Cleveland, and Long Beach which has 76 different attributes. In this work a
subset of 14 attributes is utilized because all the published experiments in the literature
review referred to these selected 14 attributes which helps to understand the major risk
factors of heart disease. This dataset is available online in UCI repository to be availed
freely for experimental purpose. The last column i.e., target value represents absence
or presence of disease in the patient represented by binary of O or 1 respectively.
The prediction is being performed on whole dataset and to present the attributes and
behavior of dataset, the sample of the data set (whole dataset is not presented because
of the size).

Exploration of dataset

The dataset contains attributes and integer values which are distributed in a file
([Link]) whose link is provides at the end of the paper in the section of data
availability. The behavioral and attributes information of the complete dataset. The
attributes of the dataset utilized (risk factors of heart attack) are discussed below:

 1. Age (age): This is a highly crucial risk factor for the occurrence of heart attacks
because the risk of getting heart attacks can double as age increases. In adults, the
fatty streaks indicative of coronary artery disease starts to develop and it is proven that
more than 80% cases of heart attacks due to coronary heart disease are in patients
aged 65 or above.
 2. Sex (sex): It has been proven that there is a higher risk of heart attack in men
compared to women aged 50 or less. After the menopause in women, there is a debate
of equal risk of heart attack in both men and women. The disease of diabetes in women
increases the risk of a heart attack.
 3. Chest pain (cp): This happens when the muscle of the heart doesn’t get enough
blood with oxygen and is called angina. The feeling of squeezing or high pressure builds
up in the chest and an uncomfortable feeling in shoulder, jaw, back, or neck can also
develop along with the feeling of indigestion in angina. The pain can be felt in the
hands. Different types of Angina include stable angina, pectoris, unstable angina,
prinzmetal angina, and microvascular angina.
 4. Blood pressure (trtbps): Arteries can be affected by high blood pressure. This can
occur because of different reasons like imbalanced cholesterol, high sugar, obesity etc.
which can enhance the risks.
 5. Cholesterol (chol): Arteries again can get affected due to imbalanced or bad
cholesterol. It narrows the arteries especially the low-density lipo-protein cholesterol.
Another cause is the blood fat i.e., triglycerides with high levels of cholesterol which can
also enhance the risk of heart attacks. So, it is advisable to maintain good cholesterol to
lower the risk of a heart attack.
 6. Fasting blood sugar (fbs): High blood sugar can become a cause of a heart attack. It
may happen due to lower hormone production by the pancreas or no response to insulin
in the body.
 7. Resting Electrocardiographic (restecg): For medium to high risk of heart attack, the
present scenario is not sufficient to understand the screening disadvantages. For those
having less risk of disease, the screening harmful effects including a rash or irritation on
skin can balance up with exercise.
 8. Heart rate (thalach): The increase in the heart rate with the enhanced risk of heart
disease is being parallelized with risk increment with blood pressure enhancement. It is
proven in research that if the heart rate increases by 10 bpm, then the chances of
cardiac death increase by 20%. This is also the same with the enhancement in the
blood pressure of 10 mm Hg.
 9. Angina (exng): The discomfort from Angina which is an Exercise-induced makes the
person feel gripped, squeezed and tight which can carry from mild to serious. The pain
is usually felt in the chest’s center and it can spread up in the shoulders, back, jaw, arm
or neck. Angina plays a crucial role in identifying coronary disease which makes it
worthwhile to consider it a separate category for analysis.
 10. Thalium Stress Test (thall): Duration of the segment is very important because it
needs to be checked that after peak stress, the recovery is happening constantly or not
with a positive treadmill test. The abnormal values come under the downslope of
depression with less than or equal to 1 mm with 60 to 80 ms. The equivocal tests i.e.,
with up-sloping segments are also there in the exercise.

Rest 4 attributes, oldpeak, slope, number of major vessels, and output are the numeric
values related to heart disease in the dataset and were not included in the 10 variables
of this study.
ML models

The study was completed with four ML models: XGBoost, support vector machines,
naïve Bayes, and logistic regression.

1. Logistic regression: One of the very popular algorithms is considered as


logistic regression which is a supervised learning model. It performs categorical
predictions which can be ‘true’ or ‘false’. This model provides probabilistic values
instead of exact ones. This algorithm works on both continuous and discrete
values. A simple S-Shaped curve can elaborate the logistic regression very
precisely.
2. Naïve Bayes: A bayes theorem based algorithm, Naïve Bayes is a supervised
learning model which works for fast predictions. It is a probabilistic classifier and
works very accurately on high dimensional data.
3. Support vector machines (SVM): It is a supervised learning model which works
on the concept of decision boundary or hyper plane. The aim of the algorithm is
to maximize the margin of the hyper planes which helps in minimizing the
misclassification problem. Model chooses extreme points to create the decision
boundary which are called as support vectors.
4. XGBoost: It is a decision tree classifier which has been implemented on
gradient boosting framework. This model works on the principle that weak
learners should be combined to produce best predictions. Ensembling is
performed in sequential manner.

Import libraries

I imported several libraries for the project:

1. numpy: To work with arrays

2. pandas: To work with csv files and dataframes


3. matplotlib: To create charts using pyplot, define parameters
using rcParams and color them with [Link]

4. warnings: To ignore all warnings which might be showing up in the


notebook due to past/future depreciation of a feature

5. train_test_split: To split the dataset into training and testing data

6. StandardScaler: To scale all the features, so that the Machine Learning


model better adapts to the dataset

Import dataset

After downloading the dataset from Kaggle, I saved it to my working


directory with the name [Link]. Next, I used read_csv() to read the
dataset and save it to the dataset variable.

Before any analysis, I just wanted to take a look at the data. So, I used
the info() method.

Understanding the data

Correlation Matrix

To begin with, let’s see the correlation matrix of features and try to analyse
it. The figure size is defined to 12 x 8 by using rcParams. Then, I used pyplot
to show the correlation matrix. Using xticks and yticks, I’ve added names
to the correlation matrix. colorbar() shows the colorbar for the matrix.
It’s easy to see that there is no single feature that has a very high
correlation with our target value. Also, some of the features have a negative
correlation with the target value and some have positive.

Histogram

The best part about this type of plot is that it just takes a single command to
draw the plots and it provides so much information in return. Just
use [Link]().
Let’s take a look at the plots. It shows how each feature and label is
distributed along different ranges, which further confirms the need for
scaling. Next, wherever you see discrete bars, it basically means that each of
these is actually a categorical variable. We will need to handle these
categorical variables before applying Machine Learning. Our target labels
have two classes, 0 for no disease and 1 for disease.

Bar Plot for Target Class

It’s really essential that the dataset we are working on should be


approximately balanced. An extremely imbalanced dataset can render the
whole model training useless and thus, will be of no use. Let’s understand it
with an example.
Let’s say we have a dataset of 100 people with 99 non-patients and 1
patient. Without even training and learning anything, the model can always
say that any new person would be a non-patient and have an accuracy of
99%. However, as we are more interested in identifying the 1 person who is
a patient, we need balanced datasets so that our model actually learns.

For x-axis I used the unique() values from the target column and then set
their name using xticks. For y-axis, I used value_count() to get the values
for each class. I colored the bars as green and red.

From the plot, we can see that the classes are almost balanced and we are
good to proceed with data processing.
Data Processing

To work with categorical variables, we should break each categorical


column into dummy columns with 1s and 0s.

Let’s say we have a column Gender, with values 1 for Male and 0 for Female.
It needs to be converted into two columns with the value 1 where the
column would be true and 0 where it will be false. Take a look at the Gist
below.

To get this done, we use the get_dummies() method from pandas. Next, we
need to scale the dataset for which we will use the StandardScaler.
The fit_transform() method of the scaler scales the data and we update
the columns.

Machine Learning

In this project, I took 4 algorithms and varied their various parameters and
compared the final models. I split the dataset into 67% training
data and 33% testing data.

K Neighbors Classifier

This classifier looks for the classes of K nearest neighbors of a given data
point and based on the majority class, it assigns a class to this data point.
However, the number of neighbors can be varied. I varied them from 1 to 20
neighbors and calculated the test score in each case.

Then, I plot a line graph of the number of neighbors and the test score
achieved in each case.
As you can see, we achieved the maximum score of 87% when the number of neighbors
was chosen to be 8.

Support Vector Classifier

This classifier aims at forming a hyperplane that can separate the classes as
much as possible by adjusting the distance between the data points and the
hyperplane. There are several kernels based on which the hyperplane is
decided. I tried four kernels namely, linear, poly, rbf, and sigmoid.

Once I had the scores for each, I used the rainbow method to select different
colors for each bar and plot a bar graph of the scores achieved by each.
As can be seen from the plot above, the linear kernel performed the best for this
dataset and achieved a score of 83%.

Decision Tree Classifier

This classifier creates a decision tree based on which, it assigns the class
values to each data point. Here, we can vary the maximum number of
features to be considered while creating the model. I range features from 1
to 30 (the total features in the dataset after dummy columns were added).
Once we have the scores, we can then plot a line graph and see the effect of
the number of features on the model scores.

Random Forest Classifier

This classifier takes the concept of decision trees to the next level. It creates
a forest of trees where each tree is formed by a random selection of features
from the total features. Here, we can vary the number of trees that will be
used to predict the class. I calculate test scores over 10, 100, 200, 500 and
1000 trees.

Next, I plot these scores across a bar graph to see which gave the best
results. You may notice that I did not directly set the X values as the
array [10, 100, 200, 500, 1000]. It will show a continuous plot from 10 to
1000, which would be impossible to decipher. So, to solve this issue, I first
used the X values as [1, 2, 3, 4, 5]. Then, I renamed them using xticks.

The project involved analysis of the heart disease patient dataset with
proper data processing. Then, 4 models were trained and tested with
maximum scores as follows:

1. K Neighbors Classifier: 87%

2. Support Vector Classifier: 83%

3. Decision Tree Classifier: 79%


4. Random Forest Classifier: 84%

Results

In this work, the evaluation of the performance metrices are being done with four
machine learning classifiers i.e., SVM, Naïve Bayes, XGBoost, and logistic regression.

In the work, maximum accuracy was achieved through XGBoost algorithm. Area under
the curve, precision, and recall are also evaluated to understand the performance of
algorithms.

Discussion

Some previous researchers proposed that the datasets should be small to deploy ML
classifiers, which has been proved in this work. Additionally, the computation time was
reduced, which is significant when the model has been deployed. The requirement for
the normalization of the dataset has also been felt during the work and the overfitting
can be there while training the model. Minimal accuracy has been achieved during
evaluation of the real world problem based data. The data can be normalized in a range
of methods, and the results can be compared. More techniques to connect heart-
disease trained ML models with specific multimedia for the convenience of patients and
clinicians could be discovered. The optimized results have been achieved in the
presented work and XGBoost provided best results when it came on to accuracy as 92
% and Area under the curve as 94%. Future work will be on optimizing the performance
of algorithms with hybrid approach for the prediction of heart disease.

Coding
[Link]
from datetime import datetime
from flask import Flask, request, render_template, session
import numpy as np
import pandas as pd
import DBClass
import os
from [Link] import RandomForestClassifier
TEMPLATE_DIR = [Link]('templates')
STATIC_DIR = [Link]('static')
#app = Flask(__name__, template_folder=TEMPLATE_DIR, static_folder=STATIC_DIR,
static_url_path="/")
app = Flask(__name__)
app.secret_key = 'SECRET KEY'
#Session(app)
@[Link]("/")
def index():
return render_template("[Link]")

@[Link]("/about")
def about():
return render_template("[Link]")

@[Link]("/adminmainpage")
def adminmainpage():
return render_template("[Link]")

@[Link]("/usermainpage")
def usermainpage():
return render_template("[Link]")
@[Link]("/logout")
def logout():
return render_template("[Link]")

@[Link]("/userviewprediction")
def userviewprediction():
return render_template("[Link]")

@[Link]("/adminlogin", methods=["POST","GET"])
def adminlogin():
msg = ''
if ([Link] == "POST"):
pwd = [Link]["pwd"]
uname = [Link]["uname"]
if(uname=="admin" and pwd=="admin"):
return render_template("[Link]")
return render_template("[Link]", msg=msg)

@[Link]("/userlogin", methods=["POST","GET"])
def userlogin():
msg = ''
if ([Link] == "POST"):
uname = [Link]["uname"]
pwd = [Link]["pwd"]
sql = "select * from NewUser where UserName = '%s' and Password = '%s' " % (uname,
pwd)
obj = [Link](sql)
if(obj):
print("Obj : ", obj)
session["id"] = obj[0]
return render_template("[Link]")
else:
msg="Invalid UserName/Password"
return render_template("[Link]",msg=msg)

@[Link]("/userviewprofile")
def userviewprofile():
tablename="NewUser"
id=session["id"]
sql = "select * from "+tablename + " where userid = "+ str(id)
data = [Link](sql)
return render_template("[Link]", data=data)

@[Link]("/adminviewcontacts")
def adminviewcontacts():
tablename="ContactTable"
sql = "Desc "+tablename
cols = [Link](sql)
sql = "select * from "+tablename
data = [Link](sql)
return render_template("[Link]", cols=cols, data=data)

@[Link]("/adminviewusers")
def adminviewusers():
tablename = "NewUser"
sql = "Desc " + tablename
cols = [Link](sql)
sql = "SELECT UserId, firstName, lastname, username, phonenumber, emailid, address
FROM " + tablename
data = [Link](sql)
return render_template("[Link]", cols=cols, data=data)

@[Link]("/userviewpredictions")
def userviewpredictions():
id = session["id"]
tablename = "predictiontable"
sql = "Desc " + tablename
cols = [Link](sql)
sql = "SELECT * FROM " + tablename + " where userid = " + str(id)
data = [Link](sql)
return render_template("[Link]", cols=cols, data=data)

@[Link]("/adminviewpredictions")
def adminviewpredictions():
tablename = "predictiontable"
sql = "Desc " + tablename
cols = [Link](sql)
sql = "SELECT * FROM " + tablename
data = [Link](sql)
return render_template("[Link]", cols=cols, data=data)

@[Link]("/newuser", methods=["POST","GET"])
def newuser():
msg=''
if([Link]=="POST"):
fname = [Link]["fname"]
lname = [Link]["lname"]
email = [Link]["email"]
phnum = [Link]["phnum"]
address = [Link]["address"]
uname = [Link]["uname"]
pwd = [Link]["pwd"]
sql="Insert into NewUser(FirstName, LastName, UserName, Password, EmailId,
PhoneNumber, Address) " \
"values('%s','%s','%s','%s','%s','%s','%s')"%(fname, lname, uname, pwd, email,
phnum, address)
[Link](sql)
msg="New User added success"
return render_template("[Link]", msg=msg)

@[Link]("/contact", methods=["POST","GET"])
def contact():
msg=''
if([Link]=="POST"):
name = [Link]["name"]
email = [Link]["email"]
subject = [Link]["subject"]
phnum = [Link]["phnum"]
message = [Link]["message"]
sql="Insert into ContactTable(PersonName, Email, Subject, Message, PhoneNum) " \
"values('%s','%s','%s','%s','%s')"%(name, email, subject, message, phnum)
[Link](sql)
msg="Contact Details added success"
return render_template("[Link]", msg=msg)
@[Link]("/gallery")
def gallery():
return render_template("[Link]")

@[Link]("/usercheckprediction", methods=["POST","GET"])
def usercheckprediction():
df = pd.read_csv('static/Heart_train.csv')
data = [Link]
X = data[:, :-1]
Y = data[:, -1:]
print("Data : \n",data)
print("X : \n", X)
print("Y : \n", Y)
value = ''
if [Link] == 'POST':
age = float([Link]['age'])
sex = float([Link]['gender'])
cp = float([Link]['cp'])
trestbps = float([Link]['trestbps'])
chol = float([Link]['chol'])
fbs = float([Link]['fbs'])
restecg = float([Link]['restecg'])
thalach = float([Link]['thalach'])
exang = float([Link]['exang'])
oldpeak = float([Link]['oldpeak'])
slope = float([Link]['slope'])
ca = float([Link]['ca'])
thal = float([Link]['thal'])
user_data = [Link](
(age,sex,cp,trestbps,chol,fbs,restecg,thalach,exang,oldpeak,
slope,ca,thal)
).reshape(1, 13)
rf = RandomForestClassifier(
n_estimators=16, criterion='entropy',max_depth=9)

[Link](np.nan_to_num(X), Y)
[Link](np.nan_to_num(X), Y)
predictions = [Link](user_data)

print("Prediction : ", predictions)


disease=''
if int(predictions[0]) == 1:
value = 'have'
disease = 'Yes'
elif int(predictions[0]) == 0:
value = "don\'t have"
disease = 'No'
print("Value : ", value)
tablename = "NewUser"
id = session["id"]
sql = "select * from " + tablename + " where userid = " + str(id)
data = [Link](sql)
if(data):
fname=data[1]
lname = data[2]
phnum = data[5]
email = data[6]
address= data[7]
date = [Link]()
now = [Link]("%m/%d/%Y, %H:%M:%S")
sql="Insert into PredictionTable(UserId, FirstName, " \
"LastName, PhoneNumber, EmailId, Address, " \
"HeartDisease, Date) values(%d, '%s','%s','%s','%s','%s','%s','%s')" \
%(id, fname, lname, phnum, email, address, disease, now)
print("SQL : ", sql)
[Link](sql)
return render_template('[Link]',value=value)

if __name__ == '__main__':
[Link](debug=True)

[Link]
{% extends '[Link]' %}
{% block content %}
<html lang="en">
<body>

<!-- ======= Hero Section ======= -->


<section id="hero">
<div class="hero-container">
<div id="heroCarousel" data-bs-interval="5000" class="carousel slide carousel-fade"
data-bs-ride="carousel">

<ol class="carousel-indicators" id="hero-carousel-indicators"></ol>

<div class="carousel-inner" role="listbox">


<!-- Slide 1 -->
<div class="carousel-item active" style="background-image:
url(static/assets/img/[Link]);">
<div class="carousel-container">
<div class="carousel-content">
<h2 class="animate__animated animate__fadeInDown">Heart Disease
Prediction</h2>
<p class="animate__animated animate__fadeInUp">What is heart disease? The
term “heart disease” refers to several types of heart conditions. </p>
</div>
</div>
</div>

<!-- Slide 2 -->


<div class="carousel-item" style="background-image: url(static/assets/img/[Link]);">
<div class="carousel-container">
<div class="carousel-content">
<h2 class="animate__animated animate__fadeInDown">Heart Disease
Prediction</h2>
<p class="animate__animated animate__fadeInUp">The most common type of
heart disease in the United States is coronary artery disease (CAD), which affects the blood
flow to the heart. Decreased blood flow can cause a heart attack.</p>
</div>
</div>
</div>

<!-- Slide 3 -->


<div class="carousel-item" style="background-image: url(static/assets/img/[Link]);">
<div class="carousel-container">
<div class="carousel-content">
<h2 class="animate__animated animate__fadeInDown">Heart Disease
Prediction</h2>
<p class="animate__animated animate__fadeInUp">Coronary artery disease is a
common heart condition. The major blood vessels that supply the heart (coronary arteries)
struggle to send enough blood, oxygen and nutrients to the heart muscle.</p>
</div>
</div>
</div>

</div>

<a class="carousel-control-prev" href="#heroCarousel" role="button" data-bs-


slide="prev">
<span class="carousel-control-prev-icon bi bi-chevron-left"
aria-hidden="true"></span>
</a>

<a class="carousel-control-next" href="#heroCarousel" role="button" data-bs-


slide="next">
<span class="carousel-control-next-icon bi bi-chevron-right"
aria-hidden="true"></span>
</a>

</div>
</div>
</section><!-- End Hero -->
</body>
</html>
{% endblock %}
[Link]
import [Link]
def getConn():
conn = [Link](host="localhost",
user="root",
password="",
database="HeartDisease")
return conn

def executeUpdate(sql):
conn=getConn()
cursor=[Link]()
[Link](sql)
[Link]()

def executeQuery(sql):
conn=getConn()
cursor=[Link]()
[Link](sql)
data=[Link]()
return data

def checkQuery(sql):
conn=getConn()
cursor=[Link]()
[Link](sql)
data=[Link]()
return data[0]
def getColumnHeaders(sql):
conn=getConn()
cursor=[Link]()
[Link](sql)
data=[Link]()
cols=[]
for x in data:
if(x[0]!='Password'):
[Link](x[0])
return cols
Screen Shots

Home Page

About Page
Gallery Page
NewUser

Admin Login
User Login

Contact Page
Admin Main Page
Admin View Users

Admin View Contacts


Admin View Prediction

UserMainPage
Check Prediction
View Predictions

DESIGN

Introduction:
Design is the first step in the development
phase for any techniques and principles for the purpose of defining
a device, a process or system in sufficient detail to permit its
physical realization.

Once the software requirements have


been analyzed and specified the software design involves three
technical activities - design, coding, implementation and testing
that are required to build and verify the software.

The design activities are of main


importance in this phase, because in this activity, decisions
ultimately affecting the success of the software implementation and
its ease of maintenance are made. These decisions have the final
bearing upon reliability and maintainability of the system. Design is
the only way to accurately translate the customer’s requirements
into finished software or a system.

Design is the place where quality is


fostered in development. Software design is a process through
which requirements are translated into a representation of
software. Software design is conducted in two steps. Preliminary
design is concerned with the transformation of requirements into
data.

UML Diagrams:

Actor:
A coherent set of roles that users of use cases play when interacting
with the use `cases.

Use case:
A description of sequence of actions, including
variants, that a system performs that yields an observable result of
value of an actor.
UML stands for Unified Modeling Language. UML is a language for
specifying, visualizing and documenting the system. This is the step
while developing any product after analysis. The goal from this is to
produce a model of the entities involved in the project which later
need to be built. The representation of the entities that are to be
used in the product being developed need to be designed.

There are various kinds of methods in software design:


They are as follows:
Use case Diagram
Sequence Diagram
Collaboration Diagram
Activity Diagram
State chat Diagram

Use case Diagrams:

Use case diagrams model behavior within a system and helps the
developers understand of what the user require. The stick man
represents what’s called an actor.

Use case diagram can be useful for getting an overall view


of the system and clarifying that can do and more importantly what
they can’t do.

Use case diagram consists of use cases and actors and shows the
interaction between the use case and actors.

 The purpose is to show the interactions between the use


case and actor.
 To represent the system requirements from user’s
perspective.
 An actor could be the end-user of the system or an
external system.

Use case Diagram


A Use case is a description of set of sequence of actions.
Graphically it is rendered as an ellipse with solid line including only
its name. Use case diagram is a behavioral diagram that shows a
set of use cases and actors and their relationship. It is an
association between the use cases and actors. An actor represents
a real-world object. Primary Actor – Sender, Secondary Actor
Receiver.

ADMIN

View Users

Admin View Contacts

View Prediction
Reports
User

View Profile

Search
User Predictions

Search
Predictions

Logout

Sequence Diagram

Sequence diagram and collaboration diagram are called


INTERACTION DIAGRAMS. An interaction diagram shows an
interaction, consisting of set of objects and their relationship
including the messages that may be dispatched among them.

A sequence diagram is an introduction that empathizes the time


ordering of messages. Graphically a sequence diagram is a table
that shows objects arranged along the X-axis and messages
ordered in increasing time along the Y-axis.

Data Flow Diagram

DFD LEVEL 0

View Users
ADMIN
HeartDiseaseP
rediction

DFD LEVEL 1

View Contacts
ADMIN
HeartDiseaseP
rediction

DFD LEVEL 2
VIEW Predictions
ADMIN
HeartDiseaseP
rediction

DATA FLOW DIAGRAMS:


The DFD takes an input-process-output view of a system
i.e. data objects flow into the software, are transformed by
processing elements, and resultant data objects flow out of the
software.

Data objects represented by labeled arrows and


transformation are represented by circles also called as bubbles.
DFD is presented in a hierarchical fashion i.e. the first data flow
model represents the system as a whole. Subsequent DFD refine
the context diagram (level 0 DFD), providing increasing details with
each subsequent level.

The DFD enables the software engineer to develop models


of the information domain & functional domain at the same time. As
the DFD is refined into greater levels of details, the analyst
performs an implicit functional decomposition of the system. At the
same time, the DFD refinement results in a corresponding
refinement of the data as it moves through the processes that
embody the applications.

A context-level DFD for the system the primary external


entities produce information for use by the system and consume
information generated by the system. The labeled arrow represents
data objects or object hierarchy.

RULES FOR DFD:

 Fix the scope of the system by means of context diagrams.

 Organize the DFD so that the main sequence of the actions


 Reads left to right and top to bottom.

 Identify all inputs and outputs.

 Identify and label each process internal to the system with Rounded
circles.

 A process is required for all the data transformation and Transfers.


Therefore, never connect a data store to a data Source or the
destinations or another data store with just a Data flow arrow.

 Do not indicate hardware and ignore control information.

 Make sure the names of the processes accurately convey


everything the process is done.

 There must not be unnamed process.

 Indicate external sources and destinations of the data, with


Squares.

 Number each occurrence of repeated external entities.

 Identify all data flows for each process step, except simple Record
retrievals.
 Label data flow on each arrow.

 Use details flow on each arrow.

 Use the details flow arrow to indicate data movements.

E-R Diagrams:

The Entity-Relationship (ER) model was originally proposed by Peter


in 1976 [Chen76] as a way to unify the network and relational
database views. Simply stated the ER model is a conceptual data
model that views the real world as entities and relationships. A
basic component of the model is the Entity-Relationship diagram
which is used to visually represent data objects. Since Chen wrote
his paper the model has been extended and today it is commonly
used for database design For the database designer, the utility of
the ER model is:

 It maps well to the relational model. The constructs used in


the ER model can easily be transformed into relational tables.
 It is simple and easy to understand with a minimum of
training. Therefore, the model can be used by the database
designer to communicate the design to the end user.
 In addition, the model can be used as a design plan by the
database developer to implement a data model in specific
database management software.
Connectivity and Cardinality

The basic types of connectivity for relations are: one-to-one, one-to-


many, and many-to-many. A one-to-one (1:1) relationship is when
at most one instance of a entity A is associated with one instance of
entity B. For example, "employees in the company are each
assigned their own office. For each employee there exists a unique
office and for each office there exists a unique employee.

A one-to-many (1:N) relationships is when for one instance of entity


A, there are zero, one, or many instances of entity B, but for one
instance of entity B, there is only one instance of entity A. An
example of a 1:N relationships is
a department has many employees

Each employee is assigned to one department

A many-to-many (M:N) relationship, sometimes called non-specific,


is when for one instance of entity A, there are zero, one, or many
instances of entity B and for one instance of entity B there are zero,
one, or many instances of entity A. The connectivity of a
relationship describes the mapping of associated
ER Notation

There is no standard for representing data objects in ER


diagrams. Each modeling methodology uses its own notation. The
original notation used by Chen is widely used in academics texts
and journals but rarely seen in either CASE tools or publications by
non-academics. Today, there are a number of notations used;
among the more common are Bachman, crow's foot, and IDEFIX.

All notational styles represent entities as rectangular boxes


and relationships as lines connecting boxes. Each style uses a
special set of symbols to represent the cardinality of a connection.
The notation used in this document is from Martin. The symbols
used for the basic ER constructs are:

 Entities are represented by labelled rectangles. The label is the


name of the entity. Entity names should be singular nouns.
 Relationships are represented by a solid line connecting two
entities. The name of the relationship is written above the line.
Relationship names should be verbs
 Attributes, when included, are listed inside the entity rectangle.
Attributes which are identifiers are underlined. Attribute names
should be singular nouns.
 Cardinality of many is represented by a line ending in a crow's
foot. If the crow's foot is omitted, the cardinality is one.
 Existence is represented by placing a circle or a perpendicular
bar on the line. Mandatory existence is shown by the bar (looks
like a 1) next to the entity for an instance is required. Optional
existence is shown by placing a circle next to the entity that is
optional

Uname Address

EmailID
LastName UserId
FirstName
PhoneNum

NewUser
HeartDisease

Date

DATABASE SPECIFICATION:

Contact Table

Field Type Null


ContactID int(11) NO
PersonName varchar(100) YES
Email varchar(50) YES
Subject varchar(200) YES
Message varchar(200) YES
PhoneNum varchar(50) YES

NewUser

Field Type Null


UserId int(11) NO
FirstName varchar(20) YES
LastName varchar(20) YES
UserName varchar(20) YES
Password varchar(20) YES
PhoneNumber varchar(20) YES
EmailId varchar(20) YES
Address varchar(100) YES

PredictionTable

Field Type Null


PredictionId int(11) NO
UserId varchar(20) YES
FirstName varchar(20) YES
LastName varchar(20) YES
PhoneNumber varchar(20) YES
EmailId varchar(20) YES
Address varchar(100) YES
HeartDisease varchar(100) YES
Date varchar(100) YES
CHAPTER -5
TESTING AND IMPLEMENTATION

5.1 SYSTEM TESTING


The purpose of testing is to discover errors. Testing is the process of trying to discover
every conceivable fault or weakness in a work product. It provides a way to check the
functionality of components, sub-assemblies, assemblies and/or a finished product It is the
process of exercising software with the intent of ensuring that the

Software system meets its requirements and user expectations and does not fail in an
unacceptable manner. There are various types of test. Each test type addresses a specific
testing requirement.

5.2 TYPES OF TESTS

5.2.1 Unit testing


Unit testing involves the design of test cases that validate that the internal program
logic is functioning properly, and that program inputs produce valid outputs. All decision
branches and internal code flow should be validated. It is the testing of individual software
units of the application .it is done after the completion of an individual unit before integration.
This is a structural testing, that relies on knowledge of its construction and is invasive. Unit tests
perform basic tests at component level and test a specific Flightiness process, application,
and/or system configuration. Unit tests ensure that each unique path of a Flightiness process
performs accurately to the documented specifications and contains clearly defined inputs and
expected results.

5.2.2 Integration testing


Integration tests are designed to test integrated software components to determine if
they actually run as one program. Testing is event driven and is more concerned with the basic
outcome of screens or fields. Integration tests demonstrate that although the components
were individually satisfaction, as shown by successfully unit testing, the combination of
components is correct and consistent. Integration testing is specifically aimed at exposing the
problems that arise from the combination of components.

5.2.3 Functional test


N Functional tests provide systematic demonstrations that functions tested are available
as specified by the Flightiness and technical requirements, system documentation, and user
manuals.

Functional testing is centered on the following items:

Valid Input : identified classes of valid input must be accepted.

Invalid Input : identified classes of invalid input must be rejected.

Functions : identified functions must be exercised.

Output : identified classes of application outputs must be exercised.

Systems/Procedures: interfacing systems or procedures must be invoked.

Organization and preparation of functional tests is focused on requirements, key


functions, or special test cases. In addition, systematic coverage pertaining to identify
Flightiness process flows; data fields, predefined processes, and successive processes must be
considered for testing. Before functional testing is complete, additional tests are identified and
the effective value of current tests is determined.

5.2.4 System Test


System testing ensures that the entire integrated software system meets requirements.
It tests a configuration to ensure known and predictable results. An example of system testing
is the configuration oriented system integration test. System testing is based on process
descriptions and flows, emphasizing pre-driven process links and integration points.
5.2.5 White Box Testing
White Box Testing is a testing in which in which the software tester has knowledge of
the inner workings, structure and language of the software, or at least its purpose. It is purpose.
It is used to test areas that cannot be reached from a black box level.

5.2.6 Black Box Testing


Black Box Testing is testing the software without any knowledge of the inner workings,
structure or language of the module being tested. Black box tests, as most other kinds of tests,
must be written from a definitive source document, such as specification or requirements
document, such as specification or requirements document.

Unit Testing:
Unit testing is usually conducted as part of a combined code and unit test phase of the
software lifecycle, although it is not uncommon for coding and unit testing to be conducted as
two distinct phases.

Test strategy and approach


Field testing will be performed manually and functional tests will be written in detail.

Test objectives
 All field entries must work properly.
 Pages must be activated from the identified link.
 The entry screen, messages and responses must not be delayed.

Features to be tested
 Verify that the entries are of the correct format
 No duplicate entries should be allowed
 All links should take the user to the correct page.

Integration Testing
Software integration testing is the incremental integration testing of two or more
integrated software components on a single platform to produce failures caused by interface
defects.
Test Results:
All the test cases mentioned above passed successfully. No defects encountered.

Acceptance Testing
User Acceptance Testing is a critical phase of any project and requires significant
participation by the end user. It also ensures that the system meets the functional
requirements.

Test Results:
All the test cases mentioned above passed successfully. No defects encountered

CHAPTER -6

CONCLUSION

The System was successfully developed to meet the needs of the clients. It was found to
provide all the features that required for the organization. The accuracy and complexity of the
software are also ensured and this system provides benefits such as user-friendly environment,
which serves to verify the integrity of a remotely-hosted Requirements monitor.

The primary objective of this study was to classify heart disease using different
models and a real-world dataset. The k-modes clustering algorithm was applied to a
dataset of patients with heart disease to predict the presence of the disease. The
dataset was preprocessed by converting the age attribute to years and dividing it into
bins of 5-year intervals, as well as dividing the diastolic and systolic blood pressure data
into bins of 10 intervals. The dataset was also split on the basis of gender to take into
account the unique characteristics and progression of heart disease in men and women.

The elbow curve method was utilized to determine the optimal number of clusters
for both the male and female datasets. The results indicated that the MLP model had
the highest accuracy of 87.23%. These findings demonstrate the potential of k-modes
clustering to accurately predict heart disease and suggest that the algorithm could be a
valuable tool in the development of targeted diagnostic and treatment strategies for the
disease. The study utilized the Kaggle cardiovascular disease dataset with 70,000
instances, and all algorithms were implemented on Google Colab. The accuracies of all
algorithms were above 86% with the lowest accuracy of 86.37% given by decision trees
and the highest accuracy given by multilayer perceptron, as previously mentioned.

FUTURE ENHANCEMENT

Limitations. Despite the promising results, there are several limitations that should
be noted. First, the study was based on a single dataset and may not be generalizable
to other populations or patient groups. Furthermore, the study only considered a limited
set of demographic and clinical variables and did not take into account other potential
risk factors for heart disease, such as lifestyle factors or genetic predispositions.
Additionally, the performance of the model on a held-out test dataset was not evaluated,
which would have provided insight on how well the model generalizes to new, unseen
data. Lastly, the interpretability of the results and the ability to explain the clusters
formed by the algorithm was not evaluated. In light of these limitations, it is
recommended to conduct further research to address these issues and to better
understand the potential of k-modes clustering.

Future research. Future research could focus on addressing the limitations of this
study by comparing the performance of the k-modes clustering algorithm with other
commonly used clustering algorithms, such as k-means or hierarchical clustering, to
gain a more comprehensive understanding of its performance. Additionally, it would be
valuable to evaluate the impact of missing data and outliers on the accuracy of the
model and develop strategies for handling these cases. Furthermore, it would be
beneficial to evaluate the performance of the model on a held-out test dataset in order
to establish its generalizability to new, unseen data. Ultimately, future research should
aim to establish the robustness and generalizability of the results and the interpretability
of the clusters formed by the algorithm, which could aid in understanding the results and
support decision making based on the study’s findings.

We plan to formalize our approach that will allow us to provide more rigorous
evaluation. This would include developing a core calculus for the TPM’s machine model based
on the cryptographic protocol Spi calculus. This semantics would account for the
authentication, secrecy, and integrity properties of the TPM. Furthermore, a formal semantics
for our approach can be built on top of this core calculus similar to the techniques
CHAPTER -7
REFERENCES

1. A Programmer's Introduction to Python, 2nd edition (Apress) - Eric Gunnerson


2. Inside Java, 2nd edition (Microsoft Press) - Tom Archer
3. Debugging Html, Css, Js(New Riders) - Jonathon Goodyear, Brian Peek, Brad Fox
4. Designing Python Applications (Microsoft Press) - Jonathon Goodyear, Brian Peek, Brad
Fox
5. Debugging Flask - Jonathon Goodyear, Brian Peek, Brad Fox

Web References:

1. Estes, C.; Anstee, Q.M.; Arias-Loste, M.T.; Bantel, H.; Bellentani, S.; Caballeria,
J.; Colombo, M.; Craxi, A.; Crespo, J.; Day, C.P.; et al. Modeling NAFLD disease
burden in China, France, Germany, Italy, Japan, Spain, United Kingdom, and
United States for the period 2016–2030. J. Hepatol. 2018, 69, 896–904.
2. Drożdż, K.; Nabrdalik, K.; Kwiendacz, H.; Hendel, M.; Olejarz, A.; Tomasik, A.;
Bartman, W.; Nalepa, J.; Gumprecht, J.; Lip, G.Y.H. Risk factors for
cardiovascular disease in patients with metabolic-associated fatty liver disease: A
machine learning approach. Cardiovasc. Diabetol. 2022, 21, 240.
3. Murthy, H.S.N.; Meenakshi, M. Dimensionality reduction using neuro-genetic
approach for early prediction of coronary heart disease. In Proceedings of the
International Conference on Circuits, Communication, Control and Computing,
Bangalore, India, 21–22 November 2014; pp. 329–332. Benjamin, E.J.; Muntner,
P.; Alonso, A.; Bittencourt, M.S.; Callaway, C.W.; Carson, A.P.; Chamberlain,
A.M.; Chang, A.R.; Cheng, S.; Das, S.R.; et al. Heart disease and stroke
statistics—2019 update: A report from the American heart
association. Circulation 2019, 139, e56–e528. Shorewala, V. Early detection of
coronary heart disease using ensemble techniques. Inform. Med.
Unlocked 2021, 26, 100655.
4. Mozaffarian, D.; Benjamin, E.J.; Go, A.S.; Arnett, D.K.; Blaha, M.J.; Cushman,
M.; de Ferranti, S.; Després, J.-P.; Fullerton, H.J.; Howard, V.J.; et al. Heart
disease and stroke statistics—2015 update: A report from the American Heart
Association. Circulation 2015, 131, e29–e322.

You might also like