The increasing demand for clean water necessitates innovative approaches to optimize water productivity through renewable energy systems. This study harnessed computer science-based algorithm to forecast the productivity of hemispherical solar stills (HSS) enhanced by various sand beds, reflectors, and a vapor extraction fan using XGBoost analysis. Initially explored was the effect of different sand types and bed heights on HSS performance, with the findings indicating that black sand, especially at a height of 1 cm combined with reflectors and a fan, markedly improved efficiency and production. An economic analysis revealed a significant reduction in water treatment costs with the optimized system. The current work extends these experimental insights through XG-Boost to predict productivity, employing evaluation metrics such as Mean Squared Error (MSE), Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), Mean Absolute Percentage Error (MAPE), Coefficient of Variation of the Root Mean Squared Error (CVRMSE), and the determination coefficient (R2), with resulted values denoted as 0.43708%, 0.95879%, 0.2780%, 0.05290%, 12.2078%, and 0.88144% respectively. This approach significantly advances the predictability and efficiency of solar distillation systems by pressing global challenges of water scarcity and sustainability and the use of solar energy.