China and the international community attach great importance to sustainable development goals such as peaking carbon emissions. As an important energy base in China, the Yellow River Basin has significant capacity for reducing carbon emissions and increasing carbon sinks. To accelerate the achievement of carbon peak targets, social and natural development data as well as carbon emission data of 56 cities along the Yellow River Basin from 2000 to 2021 were analyzed. Based on the evaluation indicators of the model, the PSO-XGBoost-RF model was selected from the comparative models to predict the carbon peak of cities in the Yellow River Basin under different paths. Under the current economic and social development, cities along the Yellow River Basin in China are facing huge pressure to reduce emissions. It is expected to achieve a carbon peak in 2033, with a peak of 2,051,320,000 tons, so the target of reaching the peak of carbon emissions before 2030 will not be accomplished. But through comprehensive optimization of the industrial structure and reduction of energy consumption, cities along the Yellow River Basin as a whole may achieve carbon peak by 2026, with a peak of 1,917,132,000 tons.