The advancement of horizontal drilling and hydraulic fracturing technologies has led to an increased significance of shale gas as a vital energy source. In the realm of oilfield development decisions, production forecast analysis stands as an essential aspect. Despite numerical simulation being a prevalent method for production prediction, its time-consuming nature is ill-suited for expeditious decision-making in oilfield development. Consequently, we present a data-driven model, ASGA-XGBoost, designed for rapid and precise forecasting of shale gas production from horizontally fractured wells. The central premise of ASGA-XGBoost entails the implementation of ASGA to optimize the hyperparameters of the XGBoost model, thereby enhancing its prediction performance. To assess the feasibility of the ASGA-XGBoost model, we employed a dataset comprising 250 samples, acquired by simulating shale gas multistage fractured horizontal well development through the use of CMG commercial numerical simulation software. Furthermore, XGBoost, GA-XGBoost, and ASGA-XGBoost models were trained using the data from the training set and employed to predict the 30-day cumulative gas production utilizing the data from the testing set. The outcomes demonstrate that the ASGA-XGBoost model yields the lowest mean absolute error and offers optimal performance in predicting the 30-day cumulative gas production. Additionally, the mean absolute error of the unoptimized XGBoost model is markedly greater than that of the optimized XGBoost model, indicating that the latter, refined through the application of intelligent optimization algorithms, exhibits superior performance. The insights gleaned from this investigation have the potential to inform the development of strategic plans for shale gas oilfields, ultimately promoting the cost-effective exploitation of this energy resource.