## 2 Materials and Methods
### Artificial Intelligence Scheme  
The spectra were preprocessed before they were evaluated by the ML methods. The preprocessing scheme employed in this study is shown in Figure 1. First, all spectra were normalized using vector normalization (VN) preprocessing. Next, the spectral data were reduced using principal component analysis (PCA) from 3057 points to 20 PCs. Separately, the preprocessed spectra were compared with those in a database of soils. Subsequently, a classical least squares preprocessing (Pre-CLS) [36] was applied to the original spectra to extract a parameter that was proportional to the percentage of soil from the database spectra. Finally, PCA and the extracted parameter were used to generate the ML models. Figure 1: Machine learning pipeline for improving classification. Pre-CLS is based on a linear model of classical least squares represented as  
\[f\Big{(}\varphi_{j},\beta_{j},\omega_{i}\Big{)}=\beta_{0}+\beta_{1}\varphi( \omega_{i})_{1}+\cdots+\beta_{j}\varphi(\omega_{i})_{j}, \tag{7}\]  
where \(f\Big{(}\varphi_{j},\beta_{j},\omega_{i}\Big{)}\) denotes the normalized calculated spectrum (CS) of soil derived from a mixture of several normalized spectra of soils \(\varphi(\omega_{i})_{j}\) recorded in the database of soils spectra (DBS); \(\omega_{i}\) denotes the wavenumber and \(\beta_{j}\) is a parameter indicating the fraction or proportion of \(\varphi(\omega_{i})_{j}\) of a particular component in the CS. The model assumes that there are no binding interactions among the components in the mixture, which implies that the intensity contributions are additive. The \(\beta_{j}\) parameters can be calculated by finding the minimum of the square difference of the normalized intensity between the real spectrum and the CS. The minimum value of the sum of the squares of \(d_{i}\)(E) with respect to \(\beta_{j}\) can be found by equating the first-order partial derivatives with respect to \(\beta_{j}\) to zero and finding the \(\beta_{j}\) values. Since the model contains \(n\) parameters, \(n\) partial derivative equations are generated as follows:  
\[\frac{\partial d^{2}}{\partial\beta_{j}}=-2\sum_{i}d_{i}\frac{\partial f\Big{(} \varphi_{j},\beta_{j},\omega_{i}\Big{)}}{\partial\beta_{j}}=0,j=1,2,\cdots,n \tag{8}\]  
The value of \(\varphi(\omega_{i})_{j}\) can be determined using a simple forward selection algorithm (FSA). According to this algorithm, an empty model is generated first, and then variables (soils spectra from the database) are added one by one. At each next step, the \(E\) value shows the improvement of the model. The process is stopped when \(E\) cannot be further improved. The criteria used to evaluate the performance of the classification models were recall, log-loss, precision, f1-score, weighted average, support, and accuracy. For binary classification, the recall of the positive class is also known as sensitivity, while the recall of the negative class is called specificity. The log-loss function is used in (multinomial) logistic regression and its extensions, such as neural networks. It is defined as the negative log-likelihood of the true labels given the predictions of a probabilistic classifier. The log-loss is defined only for two or more labels. For a single sample with the true label \(yt\) and estimated probability \(yp\) that \(yt=1\), the log-loss is  
\[-\text{log P}(yt|yp)=-(yt\ \text{log}(yp)+(1-yt)\ \text{log}(1-yp)) \tag{9}\]  
Precision is often called the positive predicted value and calculated as the ratio \(TP\)/\((TP+FP)\), where \(TP\) denotes the number of true positives. \(FP\) denotes the number of false positives. Intuitively, precision is the ability of a classifier to not label a negative sample as positive. The f1-score is also known as the balanced f-score or the f-measure. The f1-score can be defined as a weighted average of precision and recall, where the f1-score best value is 1, and the worst is 0. The relative contributions of precision and recall to the f1-score are equal.