In the context of economic globalization and the building of a community of human destiny, the integration of the world economy has accelerated, and import and export trade is particularly important in a country's economic development. Many factors influence the import and export economy, and the uncertainty is high and more challenging to predict. In order to carry out a random forest model for the import and export economy, this paper constructs a random forest model. Also, it introduces the Gini index to ze China's total import and export economy. The method starts with the RF model construction based on the factors set. The data for Beijing 1987-2021 was used as a forecast by constructing five impact factors and then introducing the Gini index to measure the importance of the impact factors. The final test was carried out by two indicators, MSE, and R2. The conclusions are as follows: for the divided training and test sets, the MSE calculated by is 0.095 and 0.188 ,and R2 is 0.924 and 0.849, respectively, which shows that the prediction model is more accurate and yields more precise prediction results. The empirical analysis shows that the method can identify the impact indicators of China's total import and export economy more accurately.