Abstract:X-ray fluorescence spectrometry has the advantages of nondestructive and rapid detection of heavy metals in soil. However, in the process of practical application, because the soil background is complex and contains a lot of noise and interference information, it is easy to be affected by the matrix effect. In order to improve the accuracy of the quantitative analysis model, it is necessary to carry out baseline correction of X-ray fluorescence spectrum and reduce the effect of baseline drift. Penalty least squares algorithm, as a common baseline algorithm, was used to further optimize the fitting baseline based on least squares by fitting the fidelity and smoothness between the baseline and the real baseline. No baseline deduction, asymmetric least squares (ASLS), adaptive iterative reweighted penalty least squares (AIRPLS), asymmetric reweighted penalty least squares (ARPLS), local symmetric reweighted penalty least squares (LSRPLS) and multi-constrained reweighted penalty least squares (DRPLS) were selected for baseline correction of the measured spectrum of heavy metal elements lead and arsenic in soil, and then the corresponding correction models were established with partial least squares (PLS) algorithm to select the optimal baseline correction algorithm. At last, the partial least square (PLS) model was compared with the correction model established by neural network (BP) and support vector machine (SVR) to evaluate the advantages and disadvantages of different models. The results showed that the optimal baseline correction algorithm of the two elements was DRPLS, which the R2 of the lead corresponding PLS model was 0.982, the prediction root mean square error (RMSEP) was 0.056 mg/kg, and the R2 of the arsenic corresponding PLS model was 0.985, the RMSEP was 0.796 mg/kg. Besides, the SVR models of lead and arsenic were optimal compared with PLS and BP models. And the R2 of the model reached 0.998 and 0.993, respectively. The RMSEP was 0.015 mg/kg and 0.596 mg/kg, respectively. Experiments showed that the prediction accuracy, detection limit and stability of the model established after baseline correction can effectively improve the quantitative analysis ability of X-ray fluorescence spectroscopy in soil.