
==== Front
J Family Med Prim Care
J Family Med Prim Care
JFMPC
J Family Med Prim Care
Journal of Family Medicine and Primary Care
2249-4863
2278-7135
Wolters Kluwer - Medknow India

JFMPC-13-3393
10.4103/jfmpc.jfmpc_2025_23
Original Article
Rapid and non-invasive diagnosis of hyperkalemia in patients with systolic myocardial failure using a model based on machine learning algorithms
Torshizi Hamid M. 1
Khorgami Mohammad R. 2
Omidi Negar 3
Khalaj Fattaneh 4
Ahmadi Mohsen 5
1 Phd Student of Biomedical Engineering and Physics Department, School of Medicine, Shahid Beheshti University of Medical Sciences, Tehran, Iran
2 Rajaie Heart Center and Department of Pediatric Cardiology, School of Medicine, Iran University of Medical Sciences, Tehran, Iran
3 Cardiac Primary Prevention Research Center, Cardiovascular Disease Research Institute, Tehran University of Medical Science, Tehran, Iran
4 Digestive Disease Research Center, Digestive Disease Research Institute, Tehran University of Medical Sciences, Tehran, Iran
5 Department of Biomedical Engineering, School of Medicine, Shahid Beheshti University of Medical Sciences, Tehran, Iran
Address for correspondence: Dr. Mohsen Ahmadi, Department of Biomedical Engineering, School of Medicine, Shahid Beheshti University of Medical Sciences, Tehran, Iran. E-mail: drmohsen.ahmadi1@gmail.com
8 2024
26 7 2024
13 8 33933397
28 12 2023
26 3 2024
30 4 2024
Copyright: © 2024 Journal of Family Medicine and Primary Care
2024
https://creativecommons.org/licenses/by-nc-sa/4.0/ This is an open access journal, and articles are distributed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License, which allows others to remix, tweak, and build upon the work non-commercially, as long as appropriate credit is given and the new creations are licensed under the identical terms.
ABSTRACT

Background:

Hyperkalemia is a potentially life-threatening electrolyte disturbance that if not diagnosed on time may lead to devastating conditions and sudden cardiac death. Blood sampling for potassium level checks is time-consuming and can delay the treatment of severe hyperkalemia on time. So, we propose a non-invasive method for correct and rapid hyperkalemia detection.

Methods:

The cardiac signal of patients referred to the Pediatrics Emergency room of Shahid Rejaee Hospital was measured by a 12-lead Philips electrocardiogram (ECG) device. Immediately, the blood samples of the patients were sent to the laboratory for potassium serum level determination. We defined 16 features for each cardiac signal at lead 2 and extracted them automatically using the algorithm developed. With the help of the principal component analysis (PCA) algorithm, the dimension reduction operation was performed. The algorithms of decision tree (DT), random forest (RF), logistic regression, and support vector machine (SVM) were used to classify serum potassium levels. Finally, we used the receiver operation characteristic (ROC) curve to display the results

Results:

In the period of 5 months, 126 patients with a serum level above 4.5 (hyperkalemia) and 152 patients with a serum potassium level below 4.5 (normal potassium) were included in the study. Classification with the help of a RF algorithm has the best result. Accuracy, Precision, Recall, F1, and area under the curve (AUC) of this algorithm are 0.71, 0.87, 0.53, 0.66, and 0.69, respectively

Conclusions:

A lead2-based RF classification model may help clinicians to rapidly detect severe dyskalemias as a non-invasive method and prevent life-threatening cardiac conditions due to hyperkalemia.

Hyperkalemia
machine learning algorithms
potassium serum level
==== Body
pmcIntroduction

Heart diseases are the first cause of death worldwide.[1] According to the statistics of the World Health Organization (WHO), 17.9 million people die every year due to heart disease. Heart failure is the final stage of many heart diseases and is associated with a high prevalence.[234] Abnormal serum levels of potassium lead to changes in myocardial cell action potentials which are associated with an increased risk of ventricular arrhythmias.[5678] However, it also increases mortality in patients with myocardial infarction and plays an important role in the outcome of cardiovascular patients. Potassium disorder causes cardiovascular, neuromuscular, renal, and metabolic diseases.[9]

In the pediatric group, hyperkalemia is more common in children with cardiac and kidney disease, especially in patients who need intensive care unit. As a potassium disorder, hyperkalemia is a common electrolyte abnormality associated with cardiovascular complications and increased mortality. About 2–5% of hospitalized patients have hyperkalemia. Traditionally, hyperkalemia is diagnosed with a blood sampling test. Electrocardiogram (ECG) as a fast, non-invasive, and accessible method may show changes in serum potassium indicating electrical changes associated with ECG.[910] Hyperkalemia causes ECG changes not only through its direct myocardial effects but also indirectly through other mechanisms including anoxia, acid-base abnormalities, and other systemic disorders.[11]

Prediction of hyperkalemia is challenging as it is affected by many parameters. Previous work employed machine learning (ML) to predict hyperkalemia. For example, in 2020, 66321 cardiac signals were analyzed to determine the potassium level.[9] In this study, with the help of deep learning, hyperkalemia was distinguished from normal potassium with high accuracy (84.5%). Similarly, a group of researchers using lead I and II succeeded in diagnosing hyperkalemia with the help of a deep convolutional neural network.[12] Conner D. Galloway managed to classify the potassium level into two groups, normal and hyperkalemia, using the information of two leads I and II.[13] In 2019, Giuseppe Regolisti and his colleagues investigated the determination of potassium levels with the help of ECG using T-wave characteristics.[14]

Until now, the methods that have been presented to measure the different analytes such as drug derivatives, amino acids, food additives, and especially potassium levels have been based entirely on the technology of sensor design[151617] and laboratory kits. Laboratory tests are expensive and require specialized equipment and infrastructure, such as trained medical staff for blood sampling and hematology analyzers for biochemical reagent evaluation. The use of these methods, while requiring a blood sample, is invasive, expensive, and time-consuming to get the test results. Many studies have shown that the imbalance of electrolytes changes the shape of the ECG.[8] In this study, we will develop and present a method for non-invasive and real-time diagnosis of hyperkalemia in patients with myocardial failure.

Methods

This study was conducted over a period of 12 months at Shahid Rajaei Hospital. During this time, patients referred to pediatric emergency were studied. The cardiac signal is measured by a 12-lead device (Phillips) with 25 mm/ss sampling. Blood sampling for potassium levels was also carried out at the same time. Patients whose ECG had noise and artifacts for any reason were excluded from the study. The information of the eligible subjects, including the basic demographic information, has been collected through interviews and questionnaires. We divided patients into two groups: patients with a normal level of serum potassium mean potassium level less than 4.5 (mmol/L) and patients with a potassium level more than 4.5 (mmol/L) as hyperkalemia. In this study, we only used the lead II signal. An algorithm based on Python programming language was designed and developed to automatically extract the features of the heart signal. Patients with any electrolyte disturbance or other systemic conditions that had a major effect on ECG signals were excluded from the study.

Feature extraction

The heart signal of lead 2 of each patient was recorded for a period of 2.8 s. We developed a program in Python (with the help of scipy.signal library[18]) to extract the amplitude and time values of P, Q, R, S, and T.

As shown in Figure 1, 16 features for each ECG signal were then calculated (P-Width, PQ, PR, PS, PT, QR, QRS, QT, RS, RT, ST, T-Width, P-Amplitude, R- Amplitude, S-Amplitude, T-Amplitude).

Figure 1 Display of features extracted from cardiac signal

Dimension reduction

All analysis was performed using Python 3.10 in the visual studio code 1.78.2.0 (microsoft/vscode) (VSCode) environment. Data were normalized by the following formula (by using Sklearns min-max-scaler[13]):

In each data set, there is a possibility of having two highly correlated features. Two identical features naturally create additional redundancy. To avoid this, dimensionality reduction algorithms can be used. We used the most important dimensionality reduction algorithms, linear and non-linear (principal component analysis (PCA), linear discriminant analysis (LDA), multi-dimensional scaling (MDS), isometric feature mapping (Isomap), locally linear embedding (LLE), Kernel PCA). The best result was obtained by adopting the PCA algorithm.

Classification

We used support vector machine (SVM), decision tree (DT), random forest (RF), and logistic regression algorithms to classify this group of data. We optimized the parameters of each algorithm with the help of the GridSearchCV method from the Sklearn Python library [13]. To better evaluate the model, we used the Monte Carlo cross-validation algorithm. The data set is randomly divided into two parts, training and validation. Then, the parameters of the model are estimated based on the training data, and the error or accuracy of the model is also calculated with the help of the validation data. In each iteration, 20 cases were assigned to the validation group. This operation was repeated 13 times.

In Figure 2, the general chart of the study steps is shown.

Figure 2 General chart of the study steps

Results

In 12 months, 126 patients with hyperkalemia and 152 patients with serum potassium levels below 4.5 were selected. The choice of this number of subjects is to ensure balance between the two groups. About 52% of the community was boys and 48% were girls. These people were between 1 and 14 years old.

In PCA, the key parameter that is considered to decide the number of basis vectors is variance. According to Figure 3, by reducing the input set to four, 95.1% of the input variance is guaranteed, so the value of k (amount of eigenvectors) was considered to be 4.

Figure 3 Explained variance by different principal components

The definition of precision, accuracy, recall, and F1 is as follows[12]:

The results of applying each of the classification algorithms are shown in Table 1. As shown, the SVM method has the lowest accuracy and the RF has the highest measurement accuracy.

Table 1 Comparison between four classification algorithms

Algorithm	Accuracy	Precision	Recall	F1	AUC	
DT	0.65	0.63	0.7	0.66	0.65	
SVM	0.6	0.7	0.45	0.55	0.61	
RF	0.74	0.83	0.54	0.66	0.69	
LR	0.65	0.625	0.56	0.58	0.64	

The F1 score comprehensively includes both precision and recall and is equal to the harmonic mean of the two. Therefore, the F1 score is considered more valid than precision or recall alone. F1 score in DT and RF algorithms is better than other algorithms. In this situation, the area under the curve (AUC) of the receiver operation characteristic (ROC) is a unified measurement criterion that is often used in binary classification.[12] ROC is a measurement of the tradeoff between a True Positive Rate and a False Positive Rate at different classification thresholds. The evaluation of the classification algorithms is shown in Figure 4 with the help of the ROC diagram. The highest value of AUC is obtained by using the RF algorithm. Therefore, if the selection criterion is based on the ROC curve and AUC, the RF algorithm has the best result. Confusion Matrices of RF, the best algorithm in this study, are shown in Figure 5.

Figure 4 Validation data set performance for Hyperkalemia from lead II

Figure 5 Confusion matrix for RF classification algorithm: 260 testing samples by helping Monte Carlo cross-validation algorithm

Discussion

The normal function of cardiac myocardium depends on many factors including normal serum electrolytes. In critically ill patients, on-time diagnosis and treatment of hyperkalemia is necessary. In the past, serial serum potassium level check with blood sampling was a practical method for potassium monitoring. Currently, the trend is to monitor potassium levels with rapid non-invasive techniques. However, there is always doubt about the accuracy of these methods for the true diagnosis of hyperkalemia. Through this work, we have developed and presented a non-invasive model that can predict hyperkalemia in this group of patients with acceptable accuracy.[314]

Classifying normal potassium from hyperkalemia (one of the most common electrolyte disorders in patients) accurately and quickly using biomarkers has a profound impact on many patients’ lives. This issue is especially very important in children with critical conditions in the intensive care unit because the burden of systemic illness leads to hyperkalemia which can affect cardiac function very rapidly. Therefore, improving the accuracy of early diagnosis of hyperkalemia is very important. We applied several ML classification methods to systematically examine a list of cardiac signal variables to select the most relevant features for predicting hyperkalemia. Then, a model was deduced with the help of a RF algorithm by training it. As shown in the results, the combination of several DTs and the subsequent creation of the RF algorithm is effective in improving the results.

So far, many attempts have been made in the field of hyperkalemia detection with the help of ML algorithms. Most of these efforts have been performed on the ECG signal. In 2022, Lin, Chin, and colleagues succeeded in diagnosing hyperkalemia with 84.5% accuracy with the help of deep learning.[9] One of the reasons for the high accuracy in this study is the definition of potassium above 6.5 as hyperkalemia. In this range, the effect of high potassium in the cardiac waveform is quite evident. Consequently, it may be too late for on-time management and effective therapy of hyperkalemia. However, in our work, this number was considered 4.5. Using the information of two leads (I and II) and defining a potassium level of 5 as the threshold of hyperkalemia, a sensitivity of 85% and specificity of 72 was reported, in 2018.[14] Similar to our findings, they acknowledged the ability of artificial intelligence to detect hyperkalemia.

Connor D. Galloway and his colleagues extended their work using a deep convolutional neural network algorithm.[19] They considered serum potassium levels above 5.5 as hyperkalemia. The effects of serum potassium on the cardiac signal are more evident at this level than potassium.

Giuseppe Regolisti and his colleagues investigated hyperkalemia with the help of ECG using T-wave characteristics.[20] They considered a serum potassium level above 5.5 as hyperkalemia. Poor prediction accuracy of potassium levels using T-wave was the result of their study.

We developed a RF model for hyperkalemia detection using the LEAD2 approach in the pediatric group. This model helps emergency physicians quickly diagnose hyperkalemia and severe hyperkalemia. This study has limitations such as a limited patient population. We hope to extend this work to include an internationally mixed-race study with a high statistical population in the future.

Author contributions

“Conceptualization, M.K. and N.O.; methodology, H.M.T.; software, H.M.T.; validation, M.K and N.O.; formal analysis, M.A. and H.M.T.; investigation, H.M.T., M.K., and N.O.; resources, M.K and N.O.; writing—original draft preparation, M.K, M.A, and H.M.T.; writing—review and editing, M.A and M.K.; visualization, H.M.T.; supervision, M.A.; project administration, M.A. All authors have read and agreed to the published version of the manuscript.”

Institutional review board statement

This research has been approved by the ethics committee of Shahid Beheshti University of Medical Sciences (IR.SBMU.MSP.REC.1398.982) and all patient information will be kept confidential.

Informed Consent Statement: “Informed consent was obtained from all subjects involved in the study.”

Data availability statement

Data available on request due to privacy and ethical restrictions.

Limitation of the study

There is no limitation.

Financial support and sponsorship

Nil.

Conflicts of interest

There are no conflicts of interest.

Acknowledgments

This article has been extracted from a thesis written by Mr. Hamid Mokhtari Torshizi in the School of Medicine, Shahid Beheshti University of Medical Sciences (Registration No. M982).
==== Refs
1 Heidenreich PA Trogdon JG Khavjou OA Butler J Dracup K Ezekowitz MD Forecasting the future of cardiovascular disease in the United States: A policy statement from the American Heart Association Circulation 2011 123 933 44 21262990
2 Fotos NV Giakoumidakis K Kollia Z Galanis P Copanitsanou P Pananoudaki E Health-related quality of life of patients with severe heart failure. A cross-sectional multicentre study Scand J Caring Sci 2013 27 686 94 23004008
3 Alper AB Campbell RC Anker SD Bakris G Wahle C Love TE A propensity-matched study of low serum potassium and mortality in older adults with chronic heart failure Int J Cardiol 2009 137 1 8 doi: 10.1016/j.ijcard. 2008.05.047 18691778
4 Bielecka-Dabrowa A Mikhailidis DP Jones L Rysz J Aronow WS Banach M The meaning of hypokalemia in heart failure Int J Cardiol 2012 158 12 7 21775000
5 Gheorghiade M Vaduganathan M Fonarow GC Bonow RO Rehospitalization for heart failure: Problems and perspectives J Am Coll Cardiol 2013 61 391 403 23219302
6 Gotsman I Zwas D Planer D Azaz-Livshits T Admon D Lotan C Clinical outcome of patients with heart failure and preserved left ventricular function Am J Med 2008 121 997 1001 18954847
7 Mattsson N Sadjadieh G Kumarathurai P Nielsen OW Køber L Sajadieh AJE Ambulatory cardiac arrhythmias in relation to mild hypokalaemia and prognosis in community dwelling middle-aged and elderly subjects Europace 2016 18 585 91 26293625
8 Liamis G Rodenburg EM Hofman A Zietse R Stricker BH Hoorn EJ Electrolyte disorders in community subjects: Prevalence and risk factors Am J Med 2013 126 256 63 23332973
9 Lin C Chau T Lin C-S Shang H-S Fang W-H Lee D-J Point-of-care artificial intelligence-enabled ECG for dyskalemia: A retrospective cohort analysis for accuracy and outcome prediction NPJ Digit Med 2022 5 8 doi: 10.1038/s41746-021-00550-0 35046489
10 Krogager ML Kragholm K Skals RK Mortensen RN Polcwiartek C Graff C The relationship between serum potassium concentrations and electrocardiographic characteristics in 163,547 individuals from primary care J Electrocardiol 2019 57 104 11 31629993
11 Ziakas A Basagiannis C Stiliadis I Pseudoinfarction pattern in a patient with hyperkalemia, diabetic ketoacidosis and normal coronary vessels: A case report J Med Case Rep 2010 4 1 4 doi: 10.1186/1752-1947-4-115 20205797
12 Liu YH Python Machine Learning by Example 35 Livery Street, Birmingham, B3 2PB UK Packt Publishing Ltd 2017
13 Pedregosa F Varoquaux G Gramfort A Michel V Thirion B Grisel O Scikit-learn: Machine learning in Python J Mach Learn Res 2011 12 2825 30
14 Galloway CD Valys AV Petterson FL Gundotra VP Treiman DL Albert DE Non-invasive detection of hyperkalemia with a smartphone electrocardiogram and artificial intelligence J Am Coll Cardiol 2018 71 A272 A
15 Gholipour A Jahanshahi M Emadi H Synthesis of carbon quantum dots and Fe-doped carbon quantum dots as fluorescent probes via one-step microwave process for rapid and accurate detection of Diclofenac sodium J Cluster Sci 2023 35 237 51
16 Gholipour A Rahmani S The green synthesis of carbon quantum dots through one-step hydrothermal approach by orange juice for rapid, and accurate detection of dopamine J Fluoresc 2023 1 3 doi: 10.1007/s10895-023-03483-x
17 Gholipour A Rahmani S The synthesis of fluorescent carbon quantum dots for tartrazine detection in food: A novel one-step microwave heating approach Fullerenes, Nanotubes and Carbon Nanostructures 2023 31 743 51
18 Virtanen P Gommers R Oliphant TE Haberland M Reddy T Cournapeau D SciPy 1.0: Fundamental algorithms for scientific computing in Python Nat Methods 2020 17 261 72 32015543
19 Galloway CD Valys AV Shreibati JB Treiman DL Petterson FL Gundotra VP Development and validation of a deep-learning model to screen for hyperkalemia from the electrocardiogram JAMA Cardiol 2019 4 428 36 30942845
20 Regolisti G Maggiore U Greco P Maccari C Parenti E Di Mario F Electrocardiographic T wave alterations and prediction of hyperkalemia in patients with acute kidney injury Intern Emerg Med 2020 15 463 72 31686358
