# Prediction of Intensive Care Unit Length of Stay in the MIMIC-IV Dataset
## 2 Methods
### Evaluation  
To evaluate the models, we randomly split the selected dataset into training and test datasets at a ratio of 80 to 20 percent. Different models are trained on the training dataset, and then their performance on the test dataset is evaluated using statistical metrics. Classifier performance is evaluated using common metrics such as accuracy, balanced accuracy, F1-score, and receiver operating characteristic--area under the curve (ROC AUC)--which are widely used to evaluate any binary classification. They are calculated from the confusion matrix with actual and predicted dimensions. The matrix elements denote true positives (\(TPs\)) and true negatives (\(TNs\)) as correctly predicted long and short LOS for each ICU stay. Incorrectly predicted long and short LOS are indicated by false positives (\(FP\)) and false negatives (\(FN\)), respectively. The accuracy is therefore directly calculated from the confusion matrix as \((TP+TN)/(TP+TN+FP+FN)\), and the F1-score as \(2 TP/(2 TP+FP+FN)\). The balanced accuracy is the (arithmetic) mean of the true positive rate (TPR) and the true negative rate (TNR) equal to \((TPR+TNR)/2\), where TPR and TNR, also called sensitivity and specificity, are expressed as \(TP/(TP+FN)\) and \(TN/(TN+FP)\), respectively. Similarly, the false positive rate (FPR) and the false negative rate (FNR) can be defined as \(FP/(FP+TN)\) and \(FN/(FN+TP)\), as well as the predictive positive value (PPV) and predictive negative value (PNV) by \(TP/(TP+FP)\) and \(TN/(TN+FN)\). AUC provides a single value metric as the area under the ROC, which displays the TPR versus the FPR for varying the threshold in the classification. As a more meaningful single measure of the confusion matrix, we also compute the Matthew correlation coefficient (MCC):  
\[MCC=\frac{TP\times TN-FP\times FN}{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}, \tag{1}\]which has the major advantage of being independent of the favorable class (i.e., positive or negative) [52].  
Regarding the regression problem, we computed several metrics for each experiment, namely the root mean square error (RMSE), the mean absolute error (MAE), the mean absolute percentage error (MAPE), and the R\({}^{2}\). The RMSE, which is commonly measured for regression, is defined by:  
\[RMSE=\sqrt{\frac{1}{n}\sum\left(\text{LOS}_{\text{predicted}}-\text{LOS}_{ \text{actual}}\right)^{2}}, \tag{2}\]  
where \(n\) is the size of the (test) dataset, and \(\text{LOS}_{\text{predicted}}\) and \(\text{LOS}_{\text{actual}}\) are the predicted and actual LOS of the model [53]. The MAE measures the absolute error of the regression prediction as  
\[MAE=\frac{1}{n}\sum\left|\text{LOS}_{\text{predicted}}-\text{LOS}_{\text{ actual}}\right|, \tag{3}\]  
with more applicability to normally distributed errors [54]. The MAPE is the next metric commonly used in the evaluation of regression models, with a more intuitive interpretation in terms of the relative error given by [55]:  
\[MAPE=\frac{1}{n}\sum\left|\frac{\text{LOS}_{\text{predicted}}-\text{LOS}_{ \text{actual}}}{\text{LOS}_{\text{actual}}}\right|\times 100\%, \tag{4}\]  
and the last is R\({}^{2}\), also called the coefficient of determination, a common statistical measure of the linear correlation between variables, which is calculated by [56]:  
\[R^{2}=1-\frac{\sum\left(\text{LOS}_{\text{predicted}}-\text{LOS}_{\text{ actual}}\right)^{2}}{\sum\left(\text{LOS}_{\text{predicted}}-\overline{\text{ LOS}}_{\text{predicted}}\right)^{2}}, \tag{5}\]  
where \(\overline{\text{LOS}}_{\text{predicted}}\) is the average over all predicted LOS of the model [57].