# Prediction of Total Petroleum Hydrocarbons and Heavy Metals in Acid Tars Using Machine Learning
## 3 Machine Learning Algorithm Description
\begin{table}
\begin{tabular}{c c c c c} \hline
**Property** & **Minimum Value** & **Maximum Value** & **Mean Value** & **Standard Deviation** \\ \hline Initial Cd concentration & 1 & 126 & 20.34 & 19.82 \\ Initial Cu concentration & 5 & 789 & 46.59 & 101.9 \\ Initial Cr concentration & 3 & 452 & 27.35 & 60.51 \\ Initial As concentration & 1.4 & 589 & 96.13 & 137.37 \\ Initial Ni concentration & 2 & 859 & 28.5 & 109.67 \\ \hline \end{tabular}  
After the data were obtained, it was divided into training and testing data. A total of 70% was used as training data, and 30% was used as testing data.  
Data visualization is the next step. Its purpose is to offer visual insight into the obtained data, which may assist in solving the machine learning problem.  
The geographic coordinates of the obtained samples are presented in Figure 1.  
\end{table} 
Table 1: _Cont._  
Figure 1: The placement of the acid tar sample sampling points. The following steps can be performed either manually or automatically. In the first option, the people conducting the machine learning make every choice along the way and write the appropriate lines of code. In the second case, the computer is responsible for making every decision and choice based on mathematical and statistical criteria. This technique is called \"AutoML\" (which comes from \"Automatic Machine Learning\"). For the development of the machine learning software, Automatic Machine Learning was chosen by the authors for the following reasons:  
* Automation and speed;
* Efficiency;
* Reduced human bias;
* Coding volume. To implement AutoML, the PyCaret library was used. PyCaret is an open-source machine-learning library in Python that automates ML workflows [43]. This library automates the entire workflow, testing a very large number of algorithms and possibilities in a short amount of time. Because everything is automated, the results are objectively the best as they are chosen through mathematical and statistical values. The parameters used in the PyCaret library are the default parameters unless specified otherwise. Also, it is worth noting that PyCaret does not accept multivariate estimation. This means the next steps were executed for every response variable considered. Preparing the data for the machine learning model is a very important step, which is essential for ensuring the accuracy, performance, and effectiveness of machine learning algorithms. It helps improve the quality and usability of the resulting insights and predictions. For the training data obtained, the only data preparation needed was normalizing the predictor data for both the training and testing sets. The following normalization methods were chosen:  
* Z-score normalization;
* Minmax normalization. The remaining steps of the program's algorithm will be repeated two times, with the dataset being normalized using each of the two algorithms. More information about the two types of normalizations can be found online [44; 45]. Both normalization algorithms were used with their default parameters. Selecting and training a machine learning model uses the prepared data to be given to a machine learning model for training and, later, testing. The purpose of this step is to choose an algorithm from a list of candidates that offers the best fit for the training data. The best algorithm to use was determined by using the PyCaret AutoML library. This library can automatically test and tune 19 machine-learning algorithms that come with it. Other algorithms can be tried, but the authors considered the default number of algorithms to be enough and did not use this option [43; 46; 47; 48; 49; 50; 51; 52]. Hyperparameter tuning is the operation of finding the set of algorithm parameters that give the best estimation for a training dataset. The hyperparameters are chosen by the programmer (or the AutoML library), and a set of candidate values must be given for each chosen hyperparameter. For each combination of hyperparameters, the algorithm is trained using the same training dataset, and the estimation accuracy is stored.