To address the significant challenges in determining the single-well production of tight gas and shale gas after hydraulic fracturing, artificial intelligence (AI) methods were implemented. Machine learning (ML) algorithms such as random forest (RF), extremely randomized trees (ET), lightweight gradient boosting machines (LightGBM), gradient boosting regression (GBR), and linear regression (LR) were utilized in conjunction with reservoir geology, engineering parameters, and production data to develop several foundational models for forecasting the production of unconventional gas wells. The accuracy of these models was evaluated. Based on this, improvements in the models’ predictive accuracy and generalizability were achieved through the ensemble of machine learning models. Furthermore, this paper selected two representative tight and shale gas reservoirs to demonstrate the application of the ensemble model for well production forecasting, and a comparative analysis with actual production data was conducted. For tight gas reservoir A, the blending model achieved an MAE of 0.8419 and an MSE of 1.0930, with an R2 score of 0.8812. For shale gas reservoir B, the blending model achieved an MAE of 1.4841 and an MSE of 3.1629, with an R2 score of 0.9524. The results of the case studies indicate that the ensemble model approach employed in this study has a higher predictive accuracy and reliability than a single machine learning algorithm, and is capable of handling high-dimensional, large-scale, and imbalanced data, offering scientific validation and technical support for the assessment of the well productivity in tight and shale gas wells.