Artificial intelligence based model for Automatic Real-Time and Non-Invasive Estimation of blood potassium level in pediatric patients

Hamid Mokhtari Torshizi1, Negar Omidi2, Mohammad Rafie Khorgami3,Fattaneh Khalaj4, Mohsen Ahmadi5*

1PhD student of Biomedical Engineering and Physics Department, School of Medicine, Shahid Beheshti University of Medical Sciences, Tehran, Iran
2Associate Professor of Cardiology, Department of Cardiology, School of Medicine, Tehran Heart Center, Tehran University of Medical Sciences, Tehran, Iran
3Rajaie Heart Center and Department of Pediatric Cardiology, School of Medicine, Iran University of Medical Sciences, Tehran, Iran
4Digestive Disease Research Center, Digestive Disease Research Institute, Tehran University of Medical Sciences, Tehran, Iran
5Associate professor, Department of Biomedical Engineering, School of Medicine, Shahid Beheshti University of Medical Sciences, Tehran, Iran.

*Corresponding author

Mohsen Ahmadi, MD , Associate professor, Department of Biomedical Engineering, School of Medicine,
Shahid Beheshti University of Medical Sciences, Tehran, Iran.


Objective: During the last decade, heart disease has become the main cause of death worldwide. One of the main causes of mortality in pediatric patients, especially in the intensive care unit, is related to cardiac arrhythmia. An abnormal variation in blood electrolytes, such as potassium, contributes to mortality in pediatric patients. Continuous and real-time monitoring of potassium serum levels can prevent fatal arrhythmias but this is not currently practical. Our Real-Time and Non-Invasive ECG-related technique uses machine learning to estimate blood potassium with good accuracy.

Patients and Methods: Hospitalized patients in emergency department of the Rajai  Cardiology and Medical Research Center  and Tehran Heart Center were recruited from December 2021 to June 2022.The electrocardiographic(ECG) features of patients were evaluated. We defined 16 features for each signal and extracted them automatically. With the assistance of the correlation matrix, the dimension reduction operation was performed. Linear regression, polynomials, decision trees, random forests, and support vector machine(SVM) algorithms have been used to find the relationship between characteristics and serum potassium levels. Finally, we used a scatter plot and mean square error (MSE) to display the results.

Results: ECG of 428 patients was analyzed. Random Forest Regression algorithm has the best estimate with an MSE of 0.3.

Conclusion: Accurate estimation of serum potassium level based on ECG signals is possible. This can potentially be a useful tool in predicting serum potassium level in specific patients.

Keywords: Serum potassium level, Machine learning, Regression model, Non-Invasive Estimation


As one of the main electrolytes, potassium plays an important role in cellular membrane potential variations, especially in the heart (1). Normal cardiac function depends on regular sequential cardiac myocyte depolarization and repolarization. Any disruption in this circle may lead to cardiac conduction disorders and severe arrhythmia. The manifestation of these changes in the ECG signal is usually related to potassium concentration measured as potassium blood level (2). Children with cardiac and kidney diseases are more susceptible to the effects of potassium changes (3). Factors such as acute systemic illness, injection of potassium for electrolyte balance, and drugs and medicine intake can cause acute changes in potassium blood levels.

It should be noted that 98% of K+ is intracellular (140 mEq/l), and 2% is extracellular (3.8 to 5.0 mEq/l) (4). Hypokalemia is the most common electrolyte imbalance in cardiac patients, delaying ventricular repolarization and downgrading conduction velocity, especially at the atrioventricular node. This can lead to various arrhythmias, such as sinus bradycardia and atrioventricular block (5, 6). Also, hypokalemia can increase atrial and ventricular ectopic pulses and enhance digoxin’s toxic effect (7).

Until today, K+ levels have been measured in blood serum or plasma (for example: (8-12)). Blood sampling in children is a harmful process especially when frequent sampling is required. In some ICU conditions this much blood sampling results in anemia or unwanted cyanosis or apnea in children with congenital heart diseases. Furthermore, this method is invasive, expensive, and requires blood samples and some time to get the test results. On the other hand, Serum K+ measurements require clotting before analysis. Therefore, an abnormal potassium level may be reported due to hemolysis which occurs if long waiting periods before the analysis takes place. This can yield miss corrected blood samples (13-15).

In the face of these challenges, we recently designed a method for serum potassium concentration quantification ([K+]) from ECG analysis. In the past, many studies have been done on the heart signal with the help of machine learning algorithms (for example: (16-21)). In this study, our [K+] estimator was validated and tested on a large group of patients. Potassium value extraction using a single lead would permit its use in wearable, wireless ECG patches and possibly in implantable loop recorders and cardiac implantable electronic devices (pacemakers and defibrillators)


The studied community

In Total 428 hospitalized patients in the Rajai Cardiology and Medical Research Center and Tehran Heart Center emergency department were recruited from December 2021 to June 2022. The electrocardiographic (ECG) features of patients were evaluated. The patient’s serum K level, ECG, and serum sample were taken within 2 hours of admission. Patients having a history of heart failure, end stage renal disease, bundle branch block, strain pattern in ECG, premature ventricular contraction, and digoxin use were excluded from the study. A specialist nurse took ECGs which were stored in files based on age and gender. Patients whose ECGs had noise or artifacts for any reason were excluded from the study too. Information about the eligible patients, including their basic demographic information, has been collected through interviews and questionnaires.

Feature Extraction

We recorded each patient’s heart signal over 2.8 seconds using a Saadat ECG machine (12 channels). To analyze the heart signals, the data was transferred from the device’s memory to an external memory. We then developed a program in Python language on the Windows platform that can extract the amplitude and time values of P, Q, R, S, and T (the sequence of steps is shown in Figure 1). In total, 16 features were calculated using these points.

RtoT  variable was defined as: The difference between the amplitude of the T wave and R wave

Dimensional reduction 

The cross-correlation matrix was used for dimensionality reduction. For every two signal features with a correlation greater than 0.7, one was removed (Fig 3).


We used z-score standardization according to the following formula:

  • is a data point (x1, x2 … xn)
  • is the sample mean
  • S is the sample standard deviation

2-5 Regression

A Regression model is one of the most common types of supervised learning in Machine Learning. When evaluating the linear relationship between the ECG characteristics and potassium serum level, we used the Pearson Correlation Coefficient and evaluated the non-linear relationship using Decision Trees and Random Forest algorithms. Python version 3 was used for cardiac signal processing.

SVR, Decision Tree, Random Forest, Linear Regression, and Polynomial Regression algorithms were used to test the linear and non-linear relationship between characteristics and potassium serum level. Based on the results, the Random Forest algorithm has the best performance in this research.

Random Forest:

It is a group learning method that involves combining several trees. Each tree is trained, and several random features are sampled at each tree node. The average of the regression results from all the decision trees is assigned to the final decision.

Model Validation:

In this study, we used 20% of the population as a test sample. The estimated potassium level was calculated from the obtained ECG data using the corresponding patient-specific potassium prediction model developed during the training phase. To assess the accuracy, we calculated the mean absolute error, which is the mean absolute value of the difference between the estimated and measured potassium for each patient.


Among the 463 patients who were admitted to the hospitals in 1 years, 35 patients were excluded from the study due to high noise and distortion of the heart signal. In our community, 56% were boys and 44% were girls. The potassium chart of these patients is shown in Figure 2. The results of the cross-correlation matrix of data are shown in Fig. 3.

Figure 2: Histogram of blood potassium serum level.

Figure 3: Cross-correlation matrix.

Based on the information in Figure 3, we remove one of the two parameters that correlate more than 0.7. PR, Ps, PT, Twidth, QS, QR, QT, RS, RT, ST, and RtoT are variables that we use to teach regression methods. Table 1 shows the efficiency of each regression algorithm based on the MSE. As indicated in the table, the polynomial method has the lowest accuracy, and the random forest method has the highest measurement accuracy.

Table 1: Efficiency of regression methods based on MSE.

Considering that most of our studied patients have a potassium level between 4 and 4.5, we use the scatter diagram to get better feedback than regression methods. Figure 4, shows the scatter diagram for different approaches.

Figure 4: Scatter diagram of different methods.

Another important goal of this study is to calculate the importance of each feature in determining the level of potassium. In Figure 5, the importance of each feature by the random forest algorithm is shown in percentage terms. Figure 6 shows how the decision tree algorithm yields decisions.

Figure 5: Features` importance by the random forest algorithm

Figure 6: How to allocate blood serum potassium level based on the input characteristics in the decision tree algorithm


Acute electrolyte disturbance especially hyperkalemia in pediatrics is life-threatening and requires prompt attention. As well as the correct determination of K level, the on-time result is also critical because many children with acute ill conditions need immediate medical attention. Blood sampling is a well-known reliable method for the evaluation of this electrolyte. Yet, evaluation of K level has always been desirable and attempts have been made for K level determination with high accuracy and sensitivity.

The effect of potassium on the ECG cardiac signal has been known for many years (22-24). So far, several studies, generally based on T-wave morphology, have been conducted to determine serum potassium levels (25-29). ECG markers, which are defined as a specific time interval or range of neural signals, are prone to noise (30). To solve this problem, many studies have investigated T wave morphology over a long period of time (31-33). Major challenges with these studies have been the definition of morphologies based on complex mathematical rules, the long time to calculate optimal parameters (several hours), and the low statistical population.

Another group of studies has investigated blood potassium based on ECG and using deep learning algorithms. In this class of studies, only hyperkalemia is detected at high potassium levels.

The purpose of this study is to design and validate an online and non-invasive potassium level extraction technique based on machine learning algorithm. We allocated 2.8 seconds to determine the serum level of potassium. This time interval ensures that several cardiac cycles are considered. Another strength of this study is the application of two stages of filtering to remove the effect of unwanted distortion on heart signal parameters. Therefore, if a part of the signal is distorted, the result of evaluating the potassium level is still reliable. Another advantage of this method is that only one lead is considered. This helps to commercialize the mentioned method and assess the potassium level remotely. Considering the high number of subjects in the studied population, it can be assumed that all T-wave morphologies were covered. We are developing our algorithm in such a way that we can analyze different types of ECG signals.

So far, attempts have been made to measure blood potassium levels using cardiac signals. Shakil Aslam and her colleagues conducted a study on 74 end-stage renal disease (ESRD) patients in 2002 (22). In their study, they tried to provide a linear relationship between T-wave amplitude or T-wave to R-wave ratio and the serum level of potassium in a patient's blood. In the same way that Szerlip et al. (34), could not provide a relationship between the T wave to R wave ratio and the level of serum potassium in the blood of individuals.

In 2018, with the introduction of two parameters, T-right slope, and T-amp, a group of researchers tried to discover the potassium serum level with ECG (35). By examining two parameters (T-amp and T-right slope) on five lead waveforms (V3, V4, V5, V6, and II), they found that T-wave-based features were not correlated with serum potassium level.

Omar Z. Yasin, MD, and her colleagues investigated the potassium serum level and heart signal of 21 dialysis patients (36). The average absolute error between estimated and blood potassium was 0.38- 0.32 mEq/L. The sample size of our study and the wide range of serum potassium levels are the strengths of our work compared to theirs.

John J. Dillon and his colleagues tried to quantify the amount of potassium using the cardiac signal and the serum level of potassium in the blood of 12 patients (29). They used the following variables for the regression operator in their work: The slope of the T wave down stroke (T right slope), the amplitude of the T wave (T amplitude), the center of gravity (COG) of the T wave (T COG), the ratio of the amplitude of the T wave to the amplitude of the R wave (T/R amplitude), and the center of gravity of the last 25% of the area under the T wave curve (T4 COG). However, they have recommended the use of the cardiac signal as a non-invasive method. Yet, due to the small sample size of their study, more research is required. In our study, we tried to overcome the weaknesses of previous studies by considering a large statistical population with a wide range of serum potassium levels, more features of the cardiac signal, and applying machine learning methods.

The high statistical community of this study has made it possible to examine all the clinical factors of the cardiac signal. Based on the results presented in Figures 5 and 6, the PT parameter is considered as the most important influencing factor in predicting the amount of potassium. This means that the combination of PQ, QRS, and ST intervals is influential. However, the second most important parameter in determining serum potassium levels is the difference in R and T wave amplitudes. This finding is similar to studies that have considered the slope of the T wave as an important parameter in the determination of serum potassium.

As shown in Figure 4, the linear and polynomial methods that were used in most studies do not have adequate predictive power. Although the Polynomial method has high accuracy in the training phase, it has the lowest accuracy in the test phase (Table 1). This is caused by the phenomenon of overfitting. The linear method also predicts all values in the range of 4 to 4.5 mmol. Although the decision tree method works well for wide potassium levels, it is not suitable for low potassium (under 4 mmol). Prediction of potassium level through the SVR method only works somewhat well in medium values. But the random forest method has solved the problem of the decision tree algorithm to a great extent, and has improved the detection of potassium in low amounts. Finally, it can be said that in this study, the random forest algorithm is more efficient than other algorithms.

Besides to potassium, other factors such as other electrolytes and the location of the leads affect the cardiac signal. Despite the presence of all the sources influencing the cardiac signal, we managed to calculate the serum potassium level with an average error of 0.3 in this study. Perhaps, in future studies, the effect of other electrolytes on ECG can be processed and by considering their effects on the cardiac signal, an increase in the accuracy of predicting blood potassium can be attained.


In conclusion, we defined a comprehensive noninvasive method for evaluating of k level in pediatrics based on ECG signal. This study may start a noninvasive portable method for the determination of K level by monitoring ECG signal results and fast measurement of k level changes in response to systemic conditions in acute ill adult and child groups.

Declaration: The authors declare that they have no known competing financial interests.

Conflict of interest statement: The authors have no conflicts to disclose


  1. Joukar SJLAR. A comparative review on heart ion channels, action potentials and electrocardiogram in rodents and human: extrapolation of experimental insights to clinic. 2021;37(1):1-15.
  2. Raffee LA, Alawneh KZ, Ababneh MJ, Hijazi HH, Al Abdi RM, Aboozour MM, et al. Clinical and electrocardiogram presentations of patients with high serum potassium concentrations within emergency settings: a prospective study. 2022;15(1):23.
  3. Wieërs ML, Mulder J, Rotmans JI, Hoorn EJJPN. Potassium and the kidney: a reciprocal relationship with clinical relevance. 2022;37(10):2245-54.
  4. Ferreira JP, Butler J, Rossignol P, Pitt B, Anker SD, Kosiborod M, et al. Abnormalities of potassium in heart failure: JACC state-of-the-art review. Journal of the American College of Cardiology. 2020;75(22):2836-50.
  5. Michaud GF, Sticherling C, Tada H, Oral H, Pelosi Jr F, Knight BP, et al. Relationship between serum potassium concentration and risk of recurrent ventricular tachycardia or ventricular fibrillation. Journal of cardiovascular electrophysiology. 2001;12(10):1109-12.
  6. Fisch C, Knoebel SB, Feigenbaum H, Greenspan K. Potassium and the monophasic action potential, electrocardiogram, conduction and arrhythmias. Progress in Cardiovascular Diseases. 1966;8(5):387-418.
  7. Aghajani M, Imani A, Kardar G, Faghihi M, Aghajani MJCP. Unfavorable left ventricular remodeling due to experience of chronic sleep restriction after myocardial infarction: The role of matrix metalloproteinases & oxidative stress. 2023;62:107460.
  8. Lima AS, Bocchi N, Gomes HM, Teixeira MFJS. An electrochemical sensor based on nanostructured hollandite-type manganese oxide for detection of potassium ions. 2009;9(9):6613-25.
  9. Meshik X, Xu K, Dutta M, Stroscio MAJIton. Optical detection of lead and potassium ions using a quantum-dot-based aptamer nanosensor. 2014;13(2):161-4.
  10. Zhang L, Chen S, Zhao Q, Huang HJAca. Carbon dots as a fluorescent probe for label-free detection of physiological potassium level in human serum and red blood cells. 2015;880:130-5.
  11. Rahimi M, Mahani M, Hassani ZJL. Carbon quantum dots fluorescence quenching for potassium optode construction. 2019;34(4):402-6.
  12. Kollegger C, Greiner P, Siegl I, Steffan C, Wiessflecker M, Pekec B, et al. Intelligent NFC potassium measurement strip with hemolysis check in capillary blood. 2018;135(1):83-8.
  13. Meng QH, Wagar EA. Pseudohyperkalemia: a new twist on an old phenomenon. Critical Reviews in Clinical Laboratory Sciences. 2015;52(2):45-55.
  14. Cooper LB, Savarese G, Carrero J-J, Szabo B, Jernberg T, Jonsson Å, et al. Clinical and research implications of serum versus plasma potassium measurements. European journal of heart failure. 2019;21(4):536-7.
  15. Hawkins R. Measurement of whole-blood potassium—is it clinically safe? Clinical chemistry. 2003;49(12):2105-6.
  16. Salari N, Hosseinian-Far A, Mohammadi M, Ghasemi H, Khazaie H, Daneshkhah A, et al. Detection of sleep apnea using Machine learning algorithms based on ECG Signals: A comprehensive systematic review. 2022;187:115950.
  17. Chakraborty A, Chatterjee S, Majumder K, Shaw RN, Ghosh A, editors. A comparative study of myocardial infarction detection from ECG data using machine learning. Advanced Computing and Intelligent Technologies: Proceedings of ICACIT 2021; 2022: Springer.
  18. Udawat AS, Singh PJJoE. An automated detection of atrial fibrillation from single‑lead ECG using HRV features and machine learning. 2022;75:70-81.
  19. Marzog HA, Abd HJ. ECG-Signal classification using efficient machine learning approach. In2022 International Congress on Human-Computer Interaction, Optimization and Robotic Applications (HORA) 2022 Jun 9 (pp. 1-7). IEEE.
  20. Ulloa-Cerna AE, Jing L, Pfeifer JM, Raghunath S, Ruhl JA, Rocha DB, et al. RECHOmmend: an ECG-based machine learning approach for identifying patients at increased risk of undiagnosed structural heart disease detectable by echocardiography. 2022;146(1):36-47.
  21. Rizwan A, Priyanga P, Abualsauod EH, Zafrullah SN, Serbaya SH, Halifa AJCI, et al. A machine learning approach for the detection of QRS Complexes in Electrocardiogram (ECG) using Discrete Wavelet Transform (DWT) algorithm. 2022;2022.
  22. Lanari A, Chait LO, Capurro CJAhj. Electrocardiographic effects of potassium. I. Perfusion through the coronary bed. 1964;67(3):357-63.
  23. LAKS MM, ELEK SRJDotC. The effect of potassium on the electrocardiogram: clinical and transmembrane correlations. 1967;51(6):573-86.
  24. El-Sherif N, Turitto GJCj. Electrolyte disorders and arrhythmogenesis. 2011;18(3):233-45.
  25. Attia ZI, DeSimone CV, Dillon JJ, Sapir Y, Somers VK, Dugan JL, et al. Novel bloodless potassium determination using a signal‐processed single‐lead ECG. 2016;5(1):e002746.
  26. Severi S, Corsi C, Haigney M, DeBie J, Mortara D, editors. Noninvasive potassium measurements from ECG analysis during hemodialysis sessions. 2009 36th Annual Computers in Cardiology Conference (CinC); 2009: IEEE.
  27. Corsi C, DeBie J, Napolitano C, Priori S, Mortara D, Severi S, editors. Validation of a novel method for non-invasive blood potassium quantification from the ECG. 2012 Computing in Cardiology; 2012: IEEE.
  28. Corsi C, Cortesi M, Callisesi G, De Bie J, Napolitano C, Santoro A, et al. Noninvasive quantification of blood potassium concentration from ECG in hemodialysis patients. 2017;7(1):1-10.
  29. Dillon JJ, DeSimone CV, Sapir Y, Somers VK, Dugan JL, Bruce CJ, et al. Noninvasive potassium determination using a mathematically processed ECG: Proof of concept for a novel “blood-less, blood test”. 2015;48(1):12-8.
  30. Palmieri F, Gomis P, Ferreira D, Ruiz JE, Bergasa B, Martín-Yebra A, et al. Monitoring blood potassium concentration in hemodialysis patients by quantifying T-wave morphology dynamics. 2021;11(1):3883.
  31. Bukhari HA, Sánchez C, Srinivasan S, Palmieri F, Potse M, Laguna P, et al. Estimation of potassium levels in hemodialysis patients by T wave nonlinear dynamics and morphology markers. 2022;143:105304.
  32. Palmieri F, Gomis P, Ruiz JE, Ferreira D, Martín-Yebra A, Pueyo E, et al. ECG-based monitoring of blood potassium concentration: Periodic versus principal component as lead transformation for biomarker robustness. 2021;68:102719.
  33. Rodrigues AS, Petrėnas A, Paliakaitė B, Kušleikaitė-Pere N, Jaruševičius G, Bumblytė IA, et al. Noninvasive monitoring of potassium fluctuations during the long interdialytic interval. 2020;8:188488-502.
  34. Szerlip HM, Weiss J, Singer IJAJoKD. Profound hyperkalemia without electrocardiographic manifestations. 1986;7(6):461-5.
  35. Chen H, Maharatna KJIJoB, Informatics H. An automatic R and T peak detection method based on the combination of hierarchical clustering and discrete wavelet transform. 2020;24(10):2825-32.
  36. Yasin OZ, Attia Z, Dillon JJ, DeSimone CV, Sapir Y, Dugan J, et al. Noninvasive blood potassium measurement using signal-processed, single-lead ecg acquired from a handheld smartphone. 2017;50(5):620-5.