Software defect prediction feature selection method based on improved whale optimization algorithm
Through the improved white whale optimization algorithm, combined with Cubic chaos mapping, triangle walking strategy and Levy flight mechanism, the problem of optimization algorithm falling into local optimality in high-dimensional software defect prediction is solved, and more efficient feature selection and software defect prediction accuracy is achieved.
Patent Information
- Application Number
- CN202411627436.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-02-28
AI Technical Summary
When processing high-dimensional software defect prediction data, existing optimization algorithms are prone to falling into local optimization, slow convergence speed, and redundant and irrelevant problems when processing high-dimensional software defect prediction data, which affects the accuracy and efficiency of software defect prediction.
The improved white whale optimization algorithm is used to initialize the population through Cubic chaos mapping, combine the triangle walk strategy and the Levy flight mechanism to search in the exploration and development stage, and use the strategy of combining Cauchy mutation and reverse learning in the whale fall stage to enhance the algorithm's global search ability and local search accuracy to avoid falling into local optimization.
It improves the accuracy and efficiency of feature selection, reduces the selection of redundant features, avoids the "dimensional disaster" problem, thereby improving the model generalization ability and prediction accuracy of software defect prediction.
Smart Images

Figure CN119537227A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of software defect prediction and relates to a software defect prediction feature selection method based on an improved Beluga optimization algorithm. Background Art
[0002] With the increasing complexity and scale of software projects, software defect prediction has become one of the key technologies to ensure software quality. Traditional software defect prediction methods rely on statistical analysis, machine learning and other technologies, among which optimization algorithms are often used for feature selection and model optimization.
[0003] However, existing optimization algorithms such as genetic algorithms, particle swarm optimization algorithms, and Beluga optimization algorithms are prone to falling into local optimality, slow convergence, and insufficient global search capabilities when processing high-dimensional data. At the same time, when using these algorithms for feature selection, the selected features are prone to redundancy and irrelevant features, which directly affects the accuracy and efficiency of software defect prediction. Summary of the invention
[0004] In order to solve the problem that redundant and irrelevant features are easily selected during feature selection in the process of software source code defect prediction, the technical solution adopted by the present invention is: a software defect prediction feature selection method based on an improved Beluga optimization algorithm, comprising the following steps:
[0005] Obtain the traditional features of a single file in the folder where the source code of the software to be predicted is located to form a data set;
[0006] Preprocess the data set for the prediction software;
[0007] The preprocessed prediction software data set is divided into a test set and a training set according to the proportion;
[0008] Based on the training set data, the improved White Whale optimization algorithm is used for training to screen out the traditional features corresponding to the software source code files to be predicted;
[0009] The selected traditional features are used to predict the number of defects in the software source code based on the test set data.
[0010] Further: the process of preprocessing the data set of the prediction software includes:
[0011] Use Min-max to normalize the data set. The specific process is: scale the features to a specified range (usually 0 to 1), calculate the maximum and minimum values of each feature, and then perform a linear transformation on each data point so that the data is evenly distributed between the minimum and maximum values;
[0012] Use SMOTE to balance the dataset. The specific processing is as follows: identify samples belonging to the minority class from the dataset. For each minority class sample, calculate the distance between the minority class sample and other samples in the same class. Synthetic sample generation: for each minority class sample and its k nearest neighbors, generate new synthetic samples between these samples. Repeat the above process until the desired level of class balance is achieved.
[0013] Further: the process of training based on the training set data and using the improved White Whale optimization algorithm to screen out the features corresponding to the software source code file to be predicted includes:
[0014] Initialization phase: Cubic chaotic mapping is introduced to generate a more evenly distributed initial population, calculate the fitness value of each beluga whale, and update the location information of the population;
[0015] Calculate the probability function W f and balance factor B f ;
[0016] The balance factor B f Compared with the balance factor threshold, when the balance factor B f >When the balance factor threshold is reached, the exploration phase begins, and the improved triangle walk method is used to move in the search space to obtain the position of the white whale after it has swum away;
[0017] When the balance factor B f When the balance factor threshold is less than or equal to the balance factor threshold, the development phase is entered, and the mathematical model of the Levy flight mechanism function is used to generate a random step with a heavy-tailed distribution, and the direction and position are adjusted according to the position of the currently selected optimal feature;
[0018] The balance factor B f <Probability function W f When , it enters the whale fall phase and updates the step size factor C 2 , calculate the step size X step , select the drop probability to simulate a small change, ensure that the population size remains unchanged, calculate the probability P and the probability value P that obeys the exponential distribution s , the white whale position is updated by combining Cauchy mutation with reverse learning, that is, when P <P s When the target position is updated, the Cauchy mutation strategy is used, otherwise the reverse learning strategy is used to dynamically and randomly update the target position to obtain the updated mathematical model of the whale fall stage.
[0019] For the current whale fall individual, the sparrow warning mechanism is used to help other individuals avoid falling into the same local optimum or further optimize their own solutions. The sparrow warning mechanism introduces parameters β and R for the current position, where β is the proportional factor that controls the search range, and R is a random vector that allows the warned individual to perform random searches in a direction different from that of the whale fall individual.
[0020] Determine whether the number of iterations has been reached. If so, end the loop. Otherwise, return to the function W that recalculates the probability. f and balance factor B f .
[0021] Further: The Cubic chaos mapping formula is expressed as:
[0022]
[0023] Where: x n represents the position of the nth population, ρ represents the mixing factor, when x 0 When =0.3 and ρ=2.595, the Cubic mapping has better chaotic ergodicity.
[0024] Further: the process of moving in the search space using the triangular walk method to obtain the position of the white whale after swimming is as follows:
[0025] First, based on the distance dis between the beluga whale and its peers, it is expressed as:
[0026]
[0027] in is the target solution of the Tth generation, is the position of the i-th beluga whale in the T-th generation.
[0028] Get the step range of the beluga whale's swimming, expressed as:
[0029] range=α·dis 1 (7)
[0030] Among them: α is a random number that obeys the normal distribution;
[0031] Define the direction β of the white whale's movement, expressed as:
[0032] β=2πα (8)
[0033] Among them: α is a random number that follows a normal distribution,
[0034] Obtain the final distance Dist between the wandering position and the same type, expressed as:
[0035] Dist=dis 2 +range2 -2·dis·range·cos(β) (9)
[0036] Update the position of the beluga whale after it swims away, denoted as .
[0037]
[0038] Further: The mathematical model of the Levy flight mechanism function is L F :
[0039]
[0040] Among them, u and v are random numbers that obey the normal distribution, β defaults to 1.5, and the mathematical model of parameter σ is:
[0041]
[0042] Further: the mathematical model of the whale fall stage is:
[0043]
[0044] Where: ω is the adjustment factor, when ω is 0.05, the optimization result of the function is optimal; is the Tth generation target solution The reverse solution of ; is the T+1th generation target solution; u b and l b are the upper and lower bounds; r is a random number that follows the (0,1) standard uniform distribution; Cauchy(0,1) is the standard Cauchy distribution function; b 3 is the pseudo information exchange coefficient, expressed as:
[0045]
[0046] Among them: α is the random initial value, β is the decay rate, T is the current iteration number, T max is the maximum number of iterations.
[0047] A software defect prediction feature selection device based on an improved Beluga optimization algorithm, comprising:
[0048] Acquisition module: used to obtain the traditional features of a single file in the folder where the source code of the software to be predicted is located to form a data set;
[0049] Preprocessing module: used to preprocess the data set to be used for prediction software;
[0050] Partition module: used to divide the preprocessed prediction software data set into a test set and a training set according to the proportion;
[0051] Training phase: Based on the training set data, the improved White Whale optimization algorithm is used for training to screen out the traditional features corresponding to the software source code file to be predicted;
[0052] Prediction stage: Use the selected traditional features to predict the number of defects in the software source code based on the test set data.
[0053] A computer device comprises: a processor and a memory, wherein the memory stores a program module, and wherein the program module runs on the processor to implement one of the methods described above.
[0054] The software defect prediction feature selection method based on the improved Beluga optimization algorithm provided by the present invention has the following advantages:
[0055] The exploration phase of the algorithm proposed in the present invention enhances the global search capability of the algorithm by simulating the swimming behavior of beluga whales, which helps to discover a wider range of feature combinations in feature selection; the development phase of the algorithm proposed in the present invention improves the local search accuracy of the algorithm by simulating the predation behavior of beluga whales, which helps to accurately locate the optimal feature subset in feature selection; at the same time, the present invention enhances the ability of the algorithm to jump out of the local optimum, which is particularly important in feature selection because it helps the algorithm avoid falling into a suboptimal feature subset; the design of the algorithm of the present invention is relatively simple, easy to implement and apply to feature selection for software defect prediction; most importantly, the present invention can effectively reduce data dimensions, reduce computational complexity, and avoid the "dimensionality disaster" problem caused by redundant features, thereby improving the generalization ability and prediction accuracy of the model.
[0056] Feature selection is performed based on the improved Beluga optimization algorithm to deal with the problem that the selected features are redundant and irrelevant during feature selection, and it is easy to fall into the local optimal solution, thereby improving the accuracy and efficiency of software defect prediction. Considering the imbalanced distribution of the data set and the inconsistent data range, SMOTE and Min-max normalization are used to process the data set; since the original Beluga algorithm does not make the population distribution uniform when initializing the population, this application uses Cubic chaotic mapping to initialize the population to make the population distribution range wider and more uniform; after the population position is determined, the update change amplitude will be small at each update, so this paper proposes to use a triangular walk strategy to expand the search range, thereby increasing the population position update amplitude; in the later stage of BWO iteration, the individuals of the population will converge towards the current optimal position, but the optimal position cannot be guaranteed to be the optimal point. Under the leadership of the local optimal individual, the population appears to fall into the local optimal position. To address this problem, this paper adopts a strategy combining Cauchy mutation and reverse learning to adaptively adjust the search space, help the algorithm jump out of the local optimal, and expand the search range of new individuals after the death of the whale. At the same time, the sparrow warning mechanism is used to help other individuals and whale fall individuals avoid falling into the same local optimum or further optimize their own solutions. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0058] Figure 1 A flowchart of the application method;
[0059] Figure 2 This is the model diagram corresponding to the improved Beluga optimization algorithm;
[0060] Figure 3 Training flow chart for improving the White Whale optimization algorithm;
[0061] Figure 4The fitness value diagram of four classifiers in different data sets, including (a) the fitness value of ant-1.7 in the four classifiers, (b) the fitness value of camel-1.4 in the four classifiers, (c) the fitness value of jedit-3.2 in the four classifiers, (d) the fitness value of jedit-4.3 in the four classifiers, (e) the fitness value of log4j-1.0 in the four classifiers, (f) poi-2.0, (g) the fitness value of synapese-1.0 in the four classifiers, (h) the fitness value of xalan-2.4 in the four classifiers, (i) the fitness value of MW1 in the four classifiers;
[0062] Figure 5 This is a comparison chart of the results of the present invention and the comparison model F1;
[0063] Figure 6 This is a comparison chart of the MCC results of the present invention and the comparative model;
[0064] Figure 7 This is a comparison chart of the Recall results of the present invention and the comparison model. DETAILED DESCRIPTION
[0065] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0066] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present invention and its application or use. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] Figure 1 A flowchart of the application method;
[0068] A software defect prediction feature selection method based on an improved Beluga optimization algorithm comprises the following steps:
[0069] S1: Obtain the traditional features of a single file in the folder where the source code of the software to be predicted is located to form a data set;
[0070] S2: preprocessing the data set for the prediction software;
[0071] S3: Divide the preprocessed prediction software data set into a test set and a training set according to the proportion;
[0072] S4: Based on the training set data, the improved White Whale optimization algorithm is used for training to screen out the traditional features corresponding to the software source code file to be predicted;
[0073] S5: Use the selected traditional features to predict the number of defects in the software source code based on the test set data.
[0074] The steps S1 / S2 / S3 / S4 / S5 are performed sequentially;
[0075] The traditional features used are shown in Table 1.
[0076] Table 1 Traditional features used in this experiment
[0077]
[0078]
[0079] The process of preprocessing the data set of the prediction software includes:
[0080] Use Min-max to normalize the data set. The specific process is: scale the features to a specified range (usually 0 to 1), calculate the maximum and minimum values of each feature, and then perform a linear transformation on each data point so that the data is evenly distributed between the minimum and maximum values;
[0081] Use SMOTE to balance the dataset. The specific processing is as follows: identify samples belonging to the minority class from the dataset. For each minority class sample, calculate the distance between the minority class sample and other samples in the same class. Synthetic sample generation: for each minority class sample and its k nearest neighbors, generate new synthetic samples between these samples. Repeat the above process until the desired level of class balance is achieved.
[0082] Figure 2 Improved Beluga optimization algorithm corresponding model diagram;
[0083] The improved beluga whale optimization algorithm model includes constructing swimming behavior as a search phase, constructing predation behavior as a development phase, and constructing death behavior as a whale fall phase;
[0084] Use Cubic to initialize the beluga whale population; Chaotic mapping has good randomness, regularity and ergodicity, which can make the beluga whale population evenly distributed, thereby improving the diversity of the population;
[0085] Entering the exploration phase, the whale explores the solution space to find the potential optimal solution. The optimal solution is the desired feature subset (that is, which features you want to select). The selected features are predicted on the test set to predict software defects. The key to this stage is to have a large search range and random directions. The whale moves in the search space with a triangular walking strategy to ensure that no possible areas are missed. This method is similar to whales swimming randomly in the ocean to search for food sources. The position update of each solution is unpredictable, but the goal is to explore as many areas as possible to increase the chance of finding a high-quality solution.
[0086] Entering the development phase, when the algorithm detects a promising solution, other solutions (whales) begin to focus on this potential optimal solution and perform a more purposeful search. This is similar to a whale discovering a school of fish and starting to swim around them, preparing to prey; the position update of the solution becomes more precise and focused at this stage, and they will adjust their direction and position according to the position of the current best solution (the currently selected optimal feature). The Levy flight mechanism is used to generate random steps with a heavy-tailed distribution, allowing the algorithm to make long-distance jumps in the search space, thereby effectively exploring the global solution space and avoiding the algorithm from converging to the local optimal solution too early.
[0087] When entering the whale fall phase, the drop probability is selected to simulate a small change to ensure that the population size remains unchanged. The white whale position and whale fall step length are updated through a strategy combining the Cauchy mutation operator and reverse learning, providing a mechanism for the algorithm to jump out of the local optimum. The sparrow alert mechanism is incorporated to help other individuals avoid falling into the same local optimum or further optimize their own solutions.
[0088] One's own solution refers to the solution represented by each individual in the algorithm (the feature subset selected by the current iteration). In the optimization algorithm, each individual (or candidate solution) is a feature subset in the problem space, representing a possible solution.
[0089] The purpose of the whale fall stage is to remove inappropriate solutions and incorporate new solutions.
[0090] Figure 3 Training flow chart for improving the White Whale optimization algorithm;
[0091] The specific training process of the improved Beluga optimization algorithm model is as follows:
[0092] S41: Set the initial hyperparameters and initialize the population through Cubic chaos mapping. The Cubic chaos mapping formula is expressed as:
[0093]
[0094] Where: x nrepresents the position of the nth population, ρ represents the mixing factor, when x 0 When =0.3,ρ=2.595,Cubic mapping has good chaotic ergodicity. The initialized population is:
[0095]
[0096] S42: Calculate the fitness value of each beluga whale and update the location information of the population to obtain the fitness value of the corresponding population:
[0097]
[0098] S43: Calculate the function W of the probability f and balance factor B f , W f and B f The calculation formula is:
[0099] W f =0.1-0.05T / T max (4)
[0100] B f =B 0 (1-T / 2T max ) (5)
[0101] Among them: B 0 is a random value from (0,1), T is the current iteration number, T max is the maximum number of iterations;
[0102] S44: Balance factor B f Compared with the balance factor threshold, the balance factor threshold is 0.5; when B f >0.5, it enters the exploration phase, in which the whale moves in the search space with a triangular walk strategy to ensure that no possible areas are missed. This method is similar to whales swimming randomly in the ocean to search for food sources. The improvements made to the triangular walk strategy are:
[0103] The distance dis between the beluga whale and its peers is obtained, expressed as:
[0104]
[0105] in: is the target solution of the Tth generation, is the position of the i-th beluga whale in the T-th generation.
[0106] Get the step range of the beluga whale's swimming, expressed as:
[0107] range=α·dis 1(7)
[0108] Among them: α is a random number that obeys the normal distribution;
[0109] Define the direction β of the white whale's movement, expressed as:
[0110] β=2πα (8)
[0111] Where: α is a random number that follows a normal distribution.
[0112] Combining formulas (6)-(8), the final distance Dist between the wandering position and the same type is obtained, which is expressed as:
[0113] Dist=dis 2 +range 2 -2·dis·range·cos(β) (9)
[0114] Update the position of the white whale after it swims away, expressed as:
[0115]
[0116] When B f When ≤0.5, it enters the development stage and updates the position according to the Levy flight method. The mathematical model of the Levy flight function is L F :
[0117]
[0118] Among them, u and v are random numbers that obey the normal distribution, β defaults to 1.5, and the mathematical model of parameter σ is:
[0119]
[0120] S45: recalculate the new fitness value using formula (3), compare the fitness values before and after the update, and obtain a better position;
[0121] S46: Compare W f and B f When B f <W f When , it enters the whale fall phase and updates the step size factor C 2 , calculate the step size X step , select the drop probability to simulate a small change, ensure that the population size remains unchanged, calculate the probability P and the probability value P that obeys the exponential distribution s , the white whale position is updated by combining Cauchy mutation with reverse learning, that is, when P <P s When the target position is updated, the Cauchy mutation strategy is used, and when the target position is updated, the reverse learning strategy is used. After the update, the mathematical model of the whale fall stage is:
[0122]
[0123] Where: ω is the adjustment factor, when ω is 0.05, the optimization result of the function is optimal; is the Tth generation target solution The reverse solution of ; is the T+1th generation target solution; u b and l b are the upper and lower bounds; r is a random number that follows the (0,1) standard uniform distribution; Cauchy(0,1) is the standard Cauchy distribution function; b 3 is the pseudo information exchange coefficient, expressed as:
[0124]
[0125] Among them: α is the random initial value, β is the decay rate, T is the current iteration number, T max is the maximum number of iterations.
[0126] S47: For the current whale fall individual, the sparrow warning mechanism is used to help other individuals avoid falling into the same local optimum or further optimize their own solutions. The sparrow warning mechanism is to introduce parameters β and R for the current position, where β is the proportional factor that controls the search range, and R is a random vector that allows the warned individual to perform random searches in a direction different from that of the whale fall individual.
[0127] S48: Determine whether the set number of iterations reaches the condition for ending the iteration loop. If so, end the penalty. Otherwise, jump to S43.
[0128] Example 1
[0129] A software defect prediction feature selection method based on an improved Beluga optimization algorithm comprises the following steps:
[0130] S1: Obtain the traditional features of a single file in the folder where the source code of the software to be predicted is located to form a data set; as shown in Table 2;
[0131] S2: preprocessing the data set for the prediction software;
[0132] S3: Divide the preprocessed prediction software data set into a test set and a training set according to the proportion;
[0133] S4: Based on the training set data, the improved White Whale optimization algorithm is used for training to screen out the traditional features corresponding to the software source code file to be predicted;
[0134] S5: Use the selected traditional features to predict the number of defects in the software source code based on the test set data.
[0135] The improved beluga optimization algorithm model constructs swimming behavior as the search phase, predation behavior as the development phase, and death behavior as the whale fall phase. Figure 2 Exploration, Exploitation and Whale fall in.
[0136] As shown in Table 2 and Table 3, the original data set of poi-2.0 software and the data set processed by Min-max
[0137] Table 2 shows the data distribution of the original data set
[0138] wmc dit noc cbo … amc max_cc avg_cc Bugs 0 11 4 2 14 … 34.54546 3 1.2727 0 1 14 1 1 8 … 16.85714 6 1.6429 2 2 3 2 0 1 … 17.33333 1 0.6667 0 3 12 3 0 12 … 24.08333 3 1.4167 0 4 6 3 0 4 … 21 1 0.8333 0 … … … … … … … … … … 120 65 3 0 21 … 21.83077 10 1.5231 0 121 14 4 0 99 … 9.785714 2 0.6429 0 122 14 1 0 24 … 56.57143 24 2.7857 2 123 4 2 0 3 … 13.5 5 1.75 0 124 27 1 0 3 … 18.22222 11 1.4444 0
[0139] Table 3 shows the data distribution of the data set after Min-max processing
[0140] wmc dit noc cbo … amc max_cc avg_cc Bugs 0 0.15493 0.6 0.058824 0.135922 … 0.342034 0.085714 0.216829 0 1 0.197183 0 0.029412 0.07767 … 0.166902 0.171429 0.2799 1 2 0.042254 0.2 0 0.009709 … 0.171617 0.028571 0.113585 0 3 0.169014 0.4 0 0.116505 … 0.238449 0.085714 0.241362 0 4 … … … … … … … … … … 0.084507 0.4 0 0.038835 … 0.207921 0.028571 0.141969 0 120 0.915493 0.4 0 0.203883 … 0.216146 0.285714 0.25949 0 121 0.197183 0.6 0 0.961165 … 0.096888 0.057143 0.10953 0 122 0.197183 0 0 0.23301 … 0.560113 0.685714 0.474598 1 123 0.056338 0.2 0 0.029126 … 0.133663 0.142857 0.298146 0 124 0.380282 0 0 0.029126 … 0.180418 0.314286 0.246082 0
[0141] It can be seen from Table 2 that the data distribution in the original data set is quite different, which will affect the results of feature selection.
[0142] Table 3 is the processed data set. It can be seen that each data value is in (0,1)
[0143] To verify the effectiveness of the present invention, the present invention firstly calculates the fitness values of four classifiers (DT, KNN, RF, SVM) on multiple data sets, such as Figure 4 As shown, (a) the fitness values of ant-1.7 corresponding to the four classifiers, (b) the fitness values of camel-1.4 corresponding to the four classifiers, (c) the fitness values of jedit-3.2 corresponding to the four classifiers, (d) the fitness values of jedit-4.3 corresponding to the four classifiers, (e) the fitness values of log4j-1.0 corresponding to the four classifiers, (f) poi-2.0, (g) the fitness values of synapese-1.0 corresponding to the four classifiers, (h) the fitness values of xalan-2.4 corresponding to the four classifiers, (i) the fitness values of MW1 corresponding to the four classifiers;
[0144] In order to further verify the effectiveness of the present invention, the present invention is compared with R-WABEM, RotBag and SMOTE-ERAR on different data sets. The experimental results are shown in Tables 4-6. Figure 5-7 This is the line chart corresponding to Table 4-6.
[0145] Table 4 Comparison of F1 results between CTMBWO and comparison models using KNN
[0146]
[0147]
[0148] Table 5 Comparison of MCC results between CTMBWO and comparison models using KNN
[0149]
[0150] Table 6 Comparison of Recall results of CTMBWO and comparison models using KNN
[0151]
[0152]
[0153] Through Table 4-6 and Figure 5-7 It can be seen that the results of the proposed method in the three indicators of F1, MCC, and Recall are significantly higher than those of the three comparison models, which shows that the present invention can effectively balance the precision and recall. Compared with other algorithms, the present invention is better at capturing positive samples and can reduce misclassified negative samples. Therefore, the classification performance of the present invention on the test data set is more stable and reliable, and can provide more accurate predictions for research problems.
[0154] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A software defect prediction feature selection method based on an improved Beluga optimization algorithm, characterized in that: The following steps are involved: Obtain the traditional features of a single file in the folder where the source code of the software to be predicted is located to form a data set; Preprocess the data set for the prediction software; The preprocessed prediction software data set is divided into a test set and a training set according to the proportion; Based on the training set data, the improved White Whale optimization algorithm is used for training to screen out the traditional features corresponding to the software source code files to be predicted; The selected traditional features are used to predict the number of defects in the software source code based on the test set data.
2. The method for selecting software defect prediction features based on the improved Beluga optimization algorithm according to claim 1, characterized in that: The process of preprocessing the data set of the prediction software includes: Use Min-max to normalize the data set. The specific process is: scale the features to the specified range, calculate the maximum and minimum values of each feature, and then perform a linear transformation on each data point so that the data is evenly distributed between the minimum and maximum values; Use SMOTE to balance the dataset. The specific processing is as follows: identify samples belonging to the minority class from the dataset. For each minority class sample, calculate the distance between the minority class sample and other samples in the same class. Synthetic sample generation: for each minority class sample and its k nearest neighbors, generate new synthetic samples between these samples. Repeat the above process until the desired level of class balance is achieved.
3. The method for selecting software defect prediction features based on the improved Beluga optimization algorithm according to claim 1, characterized in that: The process of training based on the training set data and using the improved White Whale optimization algorithm to screen out the features corresponding to the software source code file to be predicted includes: Initialization phase: Cubic chaotic mapping is introduced to generate a more evenly distributed initial population, calculate the fitness value of each beluga whale, and update the location information of the population; Calculate the probability function W f and balance factor B f ; The balance factor B f Compared with the balance factor threshold, when the balance factor B f >When the balance factor threshold is reached, the exploration phase begins, and the improved triangle walk method is used to move in the search space to obtain the position of the white whale after it has swum away; When the balance factor B f When the balance factor threshold is less than or equal to the balance factor threshold, the development phase is entered, and the mathematical model of the Levy flight mechanism function is used to generate a random step with a heavy-tailed distribution, and the direction and position are adjusted according to the position of the currently selected optimal feature; The balance factor B f <Probability function W f When , it enters the whale fall phase, updates the step size factor C2, and calculates the step size X step , select the drop probability to simulate a small change, ensure that the population size remains unchanged, calculate the probability P and the probability value P that obeys the exponential distribution s , the white whale position is updated by combining Cauchy mutation with reverse learning, that is, when P <P s When the target position is updated, the Cauchy mutation strategy is used, otherwise the reverse learning strategy is used to dynamically and randomly update the target position to obtain the updated mathematical model of the whale fall stage. For the current whale fall individual, the sparrow warning mechanism is used to help other individuals avoid falling into the same local optimum or further optimize their own solutions. The sparrow warning mechanism introduces parameters β and R for the current position, where β is the proportional factor that controls the search range, and R is a random vector that allows the warned individual to perform random searches in a direction different from that of the whale fall individual. Determine whether the number of iterations has been reached. If so, end the loop. Otherwise, return to the function W that recalculates the probability. f and balance factor B f .
4. The method for selecting software defect prediction features based on the improved Beluga optimization algorithm according to claim 1, characterized in that: The Cubic chaotic mapping formula is expressed as: Where: x n represents the position of the nth population, ρ represents the confusion factor, when x0=0.3, ρ=2.595, the Cubic mapping has good chaotic ergodicity.
5. The method for selecting software defect prediction features based on the improved Beluga optimization algorithm according to claim 1, characterized in that: The process of moving in the search space using the triangular walk method to obtain the position of the white whale after swimming is as follows: First, based on the distance dis between the beluga whale and its peers, it is expressed as: in is the target solution of the Tth generation, is the position of the i-th beluga whale in the T-th generation. Get the step range of the beluga whale's movement, expressed as: range=α·dis1 (7) Among them: α is a random number that obeys the normal distribution; Define the direction β of the white whale's movement, expressed as: β=2πα (8) Among them: α is a random number that follows a normal distribution, Obtain the final distance Dist between the wandering position and the same type, expressed as: Dist=dis 2 +range 2 -2 disrange cos(β) (9) Update the position of the beluga whale after it swims away, denoted as .
6. The method for selecting software defect prediction features based on the improved Beluga optimization algorithm according to claim 1, characterized in that: The mathematical model of the Levy flight mechanism function is L F : Among them, u and v are random numbers that obey the normal distribution, β defaults to 1.5, and the mathematical model of parameter σ is:
7. The method for selecting software defect prediction features based on the improved Beluga optimization algorithm according to claim 1, characterized in that: The mathematical model of the whale fall stage is: Where: ω is the adjustment factor, when ω is 0.05, the optimization result of the function is optimal; is the Tth generation target solution The reverse solution of ; is the T+1th generation target solution; u b and l b are the upper and lower bounds; r is a random number that obeys the (0,1) standard uniform distribution; Cauchy(0,1) is the standard Cauchy distribution function; b3 is the pseudo information exchange coefficient, expressed as: Among them: α is the random initial value, β is the decay rate, T is the current iteration number, T max is the maximum number of iterations.
8. A software defect prediction feature selection method based on an improved Beluga optimization algorithm, comprising: Acquisition module: used to obtain the traditional features of a single file in the folder where the source code of the software to be predicted is located to form a data set; Preprocessing module: used to preprocess the data set to be used for prediction software; Partition module: used to divide the preprocessed prediction software data set into a test set and a training set according to the proportion; Training phase: Based on the training set data, the improved White Whale optimization algorithm is used for training to screen out the traditional features corresponding to the software source code file to be predicted; Prediction stage: Use the selected traditional features to predict the number of defects in the software source code based on the test set data.
9. A computer device comprising: A processor and a memory, wherein the memory stores a program module, wherein the program module runs on the processor to implement the method according to any one of claims 1 to 7.
Citation Information
Cited By
Method for predicting water inrush risk of coal mining working face floor
CN120258523A