A Bayes-LightGBM software defect prediction method based on RFECV feature selection
Through RFECV feature selection and Bayesian optimization algorithm, the problem of high-dimensional feature sets in software defect prediction is solved, the prediction performance and efficiency are improved, and the calculation cost is reduced.
Patent Information
- Application Number
- CN202210300157.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-25
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2042-03-25
AI Technical Summary
In software defect prediction, the high-dimensional feature set obtained by static code inspection tools leads to increased computational costs and reduced recognition performance of the classifier, and feature selection methods are required to optimize the number of features.
The Bayes-LightGBM method based on RFECV feature selection is adopted, and the feature combination with the highest cross-validation score is selected through the combined feature selection of random forest and RFECV, and the Bayesian optimization algorithm is used to tune the hyperparameters of the LightGBM model.
It effectively reduces the number of features, improves the performance of the software defect prediction model, improves prediction performance and efficiency, and reduces computing costs.
Smart Images

Figure CN114860298B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software defect prediction, and in particular to a Bayes-LightGBM software defect prediction method based on RFECV feature selection. Background Art
[0002] Software defects are unavoidable problems in the software development process, and software defects can bring harm to software projects. In the software development cycle, the later the existing software defects are discovered, the higher the cost of repairing the software defects, and the greater the damage to the software system. Therefore, avoiding and reducing the occurrence of software defects as early as possible will greatly improve software quality. Software defect prediction is a feasible method. This method extracts features related to software defects by mining software code and historical submission records, and learns to build a software defect prediction model through machine learning or neural network models to predict the occurrence of software defects. Therefore, an effective software defect prediction method can avoid the occurrence of software defects to a large extent.
[0003] Yan Lingling et al. proposed a software defect prediction method based on mixed sampling and Random_Stacking. This method samples the unbalanced data set through a mixed sampling algorithm and uses the Stacking classifier to predict software defects. It has better performance than existing algorithms.
[0004] Wang Fang proposed to perform imbalance processing on the unbalanced software defect dataset before prediction, and found that it has better software defect prediction performance and alleviates the category imbalance problem to a certain extent. Summary of the invention
[0005] In view of the above-mentioned defects of the prior art, the technical problem to be solved by the present invention is that in the field of software defects, many features can often be obtained by checking the code through static code checking tools, resulting in too many features. The use of the original high-dimensional feature set will not only increase the computational cost of the classifier, but also may reduce its recognition performance, so it is necessary to use a feature selection method to optimize the number of features. The present invention provides a Bayes-LightGBM software defect prediction method based on RFECV feature selection, based on a combined feature selection method of random forest and RFECV, from a software defect data set, selects relevant features that have a gain on the software defect prediction model, and uses the LightGBM algorithm based on Bayesian optimization to make the software defect prediction model have better prediction performance.
[0006] To achieve the above object, the present invention provides a Bayes-LightGBM software defect prediction method based on RFECV feature selection, comprising the following steps:
[0007] Standardize the original data set;
[0008] Then, the combined feature selection method of random forest and RFECV was used on the standardized data set to select the feature combination with the highest cross-validation score;
[0009] Then use the Bayes-LightGBM algorithm to build a prediction model to predict whether software defects will occur based on the features in the data set.
[0010] Furthermore, the standardization operation of the original data set specifically includes:
[0011] Standardize the original data using StandardScaler to normalize the original data;
[0012] The normalized data were subjected to RobustScaler standardization to remove outliers outside the quartiles.
[0013] Furthermore, the combined feature selection method of random forest and RFECV is used on the standardized data set to select the feature combination with the highest cross-validation score. The random forest algorithm is used as a feature evaluator to evaluate the scores of feature subsets, and the RFECV algorithm is used to select the feature subset with the highest score.
[0014] Furthermore, the combined feature selection method of random forest and RFECV is used on the standardized data set to select the feature combination with the highest cross-validation score, including the following steps:
[0015] All initial features are used as the currently available feature combination, and then the current feature combination is used to calculate the feature importance score of each feature;
[0016] Delete one or more features with the lowest feature importance score, and then update the current feature combination;
[0017] According to the current feature combination determined in the RFE stage, cross-validate the selected feature combination;
[0018] Then use the random forest evaluator to model and score the selected feature set, and then return to the RFE stage and repeat the above steps until the cross-validation scoring of all feature combinations is completed;
[0019] The feature combination with the highest cross-validation score is selected as the optimal feature combination.
[0020] Furthermore, RFECV includes an RFE stage and a CV stage, wherein the RFE stage is used for recursive feature elimination and the CV stage is used for cross-validation.
[0021] Furthermore, the RFE stage includes the following steps:
[0022] Set all features in the data set as the initial feature combination;
[0023] Use the current feature set for modeling and calculate the feature importance of each feature in the current feature set;
[0024] According to the calculated feature importance and sorting, delete the least important feature or features, and then update the feature combination;
[0025] The updated feature combinations are modeled again, and the above steps are repeated until all feature combinations are scored by the cross-validation random forest evaluator.
[0026] Furthermore, the CV phase includes the following steps:
[0027] According to the feature importance determined in the RFE phase, the updated feature set is cross-validated;
[0028] The updated feature set is scored using the evaluator to determine the number and features of the features with the highest average score, and finally the feature set selection is completed; specifically, the feature combination is updated after each feature is deleted, which is a set of feature combinations, and n sets of feature combinations are obtained repeatedly until no features can be deleted; then for each feature combination, the random forest evaluator is used for cross-validation scoring, and the feature combination with the cross-validation score is selected based on the cross-validation score of each group of feature combinations, which is the feature combination with the best performance.
[0029] Furthermore, the Bayes-LightGBM algorithm is used to build a prediction model to predict whether a software defect will occur based on the features in the data set. The specific steps include:
[0030] After selecting appropriate features in the initial data set using RFECV and random forest algorithms, a new data set after feature selection is constructed;
[0031] The new data set is divided into training set and test set in a ratio of 8:2;
[0032] Use the Bayesian optimization algorithm to optimize the hyperparameters of LightGBM and obtain the Bayes-LightGBM prediction model;
[0033] Use K-fold cross validation to train the Bayes-LightGBM prediction model;
[0034] Based on the comparison between the test set and the prediction results, the AUC value of the prediction model is obtained. The higher the AUC value obtained, the better the classification performance of the software defect prediction model.
[0035] Technical Effects
[0036] The Bayes-LightGBM software defect prediction method based on RFECV feature selection of the present invention aims at the problem of too many software defect features in the software defect data set, and proposes a combined feature selection method based on random forest and RFECV. The method can not only select the best feature combination, but also indicate the cross-validation score of each combination, so that the selected best feature combination is more convincing, and the software defect prediction model has better prediction performance. At the same time, Bayesian optimization is proposed to perform hyperparameter tuning, so that the software defect prediction model has better prediction performance.
[0037] The concept, specific structure and technical effects of the present invention will be further described below in conjunction with the accompanying drawings to fully understand the purpose, characteristics and effects of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a flow chart of a Bayes-LightGBM software defect prediction method based on RFECV feature selection in a preferred embodiment of the present invention;
[0039] Figure 2 It is a statistical graph of raw data of a Bayes-LightGBM software defect prediction method based on RFECV feature selection in a preferred embodiment of the present invention;
[0040] Figure 3 It is a normalized data statistical graph of a Bayes-LightGBM software defect prediction method based on RFECV feature selection in a preferred embodiment of the present invention;
[0041] Figure 4 It is a standardized data statistical diagram of a Bayes-LightGBM software defect prediction method based on RFECV feature selection in a preferred embodiment of the present invention;
[0042] Figure 5 It is a cross-validation score graph of a Bayes-LightGBM software defect prediction method based on RFECV feature selection in a preferred embodiment of the present invention;
[0043] Figure 6 It is a schematic diagram of the feature importance ranking of the original data set of a Bayes-LightGBM software defect prediction method based on RFECV feature selection in a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to make the technical problems, technical solutions and beneficial effects to be solved by 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.
[0045] In the following description, specific details such as specific internal procedures and techniques are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.
[0046] like Figure 1 As shown, the embodiment of the present invention provides a Bayes-LightGBM software defect prediction method based on RFECV feature selection, comprising the following steps:
[0047] Step 100, standardizing the original data set; specifically including:
[0048] Standardize the original data using StandardScaler to normalize the original data;
[0049] The normalized data were subjected to RobustScaler standardization to remove outliers outside the quartiles.
[0050] Step 200, then use the combined feature selection method of random forest and RFECV on the standardized data set to select the feature combination with the highest cross-validation score; specifically including:
[0051] Step 200-1, using the standardized data set as a new data set;
[0052] Step 200-2, for the new data set, use the RFE algorithm to perform feature elimination, to rate the importance of the features, and update the new data set;
[0053] Step 200-3, after rating the features of the updated new data set using the CV algorithm, cross-validate the feature set;
[0054] Step 200-4, using the random forest algorithm as an evaluator, scoring the feature set in the cross-validation stage to obtain a cross-validation score of the feature set;
[0055] Step 200-5, repeating steps 200-2 to 200-4 until all features in the original feature set are eliminated;
[0056] Step 200 - 6 , selecting the feature set with the highest cross-validation score as the feature for software defect prediction and as the data set for software defect prediction.
[0057] Step 300, using the Bayes-LightGBM algorithm to build a prediction model, based on the features in the data set, to predict whether a software defect will occur; specifically including:
[0058] Step 300-1, dividing the software defect prediction data set into a training set and a test set in a ratio of 8:2;
[0059] Step 300-2, using the training set, training the LightGBM prediction model;
[0060] Step 300-3, using the Bayesian optimization algorithm to optimize the hyperparameters of the LightGBM prediction model, and the prediction model after the hyperparameter optimization is called the Bayes-LightGBM prediction model;
[0061] Step 300-4, using the Bayes-LightGBM prediction model to predict the test set, obtain the predicted results, and compare them with the actual results;
[0062] Step 300-5, based on the comparison between the predicted result and the actual result, an AUC value is obtained. The larger the AUC value, the better the software defect prediction model is.
[0063] Among them, step 200, using the combined feature selection method of random forest and RFECV on the standardized data set to select the feature combination with the highest cross-validation score, is to use the random forest algorithm as a feature evaluator to evaluate the score of the feature subset, and use the RFECV algorithm to select the feature subset with the highest score; therefore, using the combined feature selection method of random forest and RFECV on the standardized data set to select the feature combination with the highest cross-validation score includes the following steps:
[0064] In this step, the specific steps of the combined feature selection method using random forest and RFECV are as follows:
[0065] 1. Use the original data set as the current feature combination; the original data set contains 166 features, but too many features will cause the prediction model to overfit, so feature selection is performed to select appropriate features from the features in the original data set;
[0066] 2. Calculate the importance rating of each feature in the feature combination;
[0067] 3. Delete the feature with the lowest importance rating in the feature combination;
[0068] 4. Update the feature combination after deleting the feature with the lowest importance to the current feature combination;
[0069] 5. Cross-validate the current feature combination;
[0070] 6. During the cross-validation process, use random forest as an evaluator to evaluate the current feature combination;
[0071] 7. Get the cross-validation score of the current feature combination;
[0072] 8. Jump to step 2 and repeat the above steps until there are no features to delete in the current feature combination;
[0073] 9. Among the past feature combinations, select the feature combination with the highest cross-validation score as the optimal feature combination, and the algorithm of this step is completed.
[0074] Among them, RFECV includes the RFE stage for recursive feature elimination and the CV stage for cross-validation.
[0075] The RFE phase includes the following steps:
[0076] The steps of the RFE phase are briefly described as follows:
[0077] 1. Use the original dataset as the current feature combination.
[0078] 2. Calculate the importance rating of each feature in the feature combination.
[0079] 3. Delete the feature with the lowest importance rating in the feature combination.
[0080] 4. Update the feature combination after deleting the feature with the lowest importance to the current feature combination.
[0081] Specifically:
[0082] Set all available features to the initial feature set;
[0083] Use the current feature set for modeling and calculate the feature importance of each feature in the current feature set;
[0084] According to the calculated feature importance and sorting, delete the least important feature or features, and then update the feature set;
[0085] The updated feature set is modeled again and the above steps are repeated until the importance rating of all features is completed.
[0086] The CV phase comes after the RFE phase, but both phases must be cycled. The CV phase includes the following steps:
[0087] 1. Perform cross-validation on the current feature combination.
[0088] 2. During the cross-validation process, random forest is used as an evaluator to evaluate the current feature combination.
[0089] 3. Get the cross-validation score of the current feature combination.
[0090] Specifically:
[0091] Based on the feature importance determined in the RFE phase, the selected feature set is cross-validated;
[0092] The evaluator is used to score the feature set, determine the number and features with the highest average score, and finally complete the feature set selection.
[0093] Step 300, using the Bayes-LightGBM algorithm to build a prediction model, based on the features in the data set, to predict whether a software defect will occur, specifically including the following steps:
[0094] Step 300 - 1 , divide the software defect prediction data set into a training set and a test set in a ratio of 8:2.
[0095] Step 300-2, using the training set, train the LightGBM prediction model.
[0096] Step 300-3, using the Bayesian optimization algorithm, optimizes the hyperparameters of the LightGBM prediction model, and the prediction model after the hyperparameter optimization is called the Bayes-LightGBM prediction model.
[0097] Step 300-4, use the Bayes-LightGBM prediction model to predict the test set, obtain the predicted results, and compare them with the actual results.
[0098] Step 300-5, based on the comparison between the predicted result and the actual result, an AUC value is obtained. The larger the AUC value, the better the software defect prediction model is.
[0099] The embodiment of the present invention uses the Baseline-LightGBM algorithm and the Bayes-LightGBM algorithm to predict whether a software defect will occur based on the features in the data set for comparison. The Baseline-LightGBM algorithm and the Bayes-LightGBM algorithm are both performed on the same new data set after feature selection. Compared with the LightGBM algorithm with default hyperparameters, the Bayesian optimization of the LightGBM hyperparameters proposed in the embodiment of the present invention can further improve the prediction performance of the model.
[0100] The AUC evaluation index is used to illustrate that the software defect prediction method proposed in the embodiment of the present invention is effective. When the AUC index is less than 0.5, it means that the prediction method is worse than random prediction and is invalid.
[0101] Bayesian optimization refers to a method of using the Bayesian algorithm to optimize model hyperparameters during machine learning training. The machine learning model that generally uses the default hyperparameters is called the baseline model.
[0102] The default hyperparameters used by the baseline model generally do not represent the optimal model performance, because different hyperparameter combinations may lead to different model prediction performances, so it is necessary to adjust the model's hyperparameters. Manual parameter adjustment is not only time-consuming and laborious, but also often does not produce ideal results.
[0103] The Bayesian optimization algorithm is an efficient optimization algorithm. Mathematically, this problem can be uniformly described as finding the global optimal solution to the unknown objective function. The specific formula is shown in formula (1):
[0104] x = argmaxf(x), where (x∈X) # (1)
[0105] Where: x represents the parameter to be optimized; X represents the parameter set to be optimized; f(x) represents the objective function.
[0106] There are two key steps in executing the Bayesian optimization algorithm. First, choose a prior function to represent the distribution hypothesis of the optimized function. Generally, we choose a Gaussian process. Second, build a collection function to determine the next point to be evaluated from the posterior distribution of the model.
[0107] Bayesian optimization includes Gaussian process and acquisition function, as follows.
[0108] Gaussian process is an extension of multidimensional Gaussian distribution on infinite-dimensional random process. The specific formula of Gaussian process is shown in formula (2):
[0109] f(x)~GP(m(x),k(x,x′))#(2)
[0110] For convenience, the mean function is usually set to 0. i , f i )|i=1,2,...,n}, then there exists a Gaussian distribution that satisfies formula (3):
[0111] f~N(0,K(X,X))#(3)
[0112] The formula of the covariance matrix K(X, X) can be shown as formula (4):
[0113]
[0114] The acquisition function can be used to determine the next point to be evaluated, which can reduce the number of algorithm iterations and the cost of evaluation. There are three common acquisition functions: upper confidence bound (UCB), probability of improvement (PI), and expected improvement (EI). The embodiment of the present invention mainly introduces the PI function, and its specific formula is shown in formula (5):
[0115]
[0116] The hyperparameter v is used to adjust f(x + ) is the existing maximum value, v = 0 means that it tends to converge to f(x + ), and Φ() represents the normal cumulative distribution function. The principle is to find that the function value of the new point is better than f(x + ) has a large probability, and choose the point with the largest probability among these points.
[0117] The LightGBM algorithm is an iterative boosting tree system proposed by Microsoft. It is a variant of the gradient boosting decision tree (GBDT). The traditional gradient boosting decision tree generally only uses the first-order negative gradient of the loss function, while it uses the first and second order negative gradients of the loss function to calculate the residual of the current tree and use this result to fit the next round of new trees.
[0118] The LightGBM algorithm is mainly based on the traditional GBDT algorithm with the following optimizations:
[0119] 1) Decision tree algorithm based on Histogram;
[0120] 2) Gradient-on-One-Sided Sampling (GOSS): GOSS can reduce a large number of data instances with only small gradients, so that only data with high gradients can be used when calculating information gain. Compared with XGBoost traversing all features, it saves a lot of time and space overhead;
[0121] 3) Exclusive Feature Bundling (EFB): Using EFB, many mutually exclusive features can be bundled into one feature, thus achieving the purpose of dimensionality reduction;
[0122] 4) Leaf-wise growth strategy with depth limit: Most GBDT tools use the low-cost layer-wise decision tree growth strategy, because it treats leaves of the same layer indiscriminately, which brings a lot of unnecessary overhead. In fact, many leaves have low split gains and there is no need to search and split them. LightGBM uses a leaf-wise growth algorithm with depth limit.
[0123] 5) Directly support category features
[0124] 6) Support efficient parallelism
[0125] 7) Cache hit rate optimization
[0126] The Bayes-LightGBM software defect prediction method based on RFECV feature selection proposed in the embodiment of the present invention uses open source data sets to build a software defect prediction model.
[0127] The first step is to standardize the data set. Data standardization is divided into two stages. The first stage is StandardScaler standardization, and the second stage is RobustScaler standardization. Through these two stages of data standardization, a standardized data set is obtained.
[0128] The second step is to use a combined feature selection method based on random forest and RFECV. The random forest algorithm is used as a feature evaluator to evaluate the score of the feature subset, the RFECV algorithm is used to select the feature subset with the highest score, and the Baseline-LightGBM algorithm is used to build a prediction model to evaluate whether the classification model performance of the feature subset after feature selection is improved compared with using all feature sets;
[0129] The third step is to use the Bayesian optimization algorithm, which can optimize the hyperparameters of the Baseline-LightGBM algorithm and compare the Baseline-LightGBM algorithm before optimization with the Bayes-LightGBM algorithm after optimization to see whether the classification performance of the software defect prediction model has been improved. The specific process of the software defect prediction method is as follows Figure 1 shown.
[0130] In the data preprocessing stage, a key step is data standardization. Because different features may have different dimensions and dimensional units, this situation will affect the results of data analysis. Therefore, in order to eliminate the dimensional impact between indicators, data standardization is required to solve the different dimensions between data indicators and make them at the same order of magnitude, which is convenient for subsequent comparison and evaluation.
[0131] Considering that the data set itself has a large number of sample features with values of 0 and a certain amount of sample outlier values, the embodiment of the present invention mixes the StandardScaler and RobustScaler methods to preprocess the data set, standardize the data set, normally distribute it around 0, and eliminate some outliers.
[0132] StandardScaler standardization can also be called standard deviation standardization. This method uses the mean and variance to process data that obeys the normal distribution to obtain data that conforms to the standard normal distribution. This standardization processing method is to subtract the mean from the standardized data and then divide it by the standard deviation. The processed data conforms to the standard normal distribution, that is, the mean is 0 and the standard deviation is 1. It is suitable for situations where there are no obvious boundaries and extreme data values may appear. The conversion function is shown in formula (6):
[0133]
[0134] RobustScaler standardization can also be called robust standardization. This method uses robust statistics to scale data with outliers. This scaler removes the median and scales the data according to the percentile range (the default value is IQR: interquartile range). IQR refers to the range between the first quartile (25%) and the third quartile (75%). The conversion function is shown in formula (7):
[0135]
[0136] The model evaluation index used in the embodiment of the present invention is AUC, whose full name is Area Under the Curve, which expresses the area under the ROC curve.
[0137] AUC is a common indicator used to evaluate the performance of classification models. Its advantage is that it is applicable to scenarios where the distribution of positive and negative samples is inconsistent. The larger the AUC value, the better the performance of the classification model, and the maximum value can be 1; when the AUC value is less than 0.5, it can be considered that the classification model is meaningless.
[0138] The specific implementation method of the embodiment of the present invention is as follows:
[0139] There are 166 features in the original dataset, so only some of them are selected as examples.
[0140] The statistics of the original data set are as follows Figure 2 As shown:
[0141] After the original data set is normalized, the normalized data statistics are as follows: Figure 3 As shown;
[0142] After standardization, the standardized data statistics are as follows: Figure 4 As shown:
[0143] After the combined feature selection algorithm of random forest and RFECV, the cross-validation scores of various feature combinations are obtained. It can be found that when the feature combination is 43, the cross-validation score is the highest, with a score of 0.9718. The cross-validation score is shown in the figure below: Figure 5 As shown:
[0144] In addition, the embodiment of the present invention obtains a ranking of feature importance, wherein there are 43 features with a feature importance ranking of 1. These 43 selected features are used as a new data set. The feature importance ranking of the original data set is as follows: Figure 6 As shown:
[0145] Therefore, the subsequent feature combination of the embodiment of the present invention selects these 43 features as the feature set for software defect prediction.
[0146] In terms of machine learning models, the Baseline-LightGBM algorithm is used to build a software defect prediction model for the data set before and after using the RFECV feature selection algorithm, and AUC is used as the model evaluation indicator to evaluate the model performance.
[0147] Table 2 shows the comparison of the AUC values of the model before and after using the RFECV algorithm. The results show that after using the RFECV algorithm, the AUC value of the prediction model increased from 0.8715 to 0.8772, and the AUC value increased by 0.0057, proving that this method is effective.
[0148] Table 2 Comparison of AUC values of the models before and after RFECV algorithm
[0149] Before RFECV algorithm After RFECV algorithm AUC 0.8515 <![CDATA[ 0.8582 ]]>
[0150] The embodiment of the present invention uses a data set after feature selection based on the RFECV algorithm and performs Bayesian optimization. Compare the Baseline-LightGBM algorithm before Bayesian optimization with the Bayes-LightGBM algorithm after Bayesian optimization to see whether the model performance is improved.
[0151] Table 3 shows the comparison of AUC values of the LightGBM algorithm model before and after Bayesian optimization. The results show that after Bayesian optimization, the AUC value of the LightGBM algorithm model increased from 0.8973 to 0.9223, an increase of 0.025, proving that the Bayesian optimization algorithm is effective.
[0152] Table 3 shows the comparison of AUC values of the LightGBM algorithm model before and after Bayesian optimization. The results show that after Bayesian optimization, the AUC value of the LightGBM algorithm model increased from 0.8973 to 0.9223, an increase of 0.025, proving that the Bayesian optimization algorithm is effective.
[0153] Table 3 Comparison of AUC values of the models before and after the Bayesian algorithm
[0154] Before Bayesian Optimization After Bayesian optimization AUC 0.8582 <![CDATA[ 0.8665 ]]>
[0155] Table 4 shows the parameter settings of the Bayesian optimized Bayesian-LightGBM model:
[0156] Table 4 Model parameter settings after Bayesian algorithm
[0157] Parameter name Numeric colsample_bytree 0.77 learning_rate 0.15 max_depth 7 min_child_samples 7 min_gain_to_split 0.86 n_estimators 228 num_leaves 593 reg_alpha 1.12 reg_lambda 5.79 subsample 0.61
[0158] Table 5 compares the running time required by the Baseline-LightGBM algorithm on a dataset without feature selection and the running time required by the Bayes-LightGBM algorithm on a dataset after feature selection by the RFECV algorithm:
[0159] Table 5 Comparison of running time required before and after the method improvement
[0160] Original method Embodiments of the present invention Time (seconds) 9.35 6.56
[0161] According to the above experiments, the software defect prediction method proposed in the embodiment of the present invention can achieve an AUC value of 0.8665, which is 0.015 higher than the AUC value of 0.8515 achieved by the original software defect prediction method, and the running time of the algorithm is reduced from 9.35 seconds of the original method to 6.56 seconds, which proves that the method proposed in the embodiment of the present invention is better.
[0162] The experiments of the embodiments of the present invention were conducted in the following environment: the operating system was Mac OS, the chip was AppleM1 Pro chip, the memory was 16GB, the experimental software was PyCharm, and the programming language was Python.
[0163] During the experiment, the dataset was divided into 80% training set and 20% test set, and a ten-fold cross-validation method was used to ensure the reliability of the conclusion.
[0164] The dataset of the embodiment of the present invention is an open source dataset in the document [3]. The dataset samples 21 JAVA projects, all of which are selected from the Apache Software Foundation. The specific projects are shown in Table 6:
[0165] Table 6 Open source dataset projects
[0166]
[0167]
[0168] Finally, we get a dataset containing 39,518 samples, 200 feature metrics, and a label indicating whether a software defect is introduced.
[0169] The embodiment of the present invention first standardizes the original data set. The standardization step is divided into two stages. The first stage is StandardScaler standardization. This standardization method makes most of the data normally distributed near 0, but there may be outliers that are not eliminated, which affects the model effect; therefore, the second stage uses RobustScaler standardization, which can eliminate outliers according to IQR.
[0170] Then, the standardized data set is subjected to feature selection processing using a combined feature selection method based on random forest and RFECV. The embodiment of the present invention uses the random forest algorithm as the evaluator of the RFECV algorithm to evaluate the cross-validation score of each feature subset combination. When the number of features in the feature subset is 43 features, the cross-validation score of the feature subset is the highest, and its cross-validation score is 0.9718. Therefore, the subsequent feature set of the embodiment of the present invention selects these 43 features as the feature set for software defect prediction.
[0171] In terms of machine learning models, the Baseline-LightGBM algorithm is used to build a software defect prediction model for the data set before and after using the RFECV feature selection algorithm, and AUC is used as the model evaluation indicator to evaluate the model performance.
[0172] Table 2 shows the comparison of the AUC values of the model before and after using the RFECV algorithm. The results show that after using the RFECV algorithm, the AUC value of the prediction model increased from 0.8715 to 0.8772, and the AUC value increased by 0.0057, proving that this method is effective.
[0173] Table 2 Comparison of AUC values of the models before and after RFECV algorithm
[0174] Before RFECV algorithm After RFECV algorithm AUC 0.8515 <![CDATA[ 0.8582 ]]>
[0175] The embodiment of the present invention uses a data set after feature selection based on the RFECV algorithm and performs Bayesian optimization. Compare the Baseline-LightGBM algorithm before Bayesian optimization with the Bayes-LightGBM algorithm after Bayesian optimization to see whether the model performance is improved.
[0176] Table 3 shows the comparison of AUC values of the LightGBM algorithm model before and after Bayesian optimization. The results show that after Bayesian optimization, the AUC value of the LightGBM algorithm model increased from 0.8973 to 0.9223, an increase of 0.025, proving that the Bayesian optimization algorithm is effective.
[0177] Table 3 Comparison of AUC values of the models before and after the Bayesian algorithm
[0178] Before Bayesian Optimization After Bayesian optimization AUC 0.8582 <![CDATA[ 0.8665 ]]>
[0179] Based on the data set after RFE feature selection, the embodiment of the present invention selects several traditional machine learning models to compare with the method proposed in the embodiment of the present invention. The embodiment of the present invention selects logistic regression (LR), decision tree (DT), and K nearest neighbor algorithm (KNN). The three traditional machine learning models are selected for comparison because they are commonly used in classification models.
[0180] Table 7 shows the Bayes-LightGBM software defect prediction method based on RFECV feature selection proposed in an embodiment of the present invention, compared with three other traditional machine learning models:
[0181] Table 7 Comparison of AUC values among different methods
[0182] Bayes-LightGBM LR DT KNN AUC <![CDATA[ 0.8665 ]]> 0.6685 0.4774 0.6794
[0183] According to the results in Table 7, it can be shown that the Bayes-LightGBM software defect prediction method based on RFECV feature selection proposed in the embodiment of the present invention is better than the traditional machine learning model and obtains the highest AUC value of 0.8665, while the decision tree has the lowest AUC value of only 0.4774.
[0184] The above experiments have proved that the Bayes-LightGBM software defect prediction method based on RFECV feature selection proposed in the embodiment of the present invention can effectively predict the occurrence of software defects compared with other machine learning algorithms, and has a good effect on avoiding the occurrence of software defects in advance.
[0185] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. A Bayes-LightGBM software defect prediction method based on RFECV feature selection, characterized in that: The following steps are involved: Standardize the original data set; Then, the combined feature selection method of random forest and RFECV is used on the standardized data set to select the feature combination with the highest cross-validation score; the following steps are included: All initial features are used as the currently available feature combination, and then the current feature combination is used to calculate the feature importance score of each feature; Delete one or more features with the lowest feature importance score, and then update the current feature combination; According to the current feature combination determined in the RFE stage, cross-validate the selected feature combination; Then use the random forest evaluator to model and score the selected feature set, and then return to the RFE stage and repeat the above steps until the cross-validation scoring of all feature combinations is completed; Select the feature combination with the highest cross-validation score as the optimal feature combination; The RFE phase includes the following steps: Set all features in the data set as the initial feature combination; Use the current feature set for modeling and calculate the feature importance of each feature in the current feature set; According to the calculated feature importance and sorting, delete the least important feature or features, and then update the feature combination; Model the updated feature combinations again and repeat the above steps until all feature combinations have been cross-validated according to the random forest evaluator. The CV phase includes the following steps: According to the feature importance determined in the RFE stage, the updated feature set is cross-validated; The updated feature set is scored using the evaluator to determine the number and features with the highest average score, and finally the feature set selection is completed; specifically, the feature combination updated after each feature deletion is a set of feature combinations, and n sets of feature combinations are obtained repeatedly until no features can be deleted; then, for each feature combination, the random forest evaluator is used for cross-validation scoring, and the feature combination with the cross-validation score is selected based on the cross-validation score of each feature combination, which is the feature combination with the best performance; Then use the Bayes-LightGBM algorithm to build a prediction model to predict whether software defects will occur based on the features in the data set.
2. The Bayes-LightGBM software defect prediction method based on RFECV feature selection according to claim 1, characterized in that: The standardization operations of the original data set specifically include: Performing StandardScaler standardization on the raw data to normalize the raw data; The normalized data were subjected to RobustScaler standardization to remove outliers outside the quartiles.
3. The Bayes-LightGBM software defect prediction method based on RFECV feature selection according to claim 1, characterized in that: The combined feature selection method of random forest and RFECV is used on the standardized data set to select the feature combination with the highest cross-validation score. The random forest algorithm is used as a feature evaluator to evaluate the scores of feature subsets, and the RFECV algorithm is used to select the feature subset with the highest score.
4. The Bayes-LightGBM software defect prediction method based on RFECV feature selection according to claim 1, characterized in that: The RFECV includes an RFE stage and a CV stage, wherein the RFE stage is used for recursive feature elimination and the CV stage is used for cross-validation.
5. The Bayes-LightGBM software defect prediction method based on RFECV feature selection according to claim 1, characterized in that: Then use the Bayes-LightGBM algorithm to build a prediction model to predict whether a software defect will occur based on the features in the data set. The specific steps include: After selecting appropriate features from the initial data set using RFECV and random forest algorithms, a new data set after feature selection is constructed; The new data set is divided into a training set and a test set in a ratio of 8:2; Use the Bayesian optimization algorithm to optimize the hyperparameters of LightGBM and obtain the Bayes-LightGBM prediction model; Use K-fold cross validation to train the Bayes-LightGBM prediction model; Based on the comparison between the test set and the prediction results, the AUC value of the prediction model is obtained. The higher the AUC value obtained, the better the classification performance of the software defect prediction model.
