# Spatial Prediction of Soil Contaminants Using a Hybrid Random Forest-Ordinary Kriging Model
## 2 Materials and Methods
### Criteria of Error Evaluation  
When processing a dataset, 20% of the total dataset is used as test data, 90% of the remaining 80% as training data, and 10% as validation data. This partitioning method is effective when the dataset is sufficiently large. However, in situations with limited data, this can result in a biased validation accuracy of the model. To overcome this problem, k-fold cross-validation has been widely used. This method involves dividing the training data into K equal-sized folds. K-1 of these folds was used for training, whereas the remaining fold was used for validation. This process was repeated K times to ensure that each fold was used as validation data only once, thereby preventing bias.  
A quantitative assessment of the predictive performance of a model is crucial. Therefore, this study employed the root mean squared error (RMSE) as a metric. RMSE is the square root of the average of the squared differences between the actual and predicted values (Equation (1)). This metric directly measures the average magnitude of the predicted errors. A lower RMSE indicates a lower prediction error and higher model accuracy. However, one limitation of the RMSE is its sensitivity to large errors, as it assigns greater  
Figure 2: Sampling points and measurements of heavy metal concentrations using a portable X-ray fluorescence spectrometer.  
penalties to larger errors. Sensitivity to outliers is an important consideration when interpreting RMSE results.  
\[RMSE=\sqrt{\frac{\sum(y_{i}-y^{*}_{i})^{2}}{n_{data}}} \tag{1}\]  
where \(y_{i}\) represents the actual data value collected at location \(i\), \(y^{*}_{i}\) denotes the predicted data value at location \(i\), and \(n_{data}\) indicates the number of data points used in the prediction.  
The coefficient of determination (R\({}^{2}\)) was used to compensate for the shortcomings of the RMSE metric. R\({}^{2}\) measures the proportion of variance in the dependent variable that is predictable from the independent variables, reflecting the overall fit of the predictive model to the actual data (Equation (2)). In addition, R\({}^{2}\) served as an indicator of how well the model explained the data, with values closer to 1 indicating a better fit between the model predictions and actual data. However, a high R\({}^{2}\) value does not necessarily guarantee reliability of the predictive model. The predicted data must be graphically represented to verify the actual distribution. Furthermore, the effectiveness of R\({}^{2}\) diminishes when the data exhibit nonlinear relationships.  
\[R^{2}=1-\frac{SSR}{SST} \tag{2}\]  
where SST is the sum of squared total, and SSR is the sum of squared residual.  
In this study, grid search cross-validation (GridSearchCV) was used to optimize the model. GridSearchCV experiments were conducted using various hyperparameter combinations to identify the optimal set. The hyperparameters are values set before the model training begins, and their combinations are defined in a grid format to evaluate the model's performance. For example, when two hyperparameters exist, the performance of the model is tested by varying one while keeping the other constant. This process was repeated in reverse order. This systematic approach enables an extensive search over a specified parameter space, resulting in the identification of the best parameter combination for the model.  
In addition, k-fold cross-validation was incorporated into the GridSearchCV process. K was set to 5, meaning that the data were divided into five subsets, and cross-validation was performed on each subset. RMSE and R\({}^{2}\) metrics were used to evaluate the performance of each hyperparameter combination. This approach facilitated the selection of the optimal hyperparameter combination, which was then applied to the entire dataset to construct a new model. The final model was optimized and used for further prediction or evaluation.