## 4 Network Implementation and Learning Algorithm
### Random Forest Model  
In this section, we will present the random forest algorithm as an important machine learning technique for building a prediction model to enhance the LoRa network's performance. Ensemble learning is a machine learning approach that combines multiple individual models to build a more influential predictive model. The essential concept is that by combining the predictions of several models, the ensemble process can achieve better accuracy and strength than the single model when processed on its own. The process of data transmission in the LoRA network infrastructure of the oil pipeline monitoring system happens when LoRa endpoint devices send information to the server via separate gateways within the oil pipeline. The random forest model is connected with the FLoRa server to process the LoRa network parameters, which are related to the flow of incoming data and improve the network output performance depending on the trained dataset, which is created by collecting the LoRa network parameters from OMNeT++ by running the LoRa network in multiple scenarios with different network transmission parameters and recording its corresponding output performance for seven continuous days. The main goal of using the random forest algorithm is to predict and improve the network output performance by implementing the regression task based on building multiple decision trees and combining them to obtain a more accurate and steady-state prediction. To achieve the best performance, the random forest model is adjusted with 100 decision trees, the maximum depth of the trees is 15, the minimum number of samples required to split an internal node is 5, and the minimum number of samples per leaf to adjust the minimum sample number required at a leaf node is 2. Efficiently, it obtained the underlying patterns in the data, providing a hard baseline for the proposed model. Table 5 explains the features of the dataset's components. The mathematical approach is described in the following equations. \[\hat{y}=\frac{1}{M}\Sigma_{m=1}^{M}T_{m}(x) \tag{5}\]  
where \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Parameter** & **Value/Range** & **Unit** & **Description** \\ \hline Number of LoRA gateways & 10 & - & The total number of LoRa gateways in the simulation. \\ \hline Number of LoRa nodes & 100 & - & The total number of LoRa nodes in the simulation. \\ \hline LoRa server & 1 & - & Number of LoRa servers managing the network. \\ \hline Spreading factor (SF) & 7, 8, 9, 10, 11, 12 & - & Used to adjust the energy consumption and transmission range. \\ \hline Payload (PL) & 26–130 & Bytes & Size of the data transmitted by LoRa nodes. \\ \hline Bandwidth (BW) & 125 & kHz & Communication bandwidth. \\ \hline Transmission power (TP) & 11, 14, 20 & dBm & Transmission power used by LoRA nodes. \\ \hline Coding rate (CR) & 4/5 & - & Error correction rate used during the transmission. \\ \hline Noise figure (NF) & 6 & dB & Impact of noise on communication quality. \\ \hline Low data rate optimization & 0, 1 & - & Communication optimization at lower data rates. \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Summary of dataset features and components. * M is the number of trees in the forest;
* T\({}_{m}\) (X) is the output of each decision tree for the input (x);
* \(\hat{y}\) is the predicted output. \[PC_{pred}=\frac{1}{M}\Sigma_{m=1}^{M}T_{m}(XPC) \tag{6}\]  
where PC\({}_{pred}\) refers to the value of the predicted power consumption, M is the number of trees in the forest, Tm is the output of each decision tree, and XPC represents the input feature vectors of each decision tree related to power consumption. \[PD_{pred}=\frac{1}{M}\Sigma_{m=1}^{M}T_{m}(XPD) \tag{7}\]  
where PD\({}_{pred}\) refers to the value of predicted delayed packets, M is the number of trees in the forest, Tm is the output of each decision tree, and XPD represents the input feature vectors of each decision tree for the input (x) related to the packet delay. \[PL_{pred}=\frac{1}{M}\Sigma_{m=1}^{M}T_{m}(XPL) \tag{8}\]