Insights and predictive analytics for heart disease using Python
and machine learning
Jing Ke∗ Weijian Du Jitao Li
Wuhan College Wuhan College Wuhan College
Wuhan, Hubei, China Wuhan, Hubei, China Wuhan, Hubei, China
1687158013@[Link] 1516338764@[Link] 239904770@[Link]
Hui Lei Beiqi Chen Siyuan Huang
Wuhan College Wuhan College Wuhan College
Wuhan, Hubei, China Wuhan, Hubei, China Wuhan, Hubei, China
3265520142@[Link] 2161887005@[Link] 1852438544@[Link]
JunJie Yang
Wuhan College
Wuhan, Hubei, China
1157064803@[Link]
Abstract Artificial Intelligence and Sustainable Development (ICAISD 2025), Novem-
In the era of big data, big data technology is increasingly perme- ber 14–16, 2025, Shanghai, China. ACM, New York, NY, USA, 7 pages.
[Link]
ating various medical fields, providing new technical support for
the prediction and diagnosis of cardiovascular diseases. This study
1 INTRODUCTION
utilizes deep learning technology to analyze and model cardiac and
cardiovascular data, developing a disease prediction model that fea- Big data technology is transforming healthcare by enabling data-
tures rapid detection and high accuracy. The model facilitates early driven diagnosis and prognosis of heart disease. This study aims
identification and prognosis assessment of cardiovascular diseases, to develop a deep learning model for rapid, high-precision predic-
offering innovative approaches for clinical diagnosis and health tion of cardiovascular disease (CVD) to support prevention and
management. The application of medical big data not only enhances screening. CVD is the leading cause of death in China (*China
the mining of disease-related characteristics but also supports the Cardiovascular Disease Report 2015*), yet clinical practice faces
construction of medical knowledge graphs, driving the evolution of significant challenges: **data silos, insufficient diagnostic accuracy,
healthcare services toward intelligent and precision-oriented mod- and high readmission rates due to poor post-discharge care**. These
els. This research validates the effectiveness of big data technology challenges align with those identified in a systematic review on
in cardiovascular disease analysis, demonstrating significant poten- machine learning and electronic health records for primary pre-
tial for improving diagnostic efficiency and optimizing healthcare vention of CVD, which highlights data fragmentation and model
service systems. generalizability as key barriers to clinical [Link] tra-
ditional approaches, medical big data efficiently uncovers correla-
CCS Concepts tions between diseases, symptoms, tests, and treatments, facilitating
early intervention. Emphasizing the need for interpretability noted
• Computational methods → Machine learning; Machine learn-
in the same review [1], we analyze associations between clinical
ing methods; Classification and regression trees.
variables—gender, age, heart rate, blood pressure, chest pain type,
and exercise-induced angina—and CVD. Our models quantify these
Keywords
relationships and visualize them through heatmaps, improving both
big data technology, cardiovascular diseases, deep learning, disease analytical transparency and predictive accuracy.
prediction, medical knowledge graph
ACM Reference Format: 2 TECHNICAL SOLUTIONS
Jing Ke, Weijian Du, Jitao Li, Hui Lei, Beiqi Chen, Siyuan Huang, and Jun-
Jie Yang. 2025. Insights and predictive analytics for heart disease us-
2.1 overview
ing Python and machine learning. In 2025 International Conference on This project aims to accurately predict cardiovascular disease (CVD)
∗
Corresponding author.
risk by developing and comparing multiple machine learning (ML)
models. Our work aligns with the research trend of using ML to
enhance risk assessment in specific populations, as exemplified by a
This work is licensed under a Creative Commons Attribution 4.0 International License.
recent study that built a prediction model for CVD in patients with
ICAISD 2025, Shanghai, China chronic lung diseases.[2]Our technical approach follows a complete
© 2025 Copyright held by the owner/author(s). workflow: data processing, model development, and evaluation.
ACM ISBN 979-8-4007-2126-7/25/11
[Link]
We integrate classic algorithms, including logistic regression (LR),
278
ICAISD 2025, November 14–16, 2025, Shanghai, China Jing Ke et al.
Figure 1: Technology roadmap.
K-Nearest Neighbors (KNN), and decision trees (DT), and employ roadmap lays a solid foundation for reproducible future research
ensemble learning to enhance performance. This methodological and applications (Figure 1).
choice is consistent with findings from similar studies, which indi-
cate that ensemble methods, such as random forest, often achieve 2.2 data preprocessing
higher predictive accuracy than single models in specific clinical Convert the target column values (1, 2, 3, 4) representing different
[Link] entire research is based on an in-depth analysis of car- levels of heart disease presence to 1 (indicating heart disease) and
diovascular disease datasets, utilizing Python data science tools for 0 (indicating no heart disease) to fit a binary classification task.
all stages from preprocessing to visualization. This clear technical
279
Insights and predictive analytics for heart disease using Python and machine learning ICAISD 2025, November 14–16, 2025, Shanghai, China
Figure 2: confusion matrix of the logistic regression model
Figure 3: Confusion Matrix of the Naive Bayes Model
2.2.1 Rename feature and missing values processing. Since the fea-
ture names in the original dataset are not conducive to interpre-
tation, we first rename each column of the dataset to make them by measuring probabilistic relationships between labels and fea-
easier to understand. Secondly, we modify the specific values of tures, deriving posterior probability distributions via the learned
the categorical variables to enhance the interpretability of the sub- model and outputting the class with maximum posterior probability.
sequent model. The algorithm is prone to the zero-probability problem—occurring
when test set labels have unseen values, often with unbalanced
2.2.2 Model Construction Four algorithms were employed. Logistic
datasets—but our 303-sample dataset is balanced (roughly equal pa-
regression, naive Bayes, decision tree, and random forest. Among
tients and non-patients). After 8:2 train-test splitting, both groups
61 test samples, naive Bayes demonstrated the highest accuracy
are present in the training set, avoiding this issue. The Naive Bayes
(83.6%,10 errors), followed by logistic regression and random forest
model’s confusion matrix is shown in Figure 3.
at 82.0% (11 errors each), while decision tree recorded the lowest
Among the 61 samples in the test set of this model, 51 are pre-
accuracy (73.8%,16 errors). These results indicate that probabilistic
dicted correctly, and 10 are predicted incorrectly. Among the in-
models and ensemble learning methods outperform traditional
correct predictions, 4 samples of people without heart disease are
approaches.
predicted as having heart disease, while 6 samples of people actually
2.3 model construction with heart disease are predicted as not having heart disease.
After the above preprocessing, modeling is initiated. This project 2.3.3 decision tree. Decision tree is a non-parametric supervised
uses Python’s LogisticRegression, GaussianNB, DecisionTreeClas- learning method for classification and regression, with a tree-like
sifier, and RandomForestClassifier for modeling, with model expla- structure: leaf nodes represent categories, and non-leaf nodes split
nations attached. samples by attributes. It builds tree models by minimizing the loss
function, with a learning process including feature selection, tree
2.3.1 logistic regression. This study aims to predict cardiovascular generation, and pruning, and its core is recursive splitting to form
disease (CVD) risk by developing and comparing multiple machine classification rules. When building the model via Python’s sklearn
learning models. We employ logistic regression as a core binary clas- DecisionTreeClassifier, node splitting criteria include information
sifier, optimized via maximum likelihood estimation, with prepro- entropy and Gini index (default). Comparisons show the Gini index-
cessed data exported to R for advanced statistical [Link] based model performs better in evaluation metrics, so it is selected
modeling strategy is informed by recent methodological research, as the splitting standard for this project. The decision tree model’s
which indicates that Lasso regression can outperform traditional confusion matrix is shown in Figure 4.
maximum likelihood estimation in high-dimensional data scenarios Among the 61 samples in the test set of this model, 45 are pre-
(i.e., when the number of covariates is large relative to sample size). dicted correctly, and 16 are predicted incorrectly. Specifically, 7
This insight guided our approach to feature selection and model samples of people without heart disease are predicted as having
refinement.[3]The final logistic regression model demonstrated a heart disease, while 9 samples of people actually with heart disease
highly significant likelihood ratio (P < 0.0001)(see confusion matrix are predicted as not having heart disease.
in Figure 2). These results provide a robust baseline for subsequent
ensemble learning and comparative model evaluation. 2.3.4 random forest. Random Forest is an ensemble learning
method based on decision trees. It constructs multiple decision
2.3.2 Naive Bayes. Naive Bayes is a supervised generative learn- trees, with each tree trained using randomly sampled subsets of
ing algorithm based on Bayesian principles, incorporating the key samples and features. The final prediction is made by integrating
assumption of feature conditional independence. It classifies inputs
280
ICAISD 2025, November 14–16, 2025, Shanghai, China Jing Ke et al.
Table 1: Comparison of model metrics.
Model Accuracy Precision Recall F1-Score AUC-Score
Logistic regression 0.820 0.818 0.844 0.831 0.913
Naive bayes 0.836 0.867 0.813 0.839 0.905
Decision tree 0.738 0.767 0.719 0.742 0.739
Random forest 0.820 0.889 0.750 0.814 0.932
Figure 4: confusion matrix of the decision tree model
Figure 6: ROC curves of the models.
2.4 model evaluation
The accuracy, precision, recall, and F1 score were calculated using
the confusion matrix, with ROC curves plotted and AUC values
computed. Comprehensive comparison of metrics revealed that
the random forest model demonstrated superior predictive per-
formance, confirming the significant advantage of the ensemble
method in this task, as illustrated in figure 6and table 1.
After comprehensive evaluation of all metrics, our analysis
demonstrates that the model developed using the random forest
algorithm achieves superior fitting and prediction performance.
This finding objectively confirms the effectiveness of the Bagging
method in ensemble learning, which outperforms other algorithms
with significant advantages.
2.5 data handling
Figure 5: confusion matrix of the random forest model 2.5.1 The specific implementation process of the system. This study
conducts a systematic analysis of the heart disease dataset through
three key phases: data preprocessing and statistical testing, com-
the results of all decision trees. The confusion matrix of the Random prehensive correlation analysis between clinical features (includ-
Forest model is shown in Figure 5. ing demographic indicators, physiological parameters, and disease
Among the 61 samples in the test set of this model, 50 are pre- symptoms) and disease status, followed by predictive model con-
dicted correctly, and 11 are predicted incorrectly. Specifically, 3 struction and performance evaluation.
samples of people without heart disease are predicted as having
heart disease, while 8 samples of people actually with heart disease 2.5.2 Import relevant libraries and modules, set parameters, and
are predicted as not having heart disease. analyze. Import libraries such as numpy, pandas, [Link]
and Seaborn for data processing and visualization. Load the dataset
281
Insights and predictive analytics for heart disease using Python and machine learning ICAISD 2025, November 14–16, 2025, Shanghai, China
Figure 7: Dataset description table.
data=pd.read_csv(’[Link]’ from Sklearn using StandardScaler,
train-test split, and various classification algorithms (KNN, decision
tree, random forest, logistic regression, etc.), along with evaluation
metrics (accuracy, recall, F1, AUC, etc.),[4]as shown in figure 7.
age: age (years) sex: gender (1 male/0 female) cp: chest pain type (1
typical angina/2 atypical/3 non-anginal/4 asymptomatic) trestbps:
resting blood pressure (mmHg) chol: cholesterol (mg/dl) fbs: fast-
ing blood glucose>120 is 1, otherwise 0 restecg: resting ECG (0
normal/1 ST-T abnormality/2 left ventricular hypertrophy) thalach:
maximum heart rate reached exang: exercise-induced angina (1
yes/0 no) oldpeak: exercise-induced ST depression slope: ST slope
(1 ascending/2 flat/3 descending) ca: number of fluorescein-marked
vessels (0-4) thal: thalassemia (3 normal/6 fixed defect/7 reversible
defect) target: heart disease (0 no/1 yes)
3 TEST ANALYSIS
3.1 source of data on the number of people with
AIDS and tuberculosis
The dataset used in this work is sourced from Kaggle’s Heart Disease
Figure 8: Correlation heatmap.
dataset. It contains partial statistical samples of heart disease cases.
The data was obtained from the CSV file.
while correlations with age, sex, number of major vessels (ca), and
3.2 environment Configuration and Software thalassemia (thal) are relatively weak. The correlation with fasting
System blood sugar (fbs) is the least significant.
Software system: Windows 11; Experimental environment: Python 3.3.2 analysis of some feature distributions. According to the sta-
interpreter; Python development environment: Anaconda Jupyter; tistical chart in Figure 9, the following feature distribution can be
Python analyzed: Gender (sex): It shows the difference between male and
female distribution, which helps to analyze the influence of gender
3.3 testing procedure on other variables.
3.3.1 correlation analysis. Heatmaps use color gradients to visual-
ize correlations between numerical variables, allowing quick iden- 3.4 gender and disease analysis
tification of relationship strength through color intensity and exact The prevalence rate in males (gender code 1) is significantly higher
coefficient values. than in females (gender code 0). The bar chart shows male patients
As shown in Figure 8, the prevalence of heart disease shows outnumber females by 2:1 (207 vs. 96), with the number of disease
significant correlations with multiple clinical indicators: a strong cases (165) exceeding non-disease cases (138). Further analysis
negative correlation with maximum heart rate (thalach) at -0.44, confirms that females demonstrate a higher disease prevalence
Consistent with prior findings, impaired physical activity capacity rate proportionally. Additional contextual information is provided
is a significant cardiovascular risk marker.[5]a negative correla- through age-gender-disease relationships.
tion with exercise-induced angina (exang) at -0.29, and a positive
correlation with ECG slope (slope) at 0.26. Its correlations with
chest pain type (cp) and ST depression (oldpeak) both exceed 0.4,
282
ICAISD 2025, November 14–16, 2025, Shanghai, China Jing Ke et al.
Figure 9: Feature statistics chart.
3.5 age and disease relationship
This study reveals a bimodal distribution of cardiovascular disease
risk by age : the risk peak occurs in the 37–54 age group(where the
number of cases exceeds that of healthy individuals) and rises again
**after age 70**. **Middle-aged adults**, due to lifestyle risks such as
chronic stress and sedentary behavior, exhibit a susceptibility that
is even higher than that of **older adults**, whose risk is primarily
driven by physiological decline. This finding suggests the need for
age-stratified interventions: **middle-aged adults** should focus
on stress management and health education, while **older adults**
require enhanced comprehensive chronic disease care.
Figure 10: Relationship between age and disease incidence.
3.6 analysis of the relationship between age,
heart rate and disease Within the same age group, heart disease patients typically exhibit
By analyzing the distribution in Figure 10 scatter plot, we can pre- higher heart rates than healthy individuals.
liminarily determine the relationship between age, maximum heart
rate, and disease prevalence. When patients ’data points cluster 4 MACHINE LEARNING
within specific age or heart rate ranges, this suggests correlations Multiple methods were applied for data classification prediction
with disease risk. Notably, heart rate measurements for patients and algorithm evaluation, with metrics such as accuracy, precision,
generally cluster between 140-200bpm and 40-60 years old. These and recall calculated. Through machine learning processing, effec-
values show higher prevalence compared to healthy individuals, tive methods were selected to enhance the reliability and factual
as evidenced by the violin plot’s higher and more concentrated relevance of sample data analysis. As shown in Figure 11, logis-
distribution. Maximum heart rate decreases progressively with age. tic regression performed best in the data area test, achieving an
283
Insights and predictive analytics for heart disease using Python and machine learning ICAISD 2025, November 14–16, 2025, Shanghai, China
Figure 11: classification prediction and algorithm evaluatio
average accuracy of 0.93 and an AUC value of 0.91. The average the future include the development of standardized databases and
accuracy and AUC values of random forest, K-nearest neighbor, mobile health solutions for intelligent cardiovascular care.[2][3][4]
and decision tree decreased in sequence. Since logistic regression
had the largest AUC area, its classification effect was relatively the Acknowledgments
best.[6] 2023 research and innovation team of Wuhan college XST202310
5 CONCLUSION References
This study adopts Kaggle’s clinical heart disease dataset and com- [1] Liu T , Krentz A J , Huo Z ,et [Link] and Challenges of Cardiovascular
Disease Risk Prediction for Primary Prevention Using Machine Learning and
bines Python data science tools to build a predictive model for Electronic Health Records: A Systematic Review[J].Reviews in Cardiovascular
disease risk assessment. After comprehensive data preprocessing, Medicine, 2025, 26(4).DOI:10.31083/RCM37443.
[2] H M , Kang Q M , Jiang X M .Machine learning-based risk assessment for cardio-
a comparison was made among multiple machine learning mod- vascular diseases in patients with chronic lung diseases[J].Medicine, 2025,
els, with the random forest ensemble model achieving the best [3] Junior, G. P. A., & Pereira, G. H. A. (2024). A comparison of the discrimination
performance (with an accuracy rate of 82%), demonstrating the performance of lasso and maximum likelihood estimation in logistic regression
model (Version 1). arXiv.
advantages of ensemble [Link] prediction, the research [4] Rimal, Y., Sharma, N., Paudel, S., Alsadoon, A., Koirala, M. P., & Gill, S. (2025).
also analyzes the correlations between clinical features (age, gen- Comparative analysis of heart disease prediction using logistic regression, SVM,
der, heart rate) and disease risk through heatmaps and distribution KNN, and random forest with cross-validation for improved accuracy. Scientific
Reports, 15(1).
charts, providing valuable reference insights for clinical practice. [5] Hassan, Ch. A. ul, Iqbal, J., Irfan, R., Hussain, S., Algarni, A. D., Bukhari, S. S. H.,
The findings highlight its potential application value in clinical Alturki, N., & Ullah, S. S. (2022). Effectively Predicting the Presence of Coronary
Heart Disease Using Machine Learning Classifiers. Sensors, 22(19), 7227.
diagnosis and health management. Future research directions for [6] Kang, S. (2020). Model validation failure in class imbalance problems. Expert
Systems with Applications, 146, 113190
284