Whether a certain relationship is exist between shale gas exploitation and accumulation of trace metals in soil is a controversial issue in recent years. To date, few study clearly reveal the intrinsic contributions of natural and anthropogenic factors to accumulation of trace metals in soil. In this study, machine learning and geodetector models were integrated to investigate to contribution of environmental factors to variations of trace metals concentration. Before modeling, there are 10.33%–25.87% of soil considered as metal pollution, and the value of Pn further suggest that the Ba contribute the most to the comprehensive pollution index of trace metals in soil. The initial prediction of trace metals concentration by machine learning models is less effectively indicating the need for alternative approaches. To address this problem, post-constraints approach was used, and the post-constraint MSLR model demonstrates superior performance (R2 = 0.81) Additionally, through the utilization of geodetector model, the explanatory power (q) of CEC and SOM were identified as dominant natural factors with value of 0.055 and 0.089. respectively. Moreover, distance from working sites and working status were identified as the dominant anthropogenic factors associating to the spatial heterogeneity of trace metals in soil. The interaction between natural and anthropogenic factors showed a siginifacnt nonlinear enhancement effect on accumulation of Cr, Ba and Sr, and the highest value of q was 0.38 for SOM and distance. This study indicated that the potential metal contamination was related to shale gas exploitation and provide reference for controlling soil pollution in shale gas exploitation area and making management strategy.