A random forest intrusion detection method based on multi-layer classification strategy
Through the multi-layer classification strategy and random forest intrusion detection method, the problem of uneven distribution of sample categories in network intrusion detection is solved, the detection accuracy and overall detection rate of small sample categories are improved, and the data processing time is reduced.
Patent Information
- Application Number
- CN202210169929.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-23
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-02-23
AI Technical Summary
When existing network intrusion detection methods face uneven distribution of sample data categories, it is difficult to accurately detect small sample category data, resulting in low detection rates.
A random forest intrusion detection method based on a multi-layer classification strategy is used to build a multi-layer classification model through data preprocessing, feature selection and extraction, divide super classes layer by layer and use different feature subsets for classification until all small categories are divided Completed, feature selection algorithm combining PCA and supervised learning methods.
It improves the classification accuracy of small sample categories, reduces data dimensions and training time, improves computing performance, and significantly improves the detection rate of small sample categories in experiments.
Smart Images

Figure BDA0003517217700000031 
Figure BDA0003517217700000032 
Figure BDA0003517217700000061
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of network intrusion detection, and in particular relates to a random forest intrusion detection method based on a multi-layer classification strategy. Background Art
[0002] With the rapid development of the network, its security is bound to be greatly threatened, and network attacks are increasing. Network intrusion detection is one of the important technologies to improve the security of network systems. Intrusion detection can be regarded as a classification problem, that is, to make binary or multi-classification judgments on host data and network traffic data. The classification problem in the field of network security has the characteristics of high dimensionality of intrusion feature data, large intra-class variance and small inter-class variance between different intrusion categories, so many intrusion patterns cannot be accurately detected. Therefore, how to improve the efficiency and accuracy of network intrusion detection is the focus of current research.
[0003] In recent years, with the deepening of research on machine learning and deep learning, it has become possible to extract feature information from high-dimensional network intrusion detection data. However, in multi-category classification, there is often a problem of uneven distribution of data categories. Current classifiers trained on unbalanced data are prone to shifting the extracted features to large sample space, and even ignoring a few small category samples during classification, resulting in a low detection rate for small sample category data.
[0004] Random forest is an ensemble learning method of decision trees. It inherits the advantages of decision tree classification and the characteristics of high fault tolerance. It performs better than traditional deep learning algorithms such as SVM and KNN in a large number of classification and regression problems. Combining random forest with other classification algorithms to construct intrusion detection models can also improve detection accuracy. However, the data imbalance problem in which abnormal traffic in traffic data is far less than normal traffic is still a major bottleneck in the development of intrusion detection technology based on traditional machine learning methods. Summary of the invention
[0005] In view of the deficiencies pointed out in the above background technology, the present invention provides a random forest intrusion detection method based on a multi-layer classification strategy, aiming to solve the problem of uneven distribution of sample data categories and low detection rate for small sample category data in the existing intrusion detection methods in the above background technology.
[0006] To achieve the above object, the technical solution adopted by the present invention is:
[0007] A random forest intrusion detection method based on a multi-layer classification strategy, the method comprising the following steps:
[0008] (1) Preprocessing the intrusion detection data, including deformed sample processing, classification data and time series data encoding, data scaling, and feature selection and extraction;
[0009] (2) Building a multi-layer classification model
[0010] ① Calculate the similarity between each sample category in the preprocessed test set, and cluster classes with similar features into superclasses based on the similarity;
[0011] ② Taking the superclass as a layer, classifying it through the random forest algorithm, and selecting a feature subset for the model decision node of the superclass classification;
[0012] ③ Segment the superclass of this layer according to the selected feature subset;
[0013] ④ The single superclass after segmentation is sent to the next layer for classification again. In the next layer of classification, the superclasses are still divided according to the similarity between each sample category in the superclass of this layer. Repeat steps ② and ③, recursively divide the superclass into smaller categories, and continue to iterate until all small categories are divided.
[0014] Preferably, in the processing of the deformed samples, the data in the test set does not need to be processed; in the encoding of the classified data and time series data, the three classified data feature identifiers protocol_type, service and flag contained in the data set are binarized to form new features, and the new features are connected with other data features to form a feature-free label data set.
[0015] Preferably, the feature selection and extraction adopts the principal component analysis (PCA) method. PCA belongs to an unsupervised feature selection and extraction method, which can achieve the purpose of reducing dimension and information noise reduction. The goal of PCA is to represent the original high-dimensional features with a few unrelated comprehensive variables and to retain most of the information of the original data.
[0016] Preferably, the similarity calculation method between the sample categories is as follows:
[0017] First, the sample feature mean H within the category is calculated using the following formula: i :
[0018]
[0019] Among them, i represents the current category, j represents the sample, and I i represents the sample set of category i, h j is the jth sample vector, H i is the average feature of category i;
[0020] Then, the Euclidean distance κ between categories is usedt (i, j) represents the similarity between sample categories, κ t The calculation formula of (i, j) is as follows:
[0021]
[0022] Preferably, the feature subset is selected by a supervised learning feature selection algorithm, and each layer uses a different feature selection algorithm so that the sample division of each layer can match the most suitable feature subset.
[0023] Preferably, the random forest algorithm is as follows:
[0024] a. Let the training set be T, which contains N samples, that is, T = {t1, t2, ...t N}, let the feature set be F, with M-dimensional features, that is, F = {f1,f2,...f M}, the category set is C, there are L categories, that is, C = {c1,c2,...c L}, the test set is D, with λ test samples, that is, D = {d1, d2, ...c λ};
[0025] b. From the training set T with a capacity of N, use the bootstrap sampling method, that is, extract N samples with replacement as a training subset T k ;
[0026] c. For the training subset T k , randomly extract m features from the feature set F without replacement, where m = log2M, as the basis for splitting each node on the decision tree, starting from the root node, and generating a complete decision tree S from top to bottom k , no pruning is required;
[0027] d. Repeat steps a and b n times to obtain n training subsets T1, T2, ...T n , and generate decision trees S1,S2,...S n , combine n decision trees to form a random forest;
[0028] e. Sample d of test set D μ Input into the random forest, let each decision tree have d μ Make a decision, then use majority voting to vote on the decision results, and finally decide d μ Classification of
[0029] f. Repeat step e for λ times until the classification of the test set D is completed.
[0030] Compared with the shortcomings and deficiencies of the prior art, the present invention has the following beneficial effects:
[0031] (1) The present invention introduces a multi-layer classification strategy, and designs an intrusion detection model based on a random forest of multi-layer classification strategy. Different superclasses are divided at different layers, and different feature selection algorithms are used at each layer, so that the sample division of each layer can match the most suitable feature subset. After the superclass is divided, the superclass is recursively divided into smaller categories, and it is continuously iterated until all small categories are divided. Compared with random forest, the present invention can solve the problem of uneven distribution of sample categories and improve the accuracy of small sample category classification.
[0032] (2) The present invention removes data noise, reduces data dimension, reduces training time and improves computing performance through data preprocessing; removes redundant and irrelevant features through feature selection and extraction, selects the optimal feature subset from the original feature space, so that it has better classification performance than the original feature space, and reduces the time used for data processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 It is a schematic diagram of the random forest decision-making method.
[0034] Figure 2 It is a simple schematic diagram of a multi-layer classification method.
[0035] Figure 3 It is a schematic diagram of the hierarchical construction process of the multi-layer classification model.
[0036] Figure 4 This is a schematic diagram of the random forest generation process.
[0037] Figure 5 It is a feature distance matrix diagram of five categories.
[0038] Figure 6 This is a comparison chart of the confusion matrix of the random forest and multi-layer classification models under the test set. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0040] 1. Random Forest
[0041] Random forest is a bagging ensemble learning method. Bagging is to randomly select different samples from the total samples to train each classifier. Classifiers can be trained in parallel and are widely used in the field of classification and regression. Random forest generates multiple groups of decision trees through bagging to obtain different classification strategies, and then executes the judgment algorithm (such as taking the expected predicted value) to achieve the purpose of integrating all classification strategies and improving classifier performance. Figure 1 The random forest learning method is explained. Assuming that the length of the regression output vector is 3, the random forest first trains n groups of decision trees to obtain the prediction probability of each group, and then averages the n groups of output probabilities to obtain the final output of the random forest.
[0042] 2. Multi-layer classification
[0043] Multi-layer classification is a method to solve the problem of unbalanced classification tasks by simulating the information composition mode of humans and reconstructing the hierarchical structure existing in big data or manually annotated into a hierarchical structure on categories. Its principle is to train small-scale sample categories, aggregate a large number of small-scale categories into super categories with a large number of samples, and use samples of similar categories to reduce the imbalance of training and solve the problem of category imbalance. Figure 2 A simple multi-level classification approach is illustrated.
[0044] 3. Random forest intrusion detection method based on multi-layer classification strategy
[0045] 3.1 Data Preprocessing
[0046] The main purpose of data preprocessing is to remove data noise, reduce data dimension, reduce training time and improve computing performance. The main steps include deformed sample processing, classification data and time series data encoding, data scaling, and feature selection and extraction.
[0047] (1) In the processing of deformed samples, the test set contains several attack method data that do not exist in the training set. When using the test set for model verification, these data can be used as noise data to test the generalization performance of the model, so no processing is required in the experiment.
[0048] (2) In the encoding of categorical data and time series data, the dataset contains three categorical data features, namely protocol_type, service and flag. Protocol_type has three identifiers, service has 72 identifiers, and flag has 11 identifiers. These three feature identifiers are processed by label binarizer to form a total of 83 new features. These 83 features are connected with other data features to form an unlabeled dataset with 122 features.
[0049] (3) Data scaling methods include logarithmic scaling, standardization, normalization and centering. In the subsequent experiments of the present invention, data standardization is selected. Formulas (1) to (3) describe the standardization method:
[0050]
[0051]
[0052]
[0053] where μ f , σ f is the mean and standard deviation of a set of characteristic data, f i is the i-th group of data in the feature.
[0054] (4) Feature selection and extraction
[0055] The purpose of feature selection and extraction is to remove redundant and irrelevant features, select the optimal feature subset from the original feature space, make it have better classification performance than the original feature space, and reduce the time used for data processing. Traditional methods mainly include high-dimensional space mapping (such as kernel function), principal component analysis (PCA), linear discriminant analysis (LDA), etc. Among them, LDA belongs to supervised learning, which requires label data in the preprocessing stage, which is inconsistent with the actual situation; PCA belongs to unsupervised feature selection and extraction method, which can achieve the purpose of reducing dimension and information noise reduction.
[0056] The present invention uses the PCA method. The goal of PCA is to use a linear combination of a few variable features to explain the variance-covariance structure of random variables as completely as possible. The comprehensive variable with the largest variance among all combinations is called the first principal component, and then the second and third principal components can be selected in turn until the selected comprehensive variable can represent enough original data information. The specific method is as follows:
[0057] Assume that the input data is m n-dimensional vectors, represented as {X i |1≤i≤m}, the matrix form is expressed as:
[0058]
[0059] The input data is mapped to the new feature space through an n×n orthogonal matrix U, as shown in formula (5):
[0060] Y=X·U (5)
[0061] where y i =x i U. The covariance matrices of X and Y are shown in formula (6):
[0062]
[0063] C X The eigenvalues and their corresponding eigenvector pairs of C are denoted in descending order as (λ1, e1), (λ2, e2),..., (λ m , e m ), where λ1 ≥ λ2 ≥... ≥ λ m ≥ 0, and the following conditions are satisfied: y i , y i (i ≠ j) are uncorrelated. Among all linear combinations of x i , y i has the largest variance. y2 is uncorrelated with y1 and has the largest variance, and so on. y i , y i (i ≠ j) is uncorrelated with y1, y2,..., y i-1 and has the largest variance. To control the variance of Y, it is specified that u i u i T = 1. When u1 = e1, the first principal component can be obtained. In a similar way, the values of the i-th principal component can be obtained successively. The obtained principal components are linear combinations with the orthogonal eigenvectors of the covariance matrix C X as coefficients. The coefficient of the i-th principal component corresponds to the eigenvector e i of the i-th covariance eigenvalue λ1 = 1. p principal components can be used to replace the original n-dimensional features for data analysis (p < n). The variance contribution rate of a certain principal component is defined as shown in Equation (7):
[0064]
[0065] The cumulative variance contribution rate of p principal components is denoted as which represents the degree to which it can summarize the information provided by the original variables and is determined by the variance contribution rate.
[0066] 3.2 Construction of the multi-layer classification model
[0067] The hierarchical construction process of the multi-layer classification model is as Figure 3 shown, and the steps are as follows:
[0068] (1) Calculate the similarity between each sample category in the preprocessed test set, and cluster the classes with similar features into superclasses according to the similarity.
[0069] The method for calculating the similarity between sample categories is as follows:
[0070] First, calculate the mean value H of the sample features within the category using the following formula i :
[0071]
[0072] Among them, i represents the current category, j represents the sample, and I i represents the sample set of category i, h j is the jth sample vector, H i is the average feature of category i;
[0073] Then, the Euclidean distance κ between categories is used t (i, j) represents the similarity between sample categories, κ t The calculation formula of (i, j) is as follows:
[0074]
[0075] (2) The superclass is regarded as a layer and classified by random forest algorithm, and the feature subset is selected for the model decision node of the superclass classification; the feature subset is selected by the feature selection algorithm of supervised learning method, so that the sample division of each layer can match the most suitable feature subset.
[0076] (3) Segment the superclasses of this layer according to the selected feature subset;
[0077] (4) The split single superclass is sent to the next layer, and the superclass is re-divided according to the similarity between each sample category in the single superclass. Steps (2) and (3) are repeated, and it is gradually iterated until the superclass only contains each small class, completing the classification of the test set.
[0078] 3.3 Random Forest Generation Process
[0079] The random forest generation process is as follows Figure 4 As shown, the steps are as follows:
[0080] (1) Let the training set be T, which contains N samples, that is, T = {t1, t2, ...t N}, let the feature set be F, with M-dimensional features, that is, F = {f1,f2,...f M}, the category set is C, there are L categories, that is, C = {c1,c2,...c L}, the test set is D, with λ test samples, that is, D = {d1, d2, ...c λ};
[0081] (2) From the training set T of capacity N, use the bootstrap method, that is, extract N samples with replacement as a training subset T k ;
[0082] (3) For the training subset T k, randomly extract m features from the feature set F without replacement, where m = log2 M (rounded up), as the basis for splitting each node on the decision tree, starting from the root node, and generating a complete decision tree S from top to bottom k , no pruning is required;
[0083] (4) Repeat steps a and b n times to obtain n training subsets T1, T2, ...T n , and generate decision trees S1,S2,...S n , combine n decision trees to form a random forest;
[0084] (5) Sample d of the test set D μ Input into the random forest, let each decision tree have d μ Make a decision, then use majority voting to vote on the decision results, and finally decide d μ Classification of
[0085] (6) Repeat step e for λ times until the classification of the test set D is completed.
[0086] 4. Experimental test
[0087] For the multi-layer classification model, two different superclass division methods are used for experiments. First, by using the method based on the number of class samples to establish superclasses for small sample data, it is verified that the multi-layer classification model can improve the detection rate of small samples. Then, in the constructed superclass layer, a suitable supervised feature selection algorithm is selected to improve the model and obtain a model with better performance.
[0088] Experiment 1:
[0089] A simple 5-layer sample classification model is chosen to classify the intrusion detection data in order to verify that the multi-layer classification model can improve the detection rate of small samples. Figure 5 is the characteristic distance matrix of five categories, where the category feature is obtained by the mean of all samples of the category. Figure 5 It can be seen that the feature distances between the Normal class and other categories are basically the same, between 2 and 3, and the distances of Probe-U2R and R2L-U2R are more than 3, while the other distances are between 1 and 2.95. Considering the number of samples, the first layer can directly transform Normal into a superclass, and transform the other four categories into superclasses for calculation. After the Normal category is separated, Probe-U2R-R2L is used as a superclass to separate Dos. Here, the data of a single category is separated at each layer to perform stratification, and so on, until the 5th layer.
[0090] Experimental conditions: After the NSL-KDD dataset is digitized, the 122-dimensional feature data is directly processed into 50-bit sample data using PCA before the first layer and used as sample data for the experiment. The reason for choosing 5 layers is that for this superclass construction method, one type of sample data is separated from the superclass each time, so 5 separations are required in the end. The model construction information is shown in Table 1:
[0091] Table 1 Five-layer sample classification model for Experiment 1
[0092]
[0093] In Table 1, the first layer model performs the binary classification task of Normal and Abnormal. Since GC-Forest is proven to have the highest overall detection rate, it is selected as the model of this layer, and an average accuracy of 83.66% is obtained. The random forest model is used in the second, third and fourth layers because the number of samples in these three layers is 58630, 12703, 1047, etc., respectively, which is suitable for using the random forest model for binary classification. In the last layer, the number of samples is small and unevenly distributed, so the SVM algorithm is selected to supplement it.
[0094] Figure 6 This is the comparison of the confusion matrix of the random forest and multi-layer classification models under the test set. Figure 6 In the right figure, since there is no information about other small categories in each superclass calculation process, only the number of false positive samples can be counted (the data in the lower left part of the matrix represents the total number of false positive samples excluding the data on the diagonal columns), but the number of missed positive samples cannot be determined (the upper right part cannot be counted). The detection rate statistics of the two models, random forest and multi-layer classification model, are shown in Table 2:
[0095] Table 2 Comparison of detection rates of the two models in Experiment 1
[0096]
[0097] As shown in Table 2, the multi-layer classification model can improve the accuracy of small sample classification, especially in the two scarce sample data classifications of U2R type and R2L type, each of which has a significant improvement, about 16% and 35% respectively. However, in the classification of sample data of the Normal category, the detection rate is reduced by about 4%. The accuracy of the random forest model is 74.12%, and the accuracy of the multi-layer classification model is 75.41%. Therefore, although the multi-layer classification improves the classification accuracy of small samples, it also sacrifices the sample accuracy of large samples, resulting in a small improvement in the final detection rate.
[0098] Experiment 2:
[0099] Based on Experiment 1, the first layer of Experiment 2 uses the same parameters as the first layer of Experiment 1, and both use PCA for feature extraction. Before superclass detection in each other layer, the CES algorithm is used to perform supervised feature extraction based on the original 122-dimensional sample data, and then classification is performed. The sample dimensions extracted by CES at each layer and the classification accuracy of each layer are shown in Table 3:
[0100] Table 3 Five-layer sample classification model of Experiment 2
[0101]
[0102] The comparison of detection rates of the two multi-layer classification models in Experiment 1 and Experiment 2 is shown in Table 4:
[0103] Table 4 Comparison of detection rates of the two models in Experiment 1 and Experiment 2
[0104]
[0105] As can be seen from Table 4, in Experiment 2, the detection rate has been improved to varying degrees in each layer due to the selection of a suitable feature selection algorithm. After five layers of accumulation, the overall detection rate has increased by 5.17%. Therefore, the multi-layer classification model can improve the detection rate of small samples while ensuring the detection rate of large samples, thereby improving the overall detection rate, and can play a certain role in improving the random forest intrusion detection algorithm.
[0106] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for generating a random forest intrusion detection model based on a multi-layer classification strategy, characterized in that: The following steps are involved: (1) Preprocessing of intrusion detection data, including deformed sample processing, classification data and time series data encoding, data scaling, and feature selection and extraction; (2) Building a multi-layer classification model ① Calculate the similarity between each sample category in the preprocessed test set, and cluster classes with similar features into superclasses based on the similarity; ② Taking the superclass as a layer, classifying it through the random forest algorithm, and selecting a feature subset for the model decision node of the superclass classification; The algorithm of the random forest is as follows: a. Let the training set be T, which contains N samples, that is, T = {t1, t2, ...t N }, let the feature set be F, with M-dimensional features, that is, F = {f1,f2,...f M }, the category set is C, there are L categories, that is, C = {c1,c2,...c L }, the test set is D, with λ test samples, that is, D = {d1, d2, ...c λ }; b. From the training set T with a capacity of N, use the bootstrap sampling method, that is, extract N samples with replacement as a training subset T k ; c. For the training subset T k , randomly extract m features from the feature set F without replacement, where m = log2M, as the basis for splitting each node on the decision tree, starting from the root node, and generating a complete decision tree S from top to bottom k , no pruning is required; d. Repeat steps a and b n times to obtain n training subsets T1, T2, ...T n , and generate decision trees S1,S2,...S n , combine n decision trees to form a random forest; e. Sample d of the test set D μ Input into the random forest, let each decision tree have d μ Make a decision, then use majority voting to vote on the decision results, and finally decide d μ Classification of f. Repeat step e for λ times until the classification of the test set D is completed; ③ Segment the superclass of this layer according to the selected feature subset; ④ Send the split single superclass to the next layer, and re-divide the superclass according to the similarity between each sample category in the single superclass, repeat steps ② and ③, and gradually iterate until the superclass only contains each small class to complete the test set classification.
2. The method for generating a random forest intrusion detection model based on a multi-layer classification strategy as claimed in claim 1, characterized in that: In the processing of the deformed samples, the data in the test set does not need to be processed; in the encoding of the classified data and time series data, the three classified data feature identifiers protocol_type, service and flag contained in the data set are binarized to form new features, and the new features are connected with other data features to form a feature-free label data set.
3. The method for generating a random forest intrusion detection model based on a multi-layer classification strategy as claimed in claim 1, characterized in that: The feature selection and extraction adopts the principal component analysis method.
4. The method for generating a random forest intrusion detection model based on a multi-layer classification strategy as claimed in claim 1, characterized in that: The similarity calculation method between the sample categories is as follows: First, the sample feature mean H within the category is calculated using the following formula: i : Among them, i represents the current category, j represents the sample, and I i represents the sample set of category i, h j is the jth sample vector, H i is the average feature of category i; Then, the Euclidean distance κ between categories is used t (i, j) represents the similarity between sample categories, κ t The calculation formula of (i, j) is as follows:
5. The method for generating a random forest intrusion detection model based on a multi-layer classification strategy as claimed in claim 1, characterized in that: The feature subset is selected by using a supervised learning feature selection algorithm.
Citation Information
Patent Citations
A method of prediction model based on random forest algorithm
AU2020100709A4
Intrusion detection method based on PCA and random forest classification
CN107395590A
Wireless sensor network intrusion detection method based on deep learning
CN108234500A
Network intrusion detection method based on machine learning
CN110213222A
Rare attack-oriented network intrusion detection method
CN112087447A
