Patient inflow, limited resources, criticality of diseases and service quality factors have made it essential for the hospital administration to predict the length of stay (LOS) for inpatients as well as outpatients. An efficient and effective LOS prediction tool can improve the patient care and minimize the cost of service by increasing the efficiency of the system through optimal allocation of available resources in the hospital. For predicting patient’s LOS, machine learning (ML) models can have encouraging results. In this paper, five ML algorithms, namely linear regression, k- nearest neighbours, decision trees, random forest, and gradient boosting regression, have been used to predict the LOS for the patients admitted to the hospital with some medical history, laboratory measurements, and vital signs collected before admission. Additionally, the impact of principal component analysis (PCA) has been analyzed on the predictive performance of all ML algorithms. A five-fold cross-validation technique has been used to validate the results of proposed ML model. The results concluded that the RF and GB model performs better with score of 0.856 and 0.855 respectively among all the ML models without using PCA. However, the accuracy of all the models increased with the PCA except KNN and LR. The GB model when used with principal components has score and MSE approximate to 0.908 and 0.49 respectively compared to the model that incorporates with the original data. Additionally, PCA has an advantageous effect on the DT, RF and GB models. Therefore, LOS for new patients can be predicted effectively using the proposed tree-based RF and GB model with using PCA.