# Hybrid VLC-RF Channel Estimation for GFDM Wireless Sensor Networks Using Tree-Based Regressor
## 4 Model Configuration and Training Parameters
```
1:Dataset: dataset[1..18,000][1..160]
2:Target: target[1..18,000][1..160]
3:Outputs: Trained Model: RFModel[1..160]
4:Test Accuracy, Precision, Recall, F1-score
5:// **Step 1: Split Dataset into 70% Training and 30% Testing**
6:Define train and test sets for inputs and targets
7:// **Step 2: Train Random Forest Models**
8:for\(k\gets 1\) to 160 do
9:RFModel[\(k\)]\(\leftarrow\) TreeBagger(\(100,\mathrm{train\_set},\mathrm{train\_label}[:,k]\),
10:\"NumPredictorsToSample\" = 13, \"MinLesSize\" = 5)
11:endfor
12:// **Step 3: Test the Model**
13:for\(i\gets 1\) to 5400 do
14:for\(k\gets 1\) to 160 do
15:prediction[\(i\)]\(\leftarrow\) predict(RFModel[\(k\)],test_set[\(i\)])
16:endfor
17:endfor
18:// **Step 4: Calculate Metrics**
19:accuracy \(\leftarrow\)\(\left(\frac{\mathrm{TP+TN}}{\mathrm{TP+TN}}\right)\times 100\)
20:precision \(\leftarrow\)\(\frac{\mathrm{TP}}{\mathrm{TP+TN}}\)
21:recall \(\leftarrow\)\(\frac{\mathrm{TP+TN}}{\mathrm{TP+TN}}\)
22:f1_score \(\leftarrow\) 2 \(\times\)\(\frac{\mathrm{precision\_recall}\cdot\mathrm{recall}}{\mathrm{precision\_recall}}\)
```  
**Algorithm 2** Random forest training and evaluation (70/30 split). ```
1:Inputs:
2:Dataset: dataset[1..18,000][1..160]
3:Target: target[1..18,000][1..160]
4:Outputs:
5: Trained Model: SVMModel[1..160]
6:BER, Accuracy, Precision, Recall, F1-score
7:1://Step 1: Normalize and Split Dataset
8:Standardization dataset and split training and testing sets
9://Step 2:Train SVM Models
10:for\(k\gets 1\) to 160 do
11:\(\text{SVMModel}[k]\leftarrow\text{fitsym}(\text{train\_set},\text{train\_label}[:k],\)
12:\(\text{KernelFunction'}\) = linear','Standardize' = true)
13:endfor
14://Step 3:Test the Model
15:for\(i\gets 1\) to 5400 do
16:for\(k\gets 1\) to 160 do
17:\(\text{prediction}[i][k]\leftarrow\text{predict}(\text{SVMModel}[k],\text{test\_set}[i])\)
18:endfor
19://Step 4:Calculate Metrics
20:accuracy \(\leftarrow(\frac{1+\text{TN}}{\text{TP}+\text{TN}+\text{TN}+\text{TN}}) \times 100\)
21:precision \(\leftarrow\frac{\text{TP}+\text{TP}}{\text{TP}+\text{TN}}\)
22:\(\text{recall}\leftarrow\frac{\text{precision}\cdot\text{recall}}{\text{ precision}+\text{recall}}\)
23:\(\text{f1\_score}\gets 2\times\frac{\text{precision}\cdot\text{recall}}{\text{ precision}+\text{recall}}\)
```  
**Algorithm 4** Linear Regression Training and Evaluation (70/30 Split)  
```
1:Inputs:
2:Dataset: dataset[1..18,000][1..160]
3:Target: target[1..18,000][1..160]
4:Outputs:
5: Trained Model: LRModel[1..160]
6:BER, Accuracy, Precision, Recall, F1-score
7:1://Step 1:Split Dataset
8:2:Partition dataset into 70% training and 30% testing subsets
9://Step 2:Train Linear Models
10:for\(k\gets 1\) to 160 do
11:\(\text{LRModel}[k]\leftarrow\text{fitlim}(\text{train\_set},\text{train\_label}[:k])\)
12:endfor
13://Step 3:Test the Model
14:for\(i\gets 1\) to 5400 do
15:for\(k\gets 1\) to 160 do
16:\(\text{prediction}[i][k]\leftarrow\text{predict}(\text{LRModel}[k],\text{test\_set}[i])\)
17:endfor
18://Step 4:Calculate Metrics
19:accuracy \(\leftarrow\left(\frac{\text{TP}+\text{TN}}{\text{TP}+\text{TN}+\text{TN}+ \text{TN}}\right)\times 100\)
20:precision \(\leftarrow\frac{\text{TP}}{\text{TP}+\text{TP}}\)
21:recall \(\leftarrow\frac{\text{TP}}{\text{TP}+\text{TN}}\)
22:f1_score \(\leftarrow 2\times\frac{\text{precision}\cdot\text{recall}}{\text{ precision}+\text{recall}}\)
```  
**Algorithm 5** Support Vector Machine Training and Evaluation (70/30 Split)