# A Density-Based Random Forest for Imbalanced Data Classification
## 3 Methods
### DBRF Algorithm  
An overview of the entire DBRF procedure is shown in Figure 3, divided into four steps: data splitting, boundary domain construction, density domain construction, and model merging.The details of the algorithm are presented in Algorithm 1. For data splitting, the original dataset was divided into majority and minority sets. The details of the algorithm are presented in Algorithm 2. The boundary domain construction  
Figure 3: Framework of the density-based random forest (DBRF) algorithm. first counts \(m^{\prime}\), which is the number of majority classes in \(m\) neighbors of a single minority sample in the original dataset. Then, if \(\frac{m}{2}\leqslant m^{\prime}<m\), the sample is added to the boundary domain. This is shown by the gray triangles in Figure 1. The details of the algorithm are presented in Algorithm 3. Density domain construction determines the majority class samples based on the distribution of the boundary minority class samples. DBRF uses the clustering method to identify the boundary samples from boundary minority samples, as is done when solving the clustering problem with the DBSCAN algorithm. Then, it merges them with the minority class \(D^{\prime}\) to build the density domain. The green, gray, and red sample points in Figure 1 represent the density domain. The details of the algorithm are presented in Algorithm 4. ```
0: Training set \(D=\{x_{1},x_{2},...,x_{n}\}\), \(Label_{maj}\): majority class, \(Label_{min}\): minority class, \(\eta\): domain maximum distance, \(\omega\): minimum number of majority class samples in the neighbors, \(n\): number of nearest neighbors, \(size\): total number of trees, \(p\): allocation ratio;
0: Merged classifier
1:\(D^{\prime}\), \(D^{\prime\prime}=DataSplit(D,Label_{maj},Label_{min})\)\(\triangleright\) Data splitting
2:\(Boundary=BoundaryConstruction(D,D^{\prime})\), \(\triangleright\) Boundary domain construction
3:\(Density=DensityConstruction(Boundary,D^{\prime\prime},\eta,\omega)\), \(\triangleright\) Density domain construction
4:\(RF_{1}=BuildForest(D,size\times(1-p))\), \(\triangleright\) Train random forest \(RF_{1}\) with original data. 5:\(RF_{2}=BuildForest(Density,size\times p)\), \(\triangleright\) Train random forest \(RF_{2}\) with the density areas. 6:\(RF=RF_{1}+RF_{2}\), \(\triangleright\) Merging two random forests
```  
**Algorithm 1 Density-based random forest (DBRF). **  
```
0: Training set \(D=\{x_{1},x_{2},...,x_{n}\}\), \(Label_{maj}\): majority class, \(Label_{min}\): minority class
0: Majority set \(D^{\prime\prime}\), minority set \(D^{\prime}\)
1:for each \(x_{i}\in D\)do
2:if\(label(x_{i})\in Label_{maj}\)then
3:\(D^{\prime\prime}=D^{\prime\prime}\cup\{x_{i}\}\)
4:else
5:\(D^{\prime}=D^{\prime}\cup\{x_{


```
0: Boundary minority sample set \(Boundary=\{x_{1},x_{2},...,x_{n}\}\), majority set: \(D^{\prime\prime}\), domain maximum distance: \(\eta\), minimum number of majority class samples in the neighborhood: \(\omega\)
0: Density domain: \(Density\)
1:\(mergeSet=D^{\prime\prime}\cup Boundary\)\(\triangleright\) Merge the majority class and boundary
2:\(Density=\{\}\)
3:while\(Boundary\
eq\emptyset\)do
4: Record the current set of unvisited samples: \(DataOld=mergeSet\)
5: Randomly select a sample from \(Boundary\) and initialize the \(Queue\)
6:\(mergeSet=mergeSet-Queue\)
7:while\(Queue\
eq\emptyset\)do
8: Fetch the first sample \(x_{i}\) of the \(Queue\)
9:\(\|D_{\eta}(x_{i})\|=\) the number of samples whose distance from \(x_{i}\) is no greater than \(\eta\) in \(DataOld\)
10:if\(\|D\eta(x_{i})\|\geq\omega\)then
11:\(temp=D_{\eta}(x_{i})\cap mergeSet\)
12:\(Queue=Queue\cup temp\)
13:\(Density=Density\cup temp\)
14:\(mergeSet=mergeSet-temp\)
15:endif
16:\(Queue=Queue-\{x_{i}\}\)
17:endwhile
18:\(Boundary=Boundary-(Density\cap Boundary)\)
19:endwhile
20:\(Density=Density\cup D^{\prime}\)\(\triangleright\) Combine minority class samples with the found majority class samples
```

**Algorithm 4 Density domain construction.