In the quest for sustainable urban development, precise quantification of urban green space is paramount. This research delineates the implementation of a Cosine Adaptive Particle Swarm Optimization Long Short-Term Memory (CAPSO-LSTM) model, utilizing a comprehensive dataset from Beijing (1998–2021) to train and test the model. The CAPSO-LSTM model, which integrates a cosine adaptive mechanism into particle swarm optimization, advances the optimization of long short-term memory (LSTM) network hyperparameters. Comparative analyses are conducted against conventional LSTM and Partical Swarm Optimization (PSO)-LSTM frameworks, employing mean absolute error (MAE), root mean square error (RMSE), and mean absolute percentage error (MAPE) as evaluative benchmarks. The findings indicate that the CAPSO-LSTM model exhibits a substantial improvement in prediction accuracy over the LSTM model, manifesting as a 66.33% decrease in MAE, a 73.78% decrease in RMSE, and a 57.14% decrease in MAPE. Similarly, when compared to the PSO-LSTM model, the CAPSO-LSTM model demonstrates a 58.36% decrease in MAE, a 65.39% decrease in RMSE, and a 50% decrease in MAPE. These results underscore the efficacy of the CAPSO-LSTM model in enhancing urban green space area prediction, suggesting its significant potential for aiding urban planning and environmental policy formulation.