# A REM Update Methodology Based on Clustering and Random Forest
## 3 Proposed Approach for REM Updates
### Random Forest  
An RF regressor is a type of ensemble learning method composed of \(W\) decision tree regressors, where the predicted RF value corresponds to the average value of the predictions for each independent decision tree regressor. Figure 3 shows the structure of a decision tree composed of a root node as the starting point, split nodes where a split rule is applied, and leaf nodes. Figure 2: Proposed approach for REM update. We denote the training dataset of the RF algorithm as \(D_{RF}=\{\mathbf{z}_{1},...,\mathbf{z}_{m},...,\mathbf{z}_{M}\}\), where \(M\) is the total number of training samples, and \(\mathbf{z}_{m}=\{x_{m},y_{m},R_{m}\}\). The features correspond to position \((x_{m},y_{m})\), and \(R_{m}\) is the target RSSI value at position \((x_{m},y_{m})\). First, the RF algorithm creates \(W\) datasets, \(\{D_{RF,w}\}\), from the original dataset, \(D_{RF}\), with the bootstrap aggregation technique. Then, each \(w\)-th decision tree regressor is trained with corresponding dataset \(D_{RF,w}\). In each decision tree regressor, dataset \(D_{RF,w}\) is used to select a split rule in each split node until reaching a leaf node. Let us define \(D_{RF,w}^{b}\) as the subset of training samples at the \(b\)-th split node of the \(w\)-th decision tree regressor. Then, the best-split rule to be used at the \(b\)-th split node is determined with dataset \(D_{RF,w}^{b}\). A candidate split rule is defined as follows:  
\[s_{f,\alpha}^{b,w}(z_{i})=\left\{ \begin{array}{ll}1,&\text{if }f_{z_{i}}> \alpha\\ 0,&\text{otherwise},\end{array} \right. \tag{1}\]  
where \(f_{z_{i}}\) is the value of feature \(f\in\{x_{i},y_{i}\}\) in sample \(z_{i}\), with \(z_{i}\in D_{RF,w}^{b}\) during the training procedure and \(\alpha\) representing a threshold. In the training process, at the \(b\)-th split node, a small pool of random features is selected, and a set of possible thresholds for each feature is evaluated to select the best-split rule based on the lowest mean squared error (MSE). Split rule (1) divides the samples in dataset \(D_{RF,w}^{b}\) into two groups: \(DR_{RF,w}^{b}\) contains the training samples satisfying the \(b\)-th split rule, and \(DL_{RF,w}^{b}\) contains the rest. The MSE of each candidate split rule is evaluated as follows [3,20]:  
\[\text{MSE}\Big{(}s_{f,\alpha}^{b,w}\Big{)}=\frac{1}{\left|DR_{RF,w}^{b}\right| }\bigg{|}\sum_{i\in DR_{RF,w}^{b}}\Big{(}R_{i}-\hat{R}_{b}^{DR}\Big{)}^{2}+ \frac{1}{\left|DL_{RF,w}^{b}\right|}\sum_{i\in DL_{RF,w}^{b}}\Big{(}R_{i}-\hat {R}_{b}^{DL}\Big{)}^{2}, \tag{2}\]  
where \(\left|DR_{RF,w}^{b}\right|\) represents the number of samples in dataset \(DR_{RF,w^{\prime}}^{b}\left|DL_{RF,w}^{b}\right|\) represents the number of samples in dataset \(DL_{RF,w^{\prime}}^{b}\), \(R_{i}\) is the true target value of the \(i\)-th sample, while \(\hat{R}_{b}^{DR}\) and \(\hat{R}_{b}^{DL}\) are the predicted values based on the average RSSI of the training samples in datasets \(DR_{RF,w}^{b}\) and \(DL_{RF,w^{\prime}}^{b}\), respectively, when the candidate split test, \(s_{f,\alpha}^{b,w}\) is applied. Then, the candidate split test with the lowest MSE is selected as the best-split rule for the \(b\)-th split node. The aforementioned procedure is repeated in the next split node until reaching a leaf node, which is determined by the minimum number of training samples required to split a node, \(m_{\text{min}}\). Finally, the RSSI value associated with the leaf node corresponds to the average of the RSSI values of the training samples in that leaf node. Once the RF model is successfully trained, the test sample goes to each \(w\)-th decision tree regressor and evaluates the split rule at each split node to continue to the next split node. The process finishes when reaching the leaf node, where the associated value of that leaf node determines the predicted RSSI value for the sample in the \(w\)-th decision tree regressor. The final prediction of the RF model is the average of the RSSI values predicted by all the \(W\) decision tree regressors.