Full text
52,844 characters
· extracted from
preprint-html
· click to expand
Predicting community-acquired pneumonia outcome using time series data and machine learning | medRxiv /* */ /* */ <!-- <!-- /*! * yepnope1.5.4 * (c) WTFPL, GPLv2 */ (function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f<d;f++)g=a[f].split("="),(e=z[g.shift()])&&(c=e(c,g));for(f=0;f<b;f++)c=x[f](c);return c}function g(a,e,f,g,h){var i=b(a),j=i.autoCallback;i.url.split(".").pop().split("?").shift(),i.bypass||(e&&(e=d(e)?e:e[a]||e[g]||e[a.split("/").pop().split("?")[0]]),i.instead?i.instead(a,e,f,g,h):(y[i.url]?i.noexec=!0:y[i.url]=1,f.load(i.url,i.forceCSS||!i.forceJS&&"css"==i.url.split(".").pop().split("?").shift()?"c":c,i.noexec,i.attrs,i.timeout),(d(e)||d(j))&&f.load(function(){k(),e&&e(i.origUrl,h,g),j&&j(i.origUrl,h,g),y[i.url]=2})))}function h(a,b){function c(a,c){if(a){if(e(a))c||(j=function(){var a=[].slice.call(arguments);k.apply(this,a),l()}),g(a,j,b,0,h);else if(Object(a)===a)for(n in m=function(){var b=0,c;for(c in a)a.hasOwnProperty(c)&&b++;return b}(),a)a.hasOwnProperty(n)&&(!c&&!--m&&(d(j)?j=function(){var a=[].slice.call(arguments);k.apply(this,a),l()}:j[n]=function(a){return function(){var b=[].slice.call(arguments);a&&a.apply(this,b),l()}}(k[n])),g(a[n],j,b,n,h))}else!c&&l()}var h=!!a.test,i=a.load||a.both,j=a.callback||f,k=j,l=a.complete||f,m,n;c(h?a.yep:a.nope,!!i),i&&c(i)}var i,j,l=this.yepnope.loader;if(e(a))g(a,0,l,0);else if(w(a))for(i=0;i (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0];var j=d.createElement(s);var dl=l!='dataLayer'?'&l='+l:'';j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;j.type='text/javascript';j.async=true;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-P4HH5NV'); Skip to main content Home About Submit ALERTS / RSS Search for this keyword Advanced Search Predicting community-acquired pneumonia outcome using time series data and machine learning View ORCID Profile Daniel Lozano-Rojas , View ORCID Profile Matthew Richardson , View ORCID Profile Gerrit Woltmann , View ORCID Profile Robert C. Free doi: https://doi.org/10.1101/2025.03.11.25323764 Daniel Lozano-Rojas 1 Department of Respiratory Sciences, University of Leicester , Leicester, UK 2 NIHR Respiratory BRC Leicester, Department of Respiratory Sciences, University of Leicester , Leicester, UK Find this author on Google Scholar Find this author on PubMed Search for this author on this site ORCID record for Daniel Lozano-Rojas Matthew Richardson 1 Department of Respiratory Sciences, University of Leicester , Leicester, UK 2 NIHR Respiratory BRC Leicester, Department of Respiratory Sciences, University of Leicester , Leicester, UK Find this author on Google Scholar Find this author on PubMed Search for this author on this site ORCID record for Matthew Richardson Gerrit Woltmann 3 Respiratory Medicine Department, Glenfield Hospital , Leicester, UK 4 University Hospitals of Leicester NHS Trust , Leicester Find this author on Google Scholar Find this author on PubMed Search for this author on this site ORCID record for Gerrit Woltmann Robert C. Free 2 NIHR Respiratory BRC Leicester, Department of Respiratory Sciences, University of Leicester , Leicester, UK 5 School of Computing and Mathematical Sciences, University of Leicester , Leicester, UK Find this author on Google Scholar Find this author on PubMed Search for this author on this site ORCID record for Robert C. Free For correspondence: rob.free{at}leicester.ac.uk Abstract Full Text Info/History Metrics Supplementary material Data/Code Preview PDF Abstract Background Community-acquired pneumonia (CAP) is an acute respiratory condition associated with high mortality in adult populations and is potentially more serious in older patients. Accurate and consistently applied prediction of outcome may contribute to reduce in-hospital mortality. Currently, CAP outcomes are assessed with clinical scores like CURB65, based on signs and symptoms that are non-specific to the disease. Recent literature has shown that machine learning (ML) has the potential to improve outcome prediction, but the sparse and incomplete nature of the data present a challenge for the development of models that can be implemented clinically. Methods This study aimed to developed ML models that can support outcome prediction in hospital admissions with CAP using routinely collected and time-dependent data from Leicester hospitals. Thus, by modelling mortality prediction, and predicting URB65 on the third day of admission with the forecast of vital signs, implementing a methodology that explores how different characteristics involved in the training process influence the results of the predictions. Results Data comprised 9390 admissions in the training set, and 7892 in the validation set, for thirty-four clinical variables (fifteen time-dependent). Results of CAP mortality modelling reported AUC of 0.77 using a GRU model that was trained with the time series of vital signs and blood test. Results also showed improvement in models when balancing classes of the target variable in the training set, as well as improvement when using time dependent data. And importantly when predicting URB65 accuracy of 0.85 was obtained when modelled using GRU, when time series were processed using local scaling. Conclusions This approach might represent an opportunity to anticipate adverse outcomes. These results suggest that ML models utilising time series can have sizable impact in the prediction of CAP outcome, from many perspectives: Complementing currently applied scoring systems approaches like CURB65 in hospital settings, prediction of mortality or forecasting the severity of patients from vital signs that have shown correlation with CAP mortality. The models presented require further validation and development, although they present important indication for CAP mortality prediction. Background Pneumonia is an acute inflammatory condition of the lungs, usually caused by bacterial or viral infection which is among the top ten leading causes of mortality worldwide [ 1 ]. It is a substantial public health challenge, contributing not only to high mortality rates but also straining hospital admission resources and Intensive Care Unit (ICU) capacity. Community acquired pneumonia (CAP) results in long-term complications for patients, and imposing substantial financial burdens on healthcare systems [ 3 – 6 ]. In the UK, from 2023-24 there were over 260,000 admissions due to pneumonia, and the NHS reported £1 billion costs associated with pneumonia [ 7 – 8 ]. CAP is a type of pneumonia that affects individuals aged 16 and above who contract an infection before hospital admission. CAP is a particular challenge for older people and makes up most pneumonia cases in the UK [ 6 , 8 ]. Early treatment of CAP is crucial as delayed treatment can lead to adverse outcomes, although these can be improved with proper management and early detection [ 5 ]. In the UK, guidelines support diagnostic confirmation of CAP using chest X-rays. Severity is then assessed using a risk score (CURB65) based on the patient’s symptoms, physiological signs and age. The severity score dictates the level of antibiotics administered and inform the decision where treatment takes place (e.g., intermediate or intensive care units) [ 9 – 11 ]. While the CURB65 score predicts overall mortality, it can underestimate severity in younger patients with low or moderate disease score. Furthermore, it is based on non-specific symptoms and observed values at presentation to admissions, and not on the progression of the infection or response to intervention [ 12 ]. Thus, there is a clear need for novel approaches which can provide more nuanced predictive tools, such as machine learning (ML) [ 13 ]. ML models are mathematical expressions that use data to identify patterns in structured, and unstructured datasets [ 14 ]. These models are then trained using existing data to classify new data using these identified patterns [ 15 ]. Such techniques have gained popularity due to their performance for many problems across different fields, such as image recognition, anomaly detection, mortality prediction, and others [ 16 – 19 ]. In our recent review, we showed that while use of ML has been explored in CAP, this has focussed on diagnosis [ 13 ] and there has been less research into ML techniques for predicting severity and progression; particularly the use of electronic health records to predict outcomes such as mortality, ICU admission or length of stay (LOS). Additionally, multiple challenges remain, including availability of data for replicability, unbalanced data sets, and inadequate approaches for evaluating models. In this study we used routinely collected data from a single National Health Service (NHS) hospital trust to create and evaluate ML models to predict and forecast outcomes in hospital admissions from patients diagnosed with CAP (30-day mortality and CURB65 at the third day of hospitalisation). Here we present the results of our best performing models using different pre-processing approaches and both single time-point and time series data. We then compare our results with other comparable models and identify the strengths and weaknesses of our approach. Methods Data sources Ethical approval for the study was obtained from the regional NHS Research Ethics Committee (IRAS ID: 266731). Anonymised data was extracted from electronic health record (EHR) admissions of patients diagnosed with CAP at the University Hospitals of Leicester (UHL) between 2016, and February 2020. Data collected during the COVID19 pandemic (after February 2020) was excluded. Data was extracted by the National Institute of Health Research (NIHR) Leicester Biomedical Research Centre IT team. CAP patients were identified using appropriate International Classification of Diseases, tenth Revision (ICD-10) codes and a previously described approach [ 20 ]. The ICD-10 codes are listed in supplementary document A. Patients without immunosuppressive conditions (e.g., AIDS, or positive for HIV) and those aged under 16 were excluded. Data pre-processing Data extracted consisted of information from admissions, medical history, vital signs and blood tests (34 variables). It included eight static demographics variables (e.g., age at admission, ethnicity, and mortality) and 26 time series variables (e.g., respiratory rate, blood pressure). Where required, binary mental confusion was determined by deriving it from other scores (e.g., Early Warning Score). Charlson Comorbidity Index was calculated using previously reported weights [ 22 ]. Data was divided into two batches. Batch one (admissions from 2016-2018) was used to train models (training set). Batch two (admissions from 2019 – February 2020) was used to validate models during their development (test set). Data was pre-processed following the process in Figure 1 to produce linked tabular data sets (e.g., delimited comma-separated value files), merging tables, then filtering, cleaning, and interpolating. The same process was undertaken for both the training set and test set. Download figure Open in new tab Figure 1. Process flow of information processing from UHL data extraction to the final dataset used for modelling. Admissions were only included in the data sets if they met the following inclusion criteria: i) diagnosis with CAP (see above); ii) length of stay equal or longer than 3 days; iii) more than 6 records available for both vital signs and blood tests. Data cleaning consisted of bounding data within ranges of features. These ranges were defined based on clinical utility and are presented in supplementary document B). Only blood test variables which were collected in ≥70% of admissions were included. Filtered-cleaned data from time series (vital signs and blood tests) was sparse and uneven, so interpolation was performed to derive values spaced at 30-minute intervals across 3 days. Interpolation took place between the first known value for every variable in each admission to the last. Where more than one value was present in a period, a mean value was calculated. Multiple interpolation methods (linear, polynomial, Akima spline, piecewise cubic Hermite interpolation polynomial and nearest neighbour) were evaluated in a random selected sample of 25% of the training data, and using cross-validation the method with the lowest mean square error (MSE) per variable was identified and subsequently used. The above methods were then used to interpolate the variable in both, training and test sets. Time series data was then encoded using max-min scaling. The final time series dataset contained the interpolated time series of all included admissions comprising 144 readings per admission per vital sign, and blood test. For data representing static time points, continuous variables were normalised. Target-encoder was used to encode categorical variables as described in [ 23 ], to reduce the impact of the difference between the order of magnitude in the variable, and to transform variables in values of a range between 0 and 1 preserving most of the predictive power of the original variables [ 23 ]. Every admission was considered independent, including re-admissions. Statistical analysis of independent variables Differences across 34 variables between patients who were deceased and discharged were assessed. This analysis utilized the first value for each variable collected at admission, providing insights into the patient’s baseline condition at hospital arrival. Significance was tested for continuous variables via the t-test, for binary variables using the normal test, and for categorical variables using Kruskal-Wallis test, with a 95% significance level. Mortality modelling Mortality was defined as a binary variable denoting death in-hospital or within 30-days of hospital discharge. Several modelling components were explored to determine their impact on model performance. These components included: collection time, stratification by age, data balance towards the target variable, and classifier model type. Distinct attributes of these components are presented in Error! Not a valid bookmark self-reference. with the rationale behind their selection in this paper. Time series are identified as one type of component, to support benchmarking against models built using non-time dependent data. All models used 34 variables, when models involved time-dependent data, they were combined with demographics / static variables (e.g., age at admission, ethnicity, etc) Non-time series hyper-parameters were fine-tuned using search grid method and 10-fold cross-validation for metrics calculation, hyper-parameters and values can be found at supplementary material E. Whilst time series classifiers (LSTM and GRU) were optimised using a Bayesian approach previously demonstrated to find optimal hyper-parameters [ 24 – 26 ], with 5-fold cross-validation. Models were evaluated using multiple metrics including the area under the receiver operating characteristics curve (AUROC), recall, accuracy, precision, and F1 score. Hyper-parameter tuning used the search grid method and 10-fold cross-validation for SVM, Random Forest and XGBoost classifiers. Whilst time series classifiers (LSTM and GRU) were fine-tuned by applying a Bayesian optimisation approach to find optimal hyper-parameters in artificial neural networks [ 24 – 26 ], with 5-fold cross-validation. CAP severity forecasting Severity was represented by URB65, a variation of the CURB65 score excluding confusion (not included in the initial extraction but calculated from EWS). This was derived by forecasting required vital signs individually (blood urea level, respiratory rate, and blood pressure) on the third day and then calculating a score as per CURB65 [ 27 ]. The predicted URB65 score (severity in a scale of 0-4 scoring 1 point for each when the following are present: urea >7 mmol/L; respiratory rate ≥ 30/minute, systolic blood pressure <90 mmHg and/or diastolic blood pressure ≤ 0 mmHg; and age ≥ 65 years [ 27 ]) was calculated at the end of the third day of hospitalisation using the predictions from the models described below. Two components were built to forecast vital signs. First, a max-min scaling component with global and local attributes for time series transformation. The former used the max-min reference from each of the individual time series, whereas the latter used max-min reference values from across the entire data set. Second, ML models components (GRU and LSTM) predicted the sequence of the last day of hospitalisation (48 values for each variable), using a many-to-many methodology [ 15 , 28 ] where neural networks are designed which sequence the first two days (96 values), and predict the sequence of each variable at the third day (48 values) of hospitalisation. Hyper-parameters were tuned using Bayesian optimisation [ 25 ]. Model performance was assessed using root mean squared error (RMSE). General MSE refers to the average MSE of the series predicted, while the last MSE represents the last value at the third day of hospitalisation. The final URB65 results is compared using the confusion matrix, the global accuracy, and the accuracy per URB65 class. The predicted URB65 score (severity in a scale of 0-4 scoring 1 point for each when the following are present: urea >7 mmol/L; respiratory rate ≥ 30/minute, systolic blood pressure <90 mmHg and/or diastolic blood pressure ≤ 0 mmHg; and age ≥ 65 years [ 27 ]) was calculated at the end of the third day of hospitalisation using the predictions from the models of the involved vital signs. The final URB65 results is compared using the confusion matrix, the global accuracy, the accuracy per URB65 class and MatchR, a parallel for recall in multiclass classification, assessing the accuracy of prediction for each class. Tools and statistical frameworks All data processing and analytical work was done using Python 3.8 [ 29 ]. Preprocessing, and cleaning used Pandas version 2.0.3 [ 30 ]. Interpolation, modelling and statistical analysis used statsmodels version 0.13.2 [ 31 ], scikit-learn modelling [ 32 ], Keras 2.0 machine learning framework [ 33 ], Tensorflow version 2.10.0 [ 34 ] and Bayesian-optimisation [ 35 ] packages. Scripts are available at a GitHub repository in supplementary document C. This study used the ALICE High Performance Computing facility at the University of Leicester. Results Descriptive statistics A summary of the cleaning and filtering process (inclusion and exclusion of admissions) is presented in Figure 2 for each of the datasets. The training set (A) comprised 24,720 admissions (18,104 patients). After pre-processing, 9,390 admissions were included (8,243 patients). Similarly, the test set (B) contained 24,720 admissions (20,088 patients) which were narrowed down to 7,892 admissions (7,236 patients). Download figure Open in new tab Figure 2. Flow chart showing inclusion and exclusion criteria of study Download figure Open in new tab Figure 3. Results of CAP admissions mortality prediction models shown using AUC against recall. A) impact of a balancing dataset for training purposes in model results. B) All models developed and tested, divided by collected time component. C) Performance by classifier Table 2 shows that the demographics of training and test sets were similar in nature. From the 9390 admissions that formed the training set 22% (2024) died in hospital or within 30 days of discharge, 48% (4553) were women, and 80% (7524) were recorded as white British with a median age of 78 (IQR 66 - 85), and a median Charlson comorbidity score of 1 (IQR 0 - 3). The test set included 7892 admissions in which 25% (1944) died in hospital or within 30 days of discharge, 45% (3541) were women, 72% (5667) were white British, with a median age of 74 (IQR 61 - 83) and a median Charlson comorbidity score of 2 (IQR 0 - 3). View this table: View inline View popup Download powerpoint Table 1. Components of modelling for comparing the effect of different attributes on CAP outcome prediction. View this table: View inline View popup Download powerpoint Table 2. Baseline characteristics of admissions of patients with CAP for training and test data sets. Statistical comparison between admissions where patients were discharged and those who diseased. The comparison between discharged and deceased patients were identified, and showed significant differences (p<0.05) in key vital signs (temperature, blood pressure, heart rate) and common blood tests (creatinine, urea, cells blood counts, potassium, albumin, alkaline phosphate), with only mean corpuscular haemoglobin (MCH) and assisted O 2 not showing significant differences. Predicting Mortality in CAP admissions A total of 24 models were created using all training data (unstratified). Twenty for non-time dependent data corresponding to two types of data time collection (first value collected within the admission and peak and trough (PnT) values across three days), data balanced/unbalanced and five different classifiers. Four models were created using time series data, based on two different recurrent neural network-based classifiers and balanced/unbalanced data. The performance metrics of the models are presented in Table 3 . The best performing model used a recurrent neural network (RNN) based approach: a Gated Recurrent Unit (GRU) classifier trained using time series data, and a balanced data set (AUROC 0.77 and recall 0.69). This outperformed a Support Vector Machine (SVM) classifier (AUROC 0.72 and recall 0.63) and another RNN-based method, Long Short-Term Memory (LSTM) (AUROC 0.72 and recall 0.67) both of which used balanced data sets and PnT data for training. All models trained using balanced data produced higher recall than those trained using unbalanced data (maximum 0.25). View this table: View inline View popup Download powerpoint Table 3. Performance metrics of the 24 CAP admissions mortality prediction models ordered descending by best performance assessed by AUC and F1-score. 1.1.1. Age Stratification It is known that CAP patients admitted to hospital aged 65 and above have worse outcomes. To explore whether stratified models which incorporate this age boundary could improve performance, we created stratified models by training them on datasets divided into age groups (under 65 years old, and greater than or equal to 65 years old). For patients under 65, the training set contained 2196 admissions (252 deceased), and the test set 2533 admissions (306 deceased). This division did affect the balance of the classes in the data, with a mortality rate of 25% for patients 65 and above, which dropped to 9% for patients under 65 (compared to 21% for the overall dataset). In total, 40 models were trained (20 per age group), using the same three approaches described in the previous section (time range, classifier type, and balanced). The results from the best performing models are presented in Table 4 . For both patient groups, the top models utilised PnT data and balanced classes, but for patients ≥65 the most effective classifier was GRU (AUROC=0.68, recall=0.66, F1 score = 51) while for patients < 65, the most effective was an SVM classifier (AUROC = 0.71, recall = 0.46, F1 score = 0.33). However, the performance of the latter suffers from poor recall and F1 score. More complex RNN-based and SVM classifiers were shown to perform better than others. View this table: View inline View popup Download powerpoint Table 4. Age stratification metrics for the most important models Performance corresponds of a balance between the AUC and the F1-score which is compound by recall and precision. 1.2. Forecasting CAP Severity 1.2.1. URB65 variables forecasting A forecasting approach was devised which utilised models that predicted each of the four vital signs over a three-day period (respiratory rate, systolic blood pressure, diastolic blood pressure, blood urea), where in two days (96 readings) were used to train a model to predict the third day (48 readings). The results obtained at the end of the third day i.e. the last value of the predicted sequence was used to predict a severity score for the third day (URB65). Sixteen models were created using all processed admissions as training data (9390). Four models were created for each of the four vital signs, based on RNNs (LSTM and GRU) and two variations of the max-min scaling method (global or local). RNNs are designed to handle time series data better than other models and had also previously produced the best performing models. Performance was evaluated against all admissions in the test set (7892). Table 5 shows the root mean squared error (RMSE) for each vital sign, and shows that overall global scaling outperformed local max-min scaling. There was little difference in the results obtained from the two types of models (less than 0.05). The smallest RMSE was reported by the ‘blood urea’ model using global scaling (General RMSE = 0.08). RMSE based, global max-min transformation performed better than local max-min where general RMSEs show large increments for each of the symptoms involved in the URB65 calculation. Both types of blood pressure generated larger RMSE, in most of the cases >1, suggesting errors bigger than the max value used for scaling and leading to poor performance in these variables. View this table: View inline View popup Download powerpoint Table 5. results when forecasting variables involve URB65 General RMSE refers to the mean error of all the values predicted. Last RMSE refers to the RMSE of the last instance predicted. IQR is the interquartile range. View this table: View inline View popup Download powerpoint Table 6. Overall results of calculating severity with vital signs forecasts Results from the last RMSE were generally lower than the average general RMSE suggesting that the main differences might occur within the time series rather than at its last point, indicating that the global approach for respiratory rate and blood urea is a good approach to identify the state at the end of the day for each admission. Figure 4 and Figure 5 show the patterns predicted using the GRU and LSTM models, respectively. Funnel shapes can be seen for all vital signs but blood urea when using local scaling, while global scaling produced more fluctuations in the trajectory of the prediction. There are also differences between LSTM and GRU models, with the former showing less fluctuation than the latter, and stabilising more rapidly. Additionally, values that are close to minimum values of the scale (e.g., values below 0.2) were predicted flat, with little increments regardless of the model. Download figure Open in new tab Figure 4. Predicted segment of the series by scaling characteristic and vital sign using GRU model. Plots of the last day of admissions (time points 97 to 144). Local scaling models tend to converge to a same point, while global models present bigger fluctuation, showing a more specific pattern in both. Blue lines represent admissions of patients that were discharge, and red of deceased admissions, showing no particular difference in the pattern. Download figure Open in new tab Figure 5. Predicted segment of the series by scaling characteristic and vital sign using LSTM model. Plots of the last day of admissions (time points 97 to 144). Local scaling models tend to converge to a same point, while global models present bigger fluctuation, showing a more specific pattern in both. Blue lines represent admissions of patients that were discharge, and red of deceased admissions, showing no particular difference in the pattern. Predicting CAP severity The URB65 at the end of the third day was calculated for each admission using the real vital sign values, and compared with predicted values. Predicted values of URB65 were obtained using the vital signs models presented above. All models were better at predicting low and medium severity classes (URB65 = 0,1,2), than high severity classes (URB65 = 3,4) and the accuracy gradually reduces across the classes, possibly a result of less instances in these latter classes. Interestingly, the CAP severity prediction accuracy was higher in models that used the local scaling method - with the highest total accuracy achieved by both GRU and LSTM (0.85). However, these models show differences in the distribution of predictions across their confusion matrices ( Figure 6 ). Download figure Open in new tab Figure 6. Comparison of URB65 by scaling and models URB65 prediction of vital signs predicted using global scaling presented the same pattern in the distribution of predictions. However, it was limited due to a lack of admissions data, it was not possible to create a model to support predictions of URB65 = 4. Discussion This study appears to be the first attempt to use the complete time series of vital signs and blood tests together to predict CAP outcome using ML models. We showed the potential of several ML-based approaches to predict and forecast CAP outcome (mortality and severity as URB65) using non-time dependent and time dependent routinely collected health data. Recurrent neural networks presented as the most promising approaches for predicting patient mortality from time series data, but there also appears to be potential for simpler classifiers based on non-time dependent data. Furthermore, we explored different approaches for developing models and pre-processing data to optimise our results. Our main findings show that using timeseries (with imputed values) and balancing the data produced models with better performance than those produced using data representing single time-points. Consequently, the best model corresponded to a GRU classifier trained on such data. This latter observation could be explained through the sensitivity of ML model for dominant patterns of dominant classes [ 28 ]. This result may be significant for other studies where classes are regularly highly unbalanced, which is common in medical domain and often unaddressed [ 36 – 39 ]. Interestingly, from the classifiers used, SVM showed a slightly better performance when processing single time-points than other classifiers. Surprisingly, results from age stratified models showed no improvement when compared to non-stratified models, despite evidence of greater CAP severity in the older population [ 6 ]. Compared to other studies ( Table 7 ), our model benefits from using data that is routinely collected, which facilitates its validation, and potential implementation. Our model was also designed to align with current guidelines for CAP management of moderate and high severity patients [ 9 – 11 ] who require hospital admission. This means that it can make use of data from hospitals across three days of admission, evaluating disease’s progression. View this table: View inline View popup Download powerpoint Table 7. Studies of implementing ML models for CAP admission mortality prediction Others similar modelling studies have not used entire time series and have relied on data collected at admissions [ 37 – 39 , 42 ]. The exceptions to this rule [ 40 ] evaluated changes in patient states over time rather than analysing specific values within admissions. However, they have not proposed the use of time series, since a big challenge in analysing time series data from routinely collected data is that they often are incomplete and sparse. Most of these studies also only reported one metric (AUC), making it difficult to identify potential biases and issues with performance. Moreover, [ 36 – 38 ] reported results over data that was unbalanced (11%, 4%, and 10% mortality, respectively) with no discussion of the impact of it on their results. [ 40 ] based their model on the progression of the disease: using the SOFA score to represent CAP severity, although this metric is not specific to CAP. Finally, [ 39 ] trained and compared classifier models using variables that would not be available at admission (e.g., treatment received) which seems unfeasible. All this is evidence of gaps in the field that our study aimed to addressed. We utilised a novel two-stage method for predicting URB65 – a variation of CURB65 score (excluding mental confusion) – using ML-based vital sign forecasting models. Predictions from models built using locally scaled data produced more accurate CAP severity predictions than their globally scaled equivalents ( Figure 4 and Figure 5 ), in spite of the smaller error in global forecasts we surmise that prediction of overall trajectory is more important than prediction of specific variability across patient’s time series. This is also evidenced by models based on local-scaling models identifying more critical patients, and producing a score closer to the actual value than those based on global-scaling. Our most promising results were obtained using GRU and LSTM, indicating that these are appropriate models when considering time series for CAP management. Nevertheless, there may be additional approaches such as Gaussian process or generative adversarial models (GAN) which warrant investigation as these have shown promising results in adapting to different unstructured data or generate data under specific contexts [ 44 ]. The accuracy of the models suggested that this two-tiered approach could be a good option for forecasting CAP severity. The work presented here is preliminary research to explore the potential of time series data in ML-based models and it is important to acknowledge certain limitations and caveats. Data used to train and test models was collected from a single hospital site over a specific period of time, which while representing a diverse population still contains a limited number of individuals, and any further development of these ML models would require refinement and validation across larger populations to provide an appropriate evidence base. we used the most recent data in our dataset for testing, to confirm models worked when potential changes in management process were considered [ 15 ]. As they stand, models were also designed according to the threshold for non-critical patients to have been discharged [ 45 ], and therefore would only be useful for patients who spend more than 3 days in hospital, although different time horizons can be explored. Additionally, several factors which could influence a patient’s progression could not be included due to lack of data collection or difficulties in obtaining the data. This included detailed clinical history, the size of lung infiltrates (accumulation of liquid in the lungs visible through X-rays), the patient’s smoking status, dietary factors, etc. 2. Conclusions Our results show that use of AI models built using routinely collected time-series data could improve CAP outcome prediction in some cases. The use of balanced data sets also showed the importance of this approach when creating reliable models. The use of time series data for predictive modelling in medical settings is still under explored and has clear potential for improving management of CAP and other medical conditions. Declarations Clinical trial number Not applicable Ethics approval and consent to participate This study was approved by the NHS Research Ethics Committee (ref. 20/WM/0144) under the IRAS ID 266731. Prior to analysis, all patient data were anonymized to protect privacy. Consent for publication Not Applicable Availability of data and materials Competing interests The authors declare no competing interests . Funding This project was co-funded by the NIHR Leicester Biomedical Research Centre, the University of Leicester and Minciencias Colombia (Colombian Ministry of Science, Technology & Innovation). Authors’ contributions Daniel Lozano-Rojas designed the study, developed the models, carried the analysis out, and wrote the first draft of the manuscript. Robert C. Free and Gerrit Woltmann conceived, supervised the study. Robert C. Free extracted the data, and contributed to the design, analysis and drafting the manuscript. Matthew Richardson and Gerrit Woltmann provided intellectual contributions and revised the manuscript. All authors contributed to manuscript revision, read, and approved the submission. Data Availability The data that support the findings of this study are available from the authors but restrictions apply to the availability of these data, which were used under REC reference number 20/WM/0144, and so are not publicly available. Data are, however, available from the authors upon reasonable request and pertinent permissions and amendments of the responsible research committee. Acknowledgements The research was carried out at the National Institute for Health and Care Research (NIHR) Leicester Biomedical Research Centre (BRC). This research used the ALICE High Performance Computing facility at the University of Leicester. Footnotes Change on the title for correct spelling List of Abbreviations AUROC/AUC Area under the receiver’s operating characteristic curve BRC Biomedical research centre CAP Community-acquired pneumonia EHR Electronic health records eObs Electronic observations EOS Eosinophils EWS Early warning score GFR Glomerular filtration rate GRU Gated recurrent unit HCT Haematocrit ICD-10 International classification of diseases version 10 IQR Interquartile range LSTM Long-Short term memory MCH Mean corpuscular haemoglobin MCV Mean corpuscular volume ML Machine learning RMSE Root-mean-squared error NHS National health service PnT Peak and Trough RBC Red blood cells RF Random forest RNN Recurrent neural network ROC Receiver’s operating characteristic SVM Support vector machines UHL University hospitals of leicester WBC White blood cells XGB Extreme gradient boosting References [1]. ↵ Institute for Health Metrics and Evaluation (IHME). Global Burden of Disease 2021 : Findings from the GBD 2021 Study . Seattle,WA : IHME ; 2024. [2]. GBD 2021 Lower Respiratory Infections and Antimicrobial Resistance Collaborators. Global, regional, and national incidence and mortality burden of non-COVID lower respiratory infections and aetiologies, 1990–2021: a systematic analysis from the Global Burden of Disease Study 2021 . The Lancet Infectious Diseases . 2024. [3]. ↵ Cilloniz C , Torres A . What’s Next in Pneumonia? Archivos de Bronconeumologia . 2022 ; 58 : 1 – 15 . OpenUrl [4]. Torres A , Cilloniz C , Niederman MS , Menendez R , Chalmers J , Wunderink RG , et al. Pneumonia . Nature Reviews Disease Primers . 2021 ; 7 ( 1 ): 25 . OpenUrl PubMed [5]. ↵ Chalmers J , Campling J , Ellsbury G , Hawkey PM , Madhava H , Slack M . Community-Acquired Pneumonia in the United Kingdom: A Call to Action . Pneumonia . 2017 ; 9 ( 1 ): 1 – 6 . OpenUrl PubMed [6]. ↵ Cilloniz C , Dominedo C , Pericas JM , Rodriguez-Hurtado D , Torres A . Community-Acquired Pneumonia in Critically Ill Very Old Patients: A Growing Problem . European Respiratory Review . 2020 ; 29 ( 155 ): 1 – 15 . OpenUrl CrossRef [7]. ↵ NHS Digital ( 2024 ). Hospital Admitted Patient Care Activity, 2023-24: Diagnosis. Hospital Episode Statistics ; 2024. [8]. ↵ Campling J , Wright HF , Hall GC , Mugwagwa T , Vyse A , Mendes D , et al. Hospitalization costs of adult community-acquired pneumonia in England . Journal of medical economics . 2022 ; 25 : 912 – 8 . OpenUrl CrossRef PubMed [9]. ↵ National Institute for Health and Care Excellence (NICE) . Pneumonia (community-acquired): antimicrobial prescribing. NICE guideline [NG138]; 2019 Reviwed 2022. [10]. Woltmann G. Pneumonia/LRTI guidance for antibiotic prescribing ( 2021 ). NHS University Hospitals of Leicester ; 2022 [11]. ↵ Musa D . Clinical Guideline for the Management of Community Acquired Pneumonia (CAP): Emergency Department and Acute Medicine . NHS Norfolk and Norwich University Hospital ( 2024 ); 2024. [12]. ↵ Zaki HA , Hamdi Alkahlout B , Shaban E , Mohamed EH , Basharat K , Elsayed WAE , et al. The Battle of the Pneumonia Predictors: A Comprehensive Meta-Analysis Comparing the Pneumonia Severity Index (PSI) and the CURB-65 Score in Predicting Mortality and the Need for ICU Support . Cureus . 2023 ; 7 : 29 – 15 . OpenUrl [13]. ↵ Lozano-Rojas D , Free RC , McEwan AA , Woltmann G . A Systematic Literature Review of Machine Learning Applications for Community-Acquired Pneumonia . In: Proceedings of 2021 International Conference on Medical Imaging and Computer-Aided Diagnosis (MICAD 2021) . vol. 784. Springer Singapore ; 2022 . p. 292-301. [14]. ↵ Hurbans R . Grokking Artificial Intelligence Algorithms . New York : Manning Publications ; 2020 . [15]. ↵ Chollet F . Deep Learning with Python . Manning Publications ; 2018 . [16]. ↵ Varshni D , Thakral K , Agarwal L , Nijhawan R , Mittal A . Pneumonia Detection Using CNN Based Feature Extraction . Proceedings of 2019 3 rd IEEE International Conference on Electrical, Computer and Communication Technologies, ICECCT 2019. 2019:1-7. [17]. Wang T , Cai M , Ouyang X , Cao Z , Cai T , Tan X , et al. Anomaly Detection Based on Convex Analysis: A Survey . Frontiers in Physics . 2022 Apr ; 10 : 873848 . [18]. Chumbita M , Cilloniz C , Puerta-Alcalde P , Moreno-Garcıa E , Sanjuan G , Garcia-Pouton N , et al. Can Artificial Intelligence Improve the Management of Pneumonia . Journal of Clinical Medicine . 2020 ; 9 ( 1 ): 248 . OpenUrl PubMed [19]. ↵ Gilvary C , Madhukar N , Elkhader J , Elemento O . The Missing Pieces of Artificial Intelligence in Medicine . Trends in Pharmacological Sciences . 2019 ; 40 ( 8 ): 555 – 64 . OpenUrl CrossRef PubMed [20]. ↵ Free RC , Richardson M , Pillay C , Hawkes K , Skeemer J , Broughton R , et al. Specialist Pneumonia Intervention Nurse Service Improves Pneumonia Care and Outcome . BMJ Open Respiratory Research . 2021 Aug ; 8 ( 1 ): e000863 . OpenUrl Abstract / FREE Full Text [21]. Royal College of Physicians. National Early Warning Score National Early Warning Score (NEWS) 2: Standardising the Assessment of Acute-Illness Severity in the NHS. Updated report of a working party ; London : RCP , 2017 . [22]. ↵ Charlson ME , Pompei P , Ales KL , MacKenzie CR . A New Method of Classifying Prognostic Comorbidity in Longitudinal Studies: Development and Validation . Journal of Chronic Diseases . 1987 ; 40 ( 5 ): 373 – 83 . OpenUrl CrossRef PubMed Web of Science [23]. ↵ Micci-Barreca D . A Preprocessing Scheme for High-Cardinality Categorical Attributes in Classification and Prediction Problems . ACM SIGKDD Explorations Newsletter . 2001 Jul ; 3 ( 1 ): 27 – 32 . OpenUrl [24]. ↵ Cabrera D , Guaman A , Zhang S , Cerrada M , Sanchez RV , Cevallos J , et al. Bayesian approach and time series dimensionality reduction to LSTM-based model-building for fault diagnosis of a reciprocating compressor . Neurocomputing . 2020 ; 380 : 51 – 66 . OpenUrl [25]. ↵ Nguyen HP , Liu J , Zio E . A long-term prediction approach based on long short-term memory neural networks with automatic parameter optimization by Tree-structured Parzen Estimator and applied to time series data of NPP steam generators . Applied Soft Computing . 2020 ; 89 : 106116 . [26]. ↵ Snoek J , Larochelle H , Adams RP. Practical Bayesian Optimization of Machine Learning Algorithms . In: Pereira F , Burges CJ , Bottou L , Weinberger KQ , editors. Advances in Neural Information Processing Systems . vol. 25. Curran Associates, Inc .; 2012 . [27]. ↵ Capelastegui A , Espana PP , Quintana JM , Areitio I , Gorordo I , Egurrola M , et al. Validation of a Predictive Rule for the Management of Community-Acquired Pneumonia . European Respiratory Journal . 2006 ; 27 ( 1 ): 151 – 7 . OpenUrl Abstract / FREE Full Text [28]. ↵ Howard J , Gugger S , Chintala S. Deep Learning for Coders with Fastai and PyTorch: AI Applications without a PhD. First edition ed. O’Reilly Media, Inc; 2020 . [29]. ↵ Van Rossum G , Drake FL. Python 3 Reference Manual . CreateSpace ; 2009 . [30]. ↵ pandas development team T. pandas-dev/pandas: Pandas. Zenodo; 2020 . Available from : doi: 10.5281/zenodo.3509134 . OpenUrl CrossRef [31]. ↵ Seabold S , Perktold J. statsmodels: Econometric and statistical modelling with python. In: 9th Python in Science Conference; 2010 . [32]. ↵ Pedregosa F , Varoquaux G , Gramfort A , Michel V , Thirion B , Grisel O , et al. Scikit-learn: Machine Learning in Python . Journal of Machine Learning Research . 2011 ; 12 : 2825 – 30 . OpenUrl [33]. ↵ Chollet F , et al. Keras. GitHub; 2015 . Available from: https://github.com/fchollet/keras . [34]. ↵ Abadi M , Agarwal A , Barham P , Brevdo E , Chen Z , Citro C , et al. TensorFlow: Large-Scale Machine Learning on Heterogeneous Systems; 2015 . Software available from tensorflow.org . Available from: https://www.tensorflow.org/ . [35]. ↵ Nogueira F. Bayesian Optimization: Open source constrained global optimization tool for Python; 2014 . Available from: https://github.com/fmfn/BayesianOptimization . [36]. ↵ Visweswaran S , Cooper GF . Patient-Specific Models for Predicting the Outcomes of Patients with Community Acquired Pneumonia . AMIA Symposium . 2005 ;(March 1994): 759 – 63 . [37]. ↵ Cilloniz C , Ward L , Mogensen ML , Pericas JM , Mendez R , Gabarrus A , et al. Machine-Learning Model for Mortality Prediction in Patients with Community-acquired Pneumonia: Development and Validation Study . Chest . 2022 Jul. [38]. ↵ Ward L , Mogensen ML , Campos CC , Ceccato A , Gabarrus A , Amaro R , et al. A Machine-Learning Model for Prediction of Mortality among Patients with Community-Acquired Pneumonia . European Congress for Clinical Micrbiology and Infectious Diseases (ECCMID ). 2019 ; 779 . [39]. ↵ Yuan J , Liu X , Wang WF , Zhang JJ . A Broad Learning System to Predict the 28-Day Mortality of Patients Hospitalized with Community-Acquired Pneumonia: A Case-Control Study . Computational and Mathematical Methods in Medicine . 2022 ;2022. [40]. ↵ Przybilla J , Ahnert P , Bogatsch H , Bloos F , Brunkhorst FM , Bauer M , et al. Markov State Modelling of Disease Courses and Mortality Risks of Patients with Community-Acquired Pneumonia . Journal of Clinical Medicine . 2020 ; 9 ( 2 ): 393 . OpenUrl PubMed [41]. Jones BE , Jones J , Bewick T , Lim WS , Aronsky D , Brown SM , et al. CURB-65 Pneumonia Severity Assessment Adapted for Electronic Decision Support . Chest . 2011 Jul ; 140 ( 1 ): 156 – 63 . OpenUrl CrossRef PubMed Web of Science [42]. ↵ Shimizu S , Hara S , Fushimi K . PRS55 Predicting the risk of in-hospital mortality in adult community-acquired pneumonia patients with machine learning: A retrospective analysis of routinely collected health data . Value in Health . 2019 Nov ; 22 : S882 . [43]. Wu C , Rosenfeld R , Clermont G . Using Data-Driven Rules to Predict Mortality in Severe Community Acquired Pneumonia . PLoS ONE . 2014 ; 9 ( 4 ). [44]. ↵ Kim J , Choo H , Shin SY , Song KD . Synthesis and quality assessment of combined time-series and static medical data using a real-world time-series generative adversarial network . Sci Rep . 2024 Aug 17; 14 ( 1 ): 19064 . doi: 10.1038/s41598-024-69812-7 . PMID: 39154144 ; PMCID: PMC11330441 . OpenUrl CrossRef PubMed [45]. ↵ Suter-Widmer , I. , Christ-Crain , M. , Zimmerli , W. et al. Predictors for length of hospital stay in patients with community-acquired Pneumonia: Results from a Swiss Multicenter study . BMC Pulm Med 12 , 21 ( 2012 ). doi: 10.1186/1471-2466-12-21 OpenUrl CrossRef PubMed View the discussion thread. Back to top Previous Next Posted March 26, 2025. Download PDF Supplementary Material Data/Code Email Thank you for your interest in spreading the word about medRxiv. NOTE: Your email address is requested solely to identify you as the sender of this article. Your Email * Your Name * Send To * Enter multiple addresses on separate lines or separate them with commas. You are going to email the following Predicting community-acquired pneumonia outcome using time series data and machine learning Message Subject (Your Name) has forwarded a page to you from medRxiv Message Body (Your Name) thought you would like to see this page from the medRxiv website. Your Personal Message CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions. Share Predicting community-acquired pneumonia outcome using time series data and machine learning Daniel Lozano-Rojas , Matthew Richardson , Gerrit Woltmann , Robert C. Free medRxiv 2025.03.11.25323764; doi: https://doi.org/10.1101/2025.03.11.25323764 Share This Article: Copy Citation Tools Predicting community-acquired pneumonia outcome using time series data and machine learning Daniel Lozano-Rojas , Matthew Richardson , Gerrit Woltmann , Robert C. Free medRxiv 2025.03.11.25323764; doi: https://doi.org/10.1101/2025.03.11.25323764 Citation Manager Formats BibTeX Bookends EasyBib EndNote (tagged) EndNote 8 (xml) Medlars Mendeley Papers RefWorks Tagged Ref Manager RIS Zotero Tweet Widget Facebook Like Google Plus One Subject Area Respiratory Medicine Subject Areas All Articles Addiction Medicine (567) Allergy and Immunology (863) Anesthesia (296) Cardiovascular Medicine (4409) Dentistry and Oral Medicine (443) Dermatology (380) Emergency Medicine (606) Endocrinology (including Diabetes Mellitus and Metabolic Disease) (1505) Epidemiology (15202) Forensic Medicine (30) Gastroenterology (1119) Genetic and Genomic Medicine (6568) Geriatric Medicine (666) Health Economics (994) Health Informatics (4509) Health Policy (1365) Health Systems and Quality Improvement (1608) Hematology (537) HIV/AIDS (1262) Infectious Diseases (except HIV/AIDS) (15902) Intensive Care and Critical Care Medicine (1103) Medical Education (619) Medical Ethics (144) Nephrology (665) Neurology (6572) Nursing (345) Nutrition (998) Obstetrics and Gynecology (1139) Occupational and Environmental Health (954) Oncology (3319) Ophthalmology (967) Orthopedics (369) Otolaryngology (420) Pain Medicine (435) Palliative Medicine (129) Pathology (662) Pediatrics (1686) Pharmacology and Therapeutics (691) Primary Care Research (710) Psychiatry and Clinical Psychology (5420) Public and Global Health (9203) Radiology and Imaging (2190) Rehabilitation Medicine and Physical Therapy (1367) Respiratory Medicine (1191) Rheumatology (593) Sexual and Reproductive Health (709) Sports Medicine (529) Surgery (709) Toxicology (99) Transplantation (288) Urology (265) (function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'9fe6b88eac344193',t:'MTc3OTIzMTY1OQ=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();
Text is read by the "Ask this paper" AI Q&A widget below.
Extraction quality varies by source — PMC NXML preserves structure
cleanly, OA-HTML may include some navigation residue, and OA-PDF can
have broken hyphenation. The publisher copy
(via DOI)
is the canonical version.