Biochar is effective in mitigating heavy metal pollution, and cadmium (Cd) is the primary pollutant in agricultural fields. However, traditional trial-and-error methods for determining the optimal biochar remediation efficiency are time-consuming and inefficient because of the varied soil, biochar, and Cd pollution conditions. This study employed the machine learning method to predict the Cd immobilization efficiency of biochar in soil. The predictive accuracy of the random forest (RF) model was superior to that of the other common linear and nonlinear models. Furthermore, to improve the reliability and accuracy of the RF model, it was optimized by employing a root-mean-squared-error-based trial-and-error approach. With the aid of the optimized model, the empirical categories for soil Cd immobilization efficiency were biochar properties (60.96 %) > experimental conditions (19.6 %) ≈ soil properties (19.44 %). Finally, this study identified the optimal biochar properties for enhancing agricultural soil Cd remediation in different regions of China, which was beneficial for decision-making regarding nationwide agricultural soil remediation using biochar. The immobilization effect of alkaline biochar was pronounced in acidic soils with relatively high organic matter. This study provides insights into the immobilization mechanism and an approach for biochar selection for Cd immobilization in agricultural soil.