## 3 Network Intrusion Detection Model Based on CNN and GRU
### Data Pre-Processing
#### 3.1.3 Feature Selection Algorithm  
This paper proposes a new feature selection algorithm to address the problem of data features redundancy. The algorithm first calculates the importance of sample features by the Random Forest algorithm and ranks them in order of importance; then analyses the correlation between features by [PERSON]'s index; and finally combines the two results to select the features.  
The Random Forest algorithm (RF) is an integrated learning algorithm using Decision Trees as the base learner. In feature engineering, RF algorithms can identify important features from a large number of sample features. The essence of the algorithm is to analyze and calculate the contribution of each feature of the sample in the tree, and then calculate its average value and compare the contribution between the features to identify the important features [46]. Existing methods are usually evaluated using the Gini index or the out-of-bag data error rate as an evaluation metric. The specific steps are as follows:  
1. For each base learner, select the corresponding out-of-bag data (some of the remaining samples that are not selected) and calculate its error, denoted as _error_a_;
2. Randomly add disturbances to the full sample of out-of-bag data and calculate its error, noted as _error_b_;
3. Assuming that the forest contains \(M\) trees, the value of Importance of a feature is as follows:\[Importance=\frac{error\_b-error\_a}{M} \tag{2}\]  
A new dataset is constructed by filtering out the features with a high level of importance.  
The Pearson correlation coefficient is used to measure the correlation between two variables \(X\) and \(Y\). It has a value range of \((-1,1)\)[47]. The Pearson correlation coefficient is obtained by calculating the covariance and standard deviation between the two eigenvalues and quoting it by the following formula:  
\[\rho_{X,Y}=\frac{\text{cov}(X,Y)}{\sigma_{X}\sigma_{Y}}=\frac{E[(X-\mu_{X})(Y- \mu_{Y})]}{\sigma_{X}\sigma_{Y}} \tag{3}\]  
Pearson's correlation coefficient varies from \(-1\) to \(1\). If the Pearson's correlation coefficient is close to \(\pm 1\), this indicates a high correlation between the two characteristics and the relationship can be well represented by a linear equation. If the Pearson correlation coefficient is close to zero, it means that there is no linear relationship between the two features.  
The pseudo code of the feature selection algorithm proposed in this paper is shown in Algorithm 2.  
```
Input: Original data set, D Output: Processed dataset, NewD
```  
Procedure: (1) Selecting out-of-bag data and calculating the error, noted as \(error\_a\). (2) Randomly add disturbances to the out-of-bag data, noted as \(error\_b\). (3) Calculating feature importance. (4) Ranking the importance of the features. (5) Calculating the Pearson correlation coefficient and performing a correlation analysis. (6) Combine steps (4) and (5) for feature selection. (7) Obtain the selected dataset, NewD. ```  
**Algorithm 2**Feature selection algorithm (RFP)  
The pre-processed dataset is obtained by converting the data after data balancing and feature selection into a grayscale map. The converted grayscale plots for the different categories are shown in Figure 2.  
Figure 2: Converted grayscale map.