# Prediction of Intensive Care Unit Length of Stay in the MIMIC-IV Dataset
## 3 Results
### Regression  
The results of the regression are presented in Table 4. Overall, SVM performs the best, with superior performance in terms of MAE and MAPE, although RF has a slightly better RMSE and R\({}^{2}\). We note that, in the regression prediction, here, the full range of LOS is considered, i.e., 1-21 days. This leads to a challenge in predicting longer stays, because the mean prediction error (difference between predicted and actual LOS) grows exponentially with LOS. For example, with an LOS of 5 days, the mean error is approximately 1.5, while, with an LOS of 10, it increases to 6.5, i.e., more than 4 times worse. Figure 5: Percentage of the feature importance from the XGBoost model used for classification. The GCS verbal shows the highest performance importance, consistent with its strong correlation with LOS. \begin{table}
\begin{tabular}{l c c c c c} \hline \hline
**Method** & **Accuracy** & **F1** & **Balanced Accuracy** & **MCC** & **AUC** \\ \hline Logistic regression & 0.785 & 0.435 & 0.609 & 0.307 & 0.735 \\ SVM & 0.792 & 0.438 & 0.610 & 0.326 & 0.740 \\ Random forest & **0.810** & **0.442** & 0.655 & **0.410** & **0.800** \\ XGBoost & 0.802 & 0.438 & **0.671** & 0.401 & 0.777 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: The binary classification results of the different models evaluated in terms of accuracy, F1-score, balanced accuracy, MCC, and AUC. The results of each evaluation score are averaged over 10 different experiments using repeated random train/test split. Random forest outperforms other models overall. This means that, given the hyperparameters and settings of the regression models, it is indeed rather unlikely to accurately predict a prolonged LOS based on data collected in the first 24 h of ICU admission. To test the performance of the regression models on a less variable dataset, we consider actual short ICU stays with LOSs up to 4 days. The results presented in parentheses in Table 4 show a huge improvement in all metrics, indicating relatively good predictions. However, since the actual LOS is not known on the first day of admission, the latter approach is impractical for accurately predicting ICU LOS. In practice, we propose a stepwise approach to LOS prediction, where we first classify data based on ICU stays into short and long by a classifier, and then perform the regression on data with predicted short LOS. As such, the target dataset used for regression will contain some FN (data with actually long LOS predicted as short stay), making the modeling more complex while reflecting a real situation. We employed random forest and XGBoost models to classify ICU stays in the first step. These classifiers were selected by maximizing the geometric mean (G-mean) of the sensitivity and specificity of the classification equal to \(\sqrt{\text{TPR}\times\text{TNR}}\). For the reference, the corresponding confusion matrices for random forest and XGBoost classifiers used prior to regression are displayed in Table 5.  
XGBoost, for example, correctly classifies 29,976 out of 31,849 short stays with a TNR of 0.94. This means that 1873 short stays are missing because they are incorrectly classified as long stays. Similarly, only 617 stays are misclassified as short stays with an NPV of 0.98, while they are actually long stays. In the next step, the regression is performed based on the predicted short stays from the classifiers. There is a minor difference between the classification results of random forest and XGBoost, resulting in small discrepancies in the regression metrics. The results are summarized in Table 6, with random forest actually outperforming XGBoost. Although the regression results are still worse than those for the actual short stays reported in parentheses in Table 4, they are significantly improved. To more accurately predict the actual LOS for longer stays, we should move the data collection period forward and consider data from, e.g., the first four days or at least the fourth day.