River infiltration is important to groundwater recharge. The vertical infiltration volume of rivers is an important index for studying the mutual recharge of surface water and groundwater. In this study, the factors influencing the vertical infiltration of heterogeneous sediments were identified, and a vertical infiltration model of heterogeneous sediments was constructed via mathematical functions and machine learning. This study also applied a calculation method to the calculation of tributaries in the upper reaches of the Wenyu River. The effective grain size d10 and the inhomogeneity coefficient Cu are the main controlling factors of the infiltration coefficient, and a genetic algorithm was introduced to fit a functional formula for the vertical infiltration volume based on the main controlling factors. It was found that the gradient boosting decision tree (GDBT) vertical infiltration model with the Lad function as the loss function was more effective than the back propagation neural network (BP) vertical infiltration model created with the Adam optimiser and ReLU activation function. The results of this study provide technical support for the quantitative calculation of natural sediment infiltration coefficients and principal support for the formulation of relevant standards for river ecological safety and management, which are of great theoretical significance and far‐reaching application value.