Cross-project software defect prediction method for sorting tasks, electronic equipment and medium
By extracting and screening project features, a high-performance defect prediction model is constructed, which solves the problem of poor prediction performance in cross-project software defect prediction and improves the accuracy and reliability of prediction.
Patent Information
- Application Number
- CN202410673760.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-28
- Publication Date
- 2024-08-27
AI Technical Summary
The existing technology has poor prediction performance and low accuracy in cross-project software defect prediction, especially the lack of relevant training data for new projects, resulting in insufficient cross-project prediction accuracy and reliability.
By extracting feature sets from the target project and multiple source projects, perform feature scoring and screening, obtain weight distribution, build a high-performance defect prediction model, combine traditional manual features for modeling, and predict the number and ranking of defects in software modules.
It improves the accuracy and reliability of cross-project software defect prediction and ensures the reliability and accuracy of prediction results.
Smart Images

Figure CN118550825A
Abstract
Description
Technical Field
[0001] The present application relates to the field of software engineering, and in particular to a cross-project software defect prediction method for sorting tasks, and electronic equipment and media. Background Art
[0002] Software defects, as a key factor affecting software quality, are often the potential root causes of system errors and failures. Therefore, predicting software defects is an important part of software testing and software maintenance. According to the purpose of prediction, software defect prediction mainly includes two categories: the first category is software defect prediction for classification tasks, which predicts the tendency of software modules to contain defects, that is, predicts whether the software module contains defects, which can be used to determine whether the software module can be delivered or to guide testers to focus resources and energy on defective software modules; the second category is software defect prediction for sorting tasks, which predicts the number of defects contained in software modules and gives the sorting of software modules according to the number of defects, so that software developers can guide the allocation of test resources according to the actual number of available test resources, so that software modules with poor quality (containing more defects) can receive priority attention. In recent years, with the widespread application of deep learning, the application of deep learning technology has gradually emerged in the field of defect prediction. Software prediction models for classification tasks can be used to predict the tendency of software modules to contain defects, but they cannot further distinguish between software modules with more defects and software modules with fewer defects. Therefore, testers will allocate equal test resources to all software modules with defects. Software defect prediction for sorting tasks can help allocate effective testing resources more effectively.
[0003] The current software defect prediction for sorting tasks is mainly for projects within or across versions. In the actual software development process, there is often a lack of relevant training data, or the prediction model does not consider the features sufficiently, resulting in poor prediction performance and low prediction accuracy of the constructed prediction model. Especially for new projects, due to the lack of directly relevant training data, they can only rely on data from other existing projects for modeling. However, there may be significant distribution differences between data from different projects. When the prediction model built based on data from other existing projects is used to predict defects in new projects, the accuracy and reliability of cross-project software defect prediction are low. Summary of the invention
[0004] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the embodiment of the present application provides a cross-project software defect prediction method for sorting tasks, an electronic device, and a medium, which can improve the accuracy and reliability of cross-project software defect prediction by utilizing a defect prediction model with good prediction performance and high prediction accuracy.
[0005] In a first aspect, an embodiment of the present application provides a cross-project software defect prediction method for a sorting task, comprising:
[0006] Extracting a first project feature set of a target project and a plurality of second project feature sets of a plurality of source projects;
[0007] Perform feature scoring and feature screening according to the first project feature set and each of the second project feature sets, and correspondingly obtain a plurality of first training data sets;
[0008] Perform weight allocation processing according to the plurality of the first training data sets and the first project feature sets to obtain project model weights corresponding to the respective source projects;
[0009] splicing each of the first training data sets with traditional manual features to obtain multiple second training data sets;
[0010] Performing modeling based on the second training data set and the project model weights to obtain a defect prediction model;
[0011] The source code of each module of the target project to be tested is input into the defect prediction model to obtain a defect prediction result; wherein the defect prediction result includes the number of defects of each module and the module ranking based on the number of defects.
[0012] According to some embodiments of the present application, extracting a first project feature set of a target project and a plurality of second project feature sets of a plurality of source projects includes:
[0013] Obtaining a first abstract syntax tree of the target project and a plurality of second abstract syntax trees of the plurality of source projects;
[0014] Traversing all nodes of the first abstract syntax tree to obtain a first node sequence, and traversing all nodes of each of the second abstract syntax trees to obtain a plurality of second node sequences accordingly;
[0015] Convert the first node sequence into a first numerical vector, and convert the second node sequence into a second numerical vector;
[0016] The first numerical vector and the second numerical vector after dimension regularization are respectively input into a feature extractor, and the first item feature set and a plurality of the second item feature sets are output.
[0017] According to some embodiments of the present application, the dimension regularization process includes:
[0018] Obtaining the vector length of the numerical vector to be input into the bidirectional long short-term memory neural network;
[0019] When the length of the vector is greater than a preset length threshold, padding the numerical vector to obtain a regularized numerical vector;
[0020] When the vector length is less than a preset length threshold, the numerical vector is truncated to obtain a regularized numerical vector; wherein the vector length of the regularized numerical vector is equal to the preset length threshold.
[0021] According to some embodiments of the present application, the feature scoring process and the feature screening process are performed according to the first project feature set and each of the second project feature sets, and a plurality of first training data sets are obtained accordingly, including:
[0022] Assigning a first category number to each sample in the first item feature set; assigning a second category number to each sample in the second item feature set;
[0023] Integrate the first item feature set with the first category number and the second item feature set with the second category number to obtain a first classification data set; the first classification data set includes a plurality of candidate features;
[0024] Performing a first scoring calculation process on each candidate feature in the first classification data set to obtain an initial first score for each candidate feature;
[0025] Determine the candidate feature with the highest first score as a first target feature, obtain a first target feature set including the first target feature and a remaining candidate feature set excluding the first target feature;
[0026] Performing a second scoring calculation process and a screening process according to the first target feature set and the remaining candidate feature set to obtain a first training data set; the number of target features included in the first training data set is a preset target number;
[0027] The second project feature sets are screened one by one to obtain a plurality of the first training data sets.
[0028] According to some embodiments of the present application, performing a first scoring calculation process on each candidate feature in the first classification data set to obtain an initial first score for each candidate feature includes:
[0029] In the first classification data set, for each candidate feature j, a data fluctuation value of the candidate feature j is calculated; the data fluctuation value is used to characterize the difference between different categories of data corresponding to the candidate feature j, and the larger the data fluctuation value, the greater the difference; the smaller the data fluctuation value, the smaller the difference;
[0030] The first score of each candidate feature is calculated according to the data fluctuation value and the first scoring formula; wherein the first scoring formula is: Score j1 =1 / (alpha+F j);Score j1 is the first score, alpha is the preset fluctuation value, F j is the data fluctuation value of candidate feature j.
[0031] According to some embodiments of the present application, performing a second score calculation process and a screening process on the first target feature set and the remaining candidate feature set to obtain a first training data set includes:
[0032] Calculate a feature correlation value between each candidate feature in the remaining candidate feature set and all target features in the first target feature set; the feature correlation value is an average value of the absolute values of correlation coefficients between one candidate feature and all target features in the target feature set;
[0033] Calculate according to the feature correlation value, the data fluctuation value of the remaining candidate features and the second scoring formula to obtain a second score for each of the candidate features;
[0034] Determine the candidate feature with the highest second score as the second target feature;
[0035] According to the second target feature being stored in the first target feature set, an updated second target feature set and an updated remaining candidate feature set are obtained;
[0036] The next second scoring calculation process and screening process are continued according to the second target feature set and the updated remaining candidate feature set until the number of target features in the second target feature set is equal to the preset target number, and the second target feature set is determined as the first training data set.
[0037] According to some embodiments of the present application, the second scoring formula is:
[0038] Score j2 =1 / ((alpha+F j )*(beta+Corr j ));
[0039] Among them, Score j2 is the second score, alpha is the preset fluctuation value, F j is the data fluctuation value of candidate feature j, beta is the preset feature correlation value, Corr j is the feature related value.
[0040] According to some embodiments of the present application, performing weight allocation processing according to the plurality of first training data sets and the first project feature sets to obtain project model weights corresponding to the respective source projects includes:
[0041] Assigning a third category number to each sample in the first project feature set, and assigning a fourth category number to each sample in the first training data set;
[0042] Integrate the first item feature set with the third category number and the first training data set with the fourth category number to obtain a second classification data set;
[0043] Establishing a classification model based on the second classification data set, and evaluating the classification model to obtain a model performance score Fscorej;
[0044] Determine the project model weight according to the model performance score Fscorej;
[0045] The weights of the first training data sets are calculated one by one to obtain the project model weight corresponding to each of the source projects.
[0046] In a second aspect, an embodiment of the present application provides an electronic device comprising at least one processor and a memory for communicating with the at least one processor; the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform a cross-project software defect prediction method for a sorting task as described in any one of the embodiments of the first aspect.
[0047] In a third aspect, an embodiment of the present application provides a storage medium, which is a computer-readable storage medium, and the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute a cross-project software defect prediction method for sorting tasks as described in any one of the embodiments of the first aspect.
[0048] The embodiment of the present application includes: in the process of cross-project software defect prediction, first, extract the first project feature set of the target project and multiple second project feature sets of multiple source projects; then, perform feature scoring and feature screening according to the first project feature set and each second project feature set, and obtain multiple first training data sets; then, perform weight distribution according to the multiple first training data sets and the first project feature set, and obtain the project model weight corresponding to each source project; then, each first training data set is spliced with traditional manual features to obtain multiple second training data sets; then, modeling is performed based on the second training data set and the project model weight to obtain a defect prediction model; a defect prediction model with good prediction performance and high prediction accuracy is obtained; finally, the source code of each module of the target project to be tested is input into the defect prediction model to obtain a defect prediction result; wherein the defect prediction result includes the number of defects of each module and the module sorting based on the number of defects. The reliability and accuracy of the defect prediction result are high. That is to say, the embodiment of the present application can improve the accuracy and reliability of cross-project prediction of software defects by using the constructed defect prediction model with good prediction performance and high prediction accuracy.
[0049] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained through the structures particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 It is a flowchart of a cross-project software defect prediction method for sorting tasks provided by an embodiment of the present application;
[0051] Figure 2 This is an embodiment of the present application. Figure 1 A flowchart of a specific method of step S110;
[0052] Figure 3 This is an embodiment of the present application. Figure 1 A flowchart of a specific method of step S120;
[0053] Figure 4 This is an embodiment of the present application. Figure 1 A flowchart of a specific method of step S150;
[0054] Figure 5 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0056] It should be noted that although a logical order is shown in the flowchart in the description of the present application, in some cases, the steps shown or described may be performed in an order different from that in the flowchart. In the description of the present application, a number of means one or more, and a plurality of means two or more. The description of "first" and "second" is only used for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0058] The present application discloses a cross-project software defect prediction method for sorting tasks, an electronic device, and a storage medium. The method includes: extracting a first project feature set of a target project and multiple second project feature sets of multiple source projects; performing feature scoring processing and feature screening processing according to the first project feature set and each second project feature set, and obtaining multiple first training data sets; performing weight distribution processing according to multiple first training data sets and the first project feature set, and obtaining project model weights corresponding to each source project; splicing each first training data set with traditional manual features to obtain multiple second training data sets; performing modeling processing based on the second training data set and the project model weight to obtain a defect prediction model; inputting the source code of each module of the target project to be tested into the defect prediction model to obtain a defect prediction result. It can improve the accuracy and reliability of cross-project prediction of software defects.
[0059] The embodiments of the present application are further described below in conjunction with the accompanying drawings.
[0060] First, as Figure 1 As shown, an embodiment of the present application provides a cross-project software defect prediction method for sorting tasks, including but not limited to steps S110 to S160.
[0061] Step S110: extracting a first project feature set of a target project and a plurality of second project feature sets of a plurality of source projects;
[0062] Step S120: performing feature scoring processing and feature screening processing according to the first project feature set and each second project feature set, and correspondingly obtaining a plurality of first training data sets;
[0063] Step S130: performing weight allocation processing according to the plurality of first training data sets and the first project feature set to obtain project model weights corresponding to each source project;
[0064] Step S140: each first training data set is concatenated with the traditional manual features to obtain a plurality of second training data sets;
[0065] Step S150: performing modeling processing based on the second training data set and the project model weight to obtain a defect prediction model;
[0066] Step S160: inputting the source code of each module of the target project to be tested into the defect prediction model to obtain a defect prediction result; wherein the defect prediction result includes the number of defects of each module and the module ranking based on the number of defects.
[0067] It is understandable that in the modeling process in step S150, a random forest algorithm, a linear regression algorithm, or a ridge regression algorithm may be used. Therefore, the present application does not specifically limit the type of classification modeling algorithm used in the process of establishing the classification model.
[0068] Through step S110 to step S160, in the process of cross-project software defect prediction, first, extract the first project feature set of the target project and multiple second project feature sets of multiple source projects; then, perform feature scoring and feature screening according to the first project feature set and each second project feature set, and obtain multiple first training data sets; then, perform weight distribution according to the multiple first training data sets and the first project feature set, and obtain the project model weight corresponding to each source project; then, splice each first training data set with traditional manual features to obtain multiple second training data sets; then, perform modeling based on the second training data set and the project model weight to obtain a defect prediction model; obtain a defect prediction model with good prediction performance and high prediction accuracy; finally, input the source code of each module of the target project to be tested into the defect prediction model to obtain a defect prediction result; wherein the defect prediction result includes the number of defects of each module and the module sorting based on the number of defects. The reliability and accuracy of the defect prediction result are high. That is to say, the embodiment of the present application can improve the accuracy and reliability of cross-project prediction of software defects by utilizing the constructed defect prediction model with good prediction performance and high prediction accuracy.
[0069] According to some embodiments of the present application, Figure 2 , further illustrating step S110, step S110 extracts a first project feature set of a target project and multiple second project feature sets of multiple source projects, including but not limited to steps S111 to S114.
[0070] Step S111: obtaining a first abstract syntax tree of a target project and a plurality of second abstract syntax trees of a plurality of source projects;
[0071] Step S112: traverse all nodes of the first abstract syntax tree to obtain a first node sequence, and traverse all nodes of each second abstract syntax tree to obtain a plurality of second node sequences accordingly;
[0072] Step S113: converting the first node sequence into a first numerical vector, and converting the second node sequence into a second numerical vector;
[0073] Step S114: input the first numerical vector and the second numerical vector after dimension regularization into the feature extractor respectively, and output a first item feature set and multiple second item feature sets.
[0074] It is understandable that in step S111, a suitable static syntax analysis tool can be selected according to the programming language used in the software source code to obtain the abstract syntax tree of the code module. Specifically, for source code written in java language, javalang of python can be used for analysis.
[0075] It is understandable that software source code is usually written in a high-level programming language, often following a set of clear semantic definitions and grammatical rules, and is usually highly structured and standardized. In order to enable the defect prediction model to be established to fully utilize the grammatical information of the code, a node type sequence can be extracted from the abstract syntax tree of the code module, where the node type refers to the grammatical type corresponding to the syntax tree node token, such as class, method, operator, etc. That is, after obtaining the first abstract syntax tree of the target project and multiple second abstract syntax trees of multiple source projects, all nodes of the abstract syntax tree are traversed in a depth-first manner through step S112 to obtain the node sequence corresponding to each code file.
[0076] It is understandable that the node sequence traversed from the abstract syntax tree is a string sequence and cannot be directly input into the encoder to extract features, so the node sequence must first be converted into a numerical vector. In natural language processing, word vectors are usually used to represent words. When predicting software defects, the nodes of the abstract syntax tree can be regarded as a word in the natural language, and the corresponding word vectors are generated to convert the node sequence. Therefore, step S113 is then executed.
[0077] Specifically, step S113 includes but is not limited to: according to a preset word vector generation algorithm, converting the first AST node sequence into a first word vector table, converting the second AST node sequence into a second word vector table; according to the first word vector table, converting the words in the first AST node sequence into a first numerical vector; according to the second word vector table, converting the words in the second AST node sequence into a second numerical vector. Among them, because the skip-gram model has a better effect in generating rare words, the word vector generation algorithm preset in the embodiment of the present application is the skip-gram model. After obtaining the word vector tables of the source project and the target project, all the words in the node sequence can be converted into word vector matrices according to their respective word vector tables, that is, numerical vectors to be input into the feature extractor later; data preparation is performed for subsequent feature extraction.
[0078] It is understandable that since the length of each code file node sequence is different, the length of the converted numerical vector is also different and cannot be directly input into the feature extractor to extract features. Therefore, before executing step S114, the numerical vector needs to be dimensionally normalized.
[0079] According to some embodiments of the present application, step S114 is further described, and the dimensionality regularization processing includes: obtaining the vector length of the numerical vector to be input into the bidirectional long short-term memory neural network; when the vector length is greater than a preset length threshold, padding the numerical vector to obtain a regularized numerical vector; when the vector length is less than the preset length threshold, truncating the numerical vector to obtain a regularized numerical vector; wherein the vector length of the regularized numerical vector is equal to the preset length threshold.
[0080] Specifically, in order to balance the length of the numerical vector, the embodiments of the present application uniformly stipulate that the preset length threshold of the numerical vector is 64 dimensions. It can be understood that the preset length threshold can be set according to the actual feature extraction requirements. Therefore, the embodiments of the present application do not impose specific restrictions on this. For example: when the vector length of the numerical vector exceeds the preset length threshold, the numerical vector is truncated to make it 64 dimensions; when the vector length of the numerical vector is less than the preset length threshold, zeros are added to the numerical vector to make it 64 dimensions; when the vector length is equal to the preset length threshold, the numerical vector is not processed.
[0081] It is understandable that recurrent neural network (RNN) has achieved good results in the field of natural language processing, and long short-term memory neural network (LSTM) is an optimization of RNN network, which solves the problem of gradient disappearance of RNN network in long sequences, and can learn long-term dependent information. Since code is a structure with logic and semantics, it has the property of tight coupling, so the code fragments that produce defects are usually related to their contexts, and the selected feature extractor should be able to perform forward and reverse processing on the input sequence. Therefore, in step S114 of the embodiment of the present application, a bidirectional long short-term memory network (BLSTM) is used, that is, a two-layer LSTM network is used as a feature extractor. And since the present invention is directed to a sorting task, mean square error (MSE) is used as a loss function for parameter adjustment.
[0082] It should be noted that other deep learning algorithms can also be used for feature extraction in the embodiments of the present application, such as: Deep residual network (ResNet), GoogLeNet, dense convolutional network (Denselyconnected convolutional networks, DenseNet), etc. Therefore, the present application does not make specific restrictions on the type of feature extractor used in the feature extraction process.
[0083] Through step S111 to step S114, a first project feature set and multiple second project feature sets are extracted to prepare data for the subsequent establishment of a defect prediction model.
[0084] It is understandable that in cross-project software defect prediction, if a new project is predicted, it is necessary to completely rely on the data of other projects to build a prediction model. Normally, data from multiple source projects can be obtained as training data sets. Assuming that data from n source projects can be used as training data, since the feature extractor BiLSTM used in the embodiment of the present application is trained based on the data of all n projects used for training (including the source code and defect number of all modules), it may be mixed with some noise features when extracting features of different projects. Specifically, there is a significant difference between a certain feature extracted from the source project Pi and the same feature extracted from the target project Pobject, and this difference may have an adverse effect on modeling prediction. Therefore, the embodiment of the present application provides a feature screening mechanism implemented by step S120.
[0085] According to some embodiments of the present application, Figure 3 , further illustrating step S120, step S120: performing feature scoring processing and feature screening processing according to the first project feature set and each second project feature set, and correspondingly obtaining multiple first training data sets, including but not limited to steps S121 to S126.
[0086] Step S121: assign a first category number to each sample in the first project feature set; assign a second category number to each sample in the second project feature set.
[0087] Step S122: Integrate a first item feature set with a first category number and a second item feature set with a second category number to obtain a first classification data set; the first classification data set includes a plurality of candidate features.
[0088] Step S123: performing a first scoring calculation process on each candidate feature in the first classification data set to obtain an initial first score for each candidate feature.
[0089] Step S124: determining the candidate feature with the highest first score as the first target feature, obtaining a first target feature set including the first target feature and a remaining candidate feature set not including the first target feature.
[0090] Step S125: performing a second scoring calculation process and a screening process based on the first target feature set and the remaining candidate feature sets to obtain a first training data set; the number of target features included in the first training data set is a preset target number.
[0091] Step S126: Screen the second project feature sets one by one to obtain a plurality of first training data sets.
[0092] In step S126, feature screening as shown in steps S121 to S125 is performed on the second project feature set one by one, and a first training data set of multiple source projects can be obtained accordingly.
[0093] Through steps S121 to S126, a feature screening mechanism is implemented to provide training data with less differences, and provide training data of better quality for subsequent training prediction models, which is conducive to obtaining a defect prediction model with better prediction performance and higher prediction accuracy.
[0094] According to some embodiments of the present application, step S123 is further described. Step S123: performing a first scoring calculation process on each candidate feature in the first classification data set to obtain an initial first score for each candidate feature, including but not limited to steps S1231 to S1232.
[0095] Step S1231: In the first classification data set, the data fluctuation value of candidate feature j is calculated for each candidate feature j; the data fluctuation value is used to characterize the difference between different categories of data corresponding to the candidate feature j, the larger the data fluctuation value, the greater the difference; the smaller the data fluctuation value, the smaller the difference.
[0096] Step S1232: Calculate the first score of each candidate feature according to the data fluctuation value and the first scoring formula; wherein the first scoring formula is: Score j1 =1 / (alpha+F j );Score j1 is the first score, alpha is the preset fluctuation value, F j is the data fluctuation value of candidate feature j.
[0097] It is understandable that the data fluctuation value F j It is obtained by calculating the inter-group fluctuation or intra-group fluctuation for candidate feature j.
[0098] It is understandable that when Fj is too small, the divisor in the first scoring formula may be 0. In order to avoid this situation, the parameter alpha is added. The parameter alpha can depend on the value of the minimum data fluctuation value Fj. For example, when the minimum Fj is 1%, the parameter alpha is set to 1%. If the minimum Fj is 0, the parameter alpha can be set to 0.01 or other values. Therefore, this application does not make a specific limitation on the value of the parameter alpha.
[0099] Through step S1231 to step S1232, the candidate features are scored for the first time, providing a reliable reference for executing step S124 to screen out the features that are most similar to the data distribution of the target project; this is conducive to initially laying a good data foundation for the subsequent construction of a defect prediction model.
[0100] According to some embodiments of the present application, step S125 is further described. Step S125: performing a second score calculation process and a screening process based on the first target feature set and the remaining candidate feature sets to obtain a first training data set, including but not limited to steps S1251 to S1255.
[0101] Step S1251: Calculate the feature correlation value between each candidate feature in the remaining candidate feature set and all target features in the first target feature set; the feature correlation value is the average of the absolute values of the correlation coefficients between a candidate feature and all target features in the target feature set.
[0102] Step S1252: Calculate according to the feature correlation value, the data fluctuation value of the remaining candidate features and the second scoring formula to obtain the second score of each candidate feature.
[0103] Step S1253: Determine the candidate feature with the second highest score as the second target feature.
[0104] Step S1254: storing the second target feature in the first target feature set to obtain an updated second target feature set and an updated remaining candidate feature set.
[0105] Step S1255: Continue the next second scoring calculation process and screening process according to the second target feature set and the updated remaining candidate feature set until the number of target features in the second target feature set is equal to the preset target number, and determine the second target feature set as the first training data set.
[0106] According to some embodiments of the present application, the second scoring formula in step S1252 is:
[0107] Score j2 =1 / ((alpha+F j )*(beta+Corr j ));
[0108] Among them, Score j2 is the second score, alpha is the preset fluctuation value, F j is the data fluctuation value of candidate feature j, beta is the preset feature correlation value, Corr j is the feature related value.
[0109] It is understandable that when Corrj is too small, the divisor in the second scoring formula may be 0. In order to avoid this situation, a parameter beta is added. The parameter beta can depend on the minimum feature correlation value Corr j The value of, for example, Corr j If the minimum value of Corr is 1%, then the parameter beta can be set to 1%. j The minimum value of is 0, then the parameter beta can be set to 0.01 or other values. Therefore, this application does not make any specific restrictions on the value of the parameter beta. The second scoring formula 1 / (alpha+F j ) is the first score, and the parameter definition thereof can refer to the aforementioned description of the first scoring formula, which will not be repeated here.
[0110] Through step S1251 to step S1255, after the first target feature is selected, start from selecting the second target feature, score based on the correlation between the features, and select the remaining target features until a preset target number of target features are obtained; thus laying a good data foundation for the subsequent construction of a defect prediction model.
[0111] An example is given to illustrate the feature screening mechanism provided by the embodiment of the present application.
[0112] Assume that the first feature set of the extracted target project is P object , P1, P2, ... P n The n second project feature sets are obtained by extracting features from n source projects for training using BiLSTM. The second project feature set is recorded as Pi (i = 1, 2, 3 ..., n). The total number of features of a second project feature set (such as P1) is m, and the number of target features to be screened is k (usually, k is 0.2*m). The feature screening process of the second project feature set Pi (i = 1, 2, 3 ..., n) of the source project is as follows:
[0113] First, data preprocessing is performed on the second project feature set Pi (i=1, 2, 3, ..., n), and the predicted value (number of defects) is deleted to obtain the second project feature set after data preprocessing.
[0114] Secondly, assign category number 1 (i.e., the second category number) to each sample in the second feature set Pi, and assign category number 1 (i.e., the second category number) to each sample in the first feature set P object Each sample of is assigned a category number -1 (i.e., the first category number); and the second item feature set Pi and P assigned the category number object Form a first classification data set D i1 .
[0115] Next, in the first classification data set D i1 For each candidate feature j, the data fluctuation value F is calculated j . Data fluctuation value F j The closer the value of is to 0, the more it indicates that different categories of data (i.e., Pi and P object The smaller the data on feature j) is, the smaller the significant difference is. In other words, the data fluctuation value F j The closer the value of is to 0, the higher the similarity between the data distribution of the source project and the target project based on the candidate feature j, and the more reference value the data of the source project has. Therefore, the first score assigned to each feature j is: Score j1 =1 / (alpha+F j );Score j1 is the first score, alpha is the preset fluctuation value, F j is the data fluctuation value of candidate feature j.
[0116] Next, the candidate feature j with the highest first score is selected as the first target feature, and a first target feature set including the first target feature is obtained.
[0117] Then, when selecting the second to kth target features, the correlation between features needs to be further considered. Assuming that the Selected set (i.e., the target feature set) is used to store the selected target features, the Selected set is used to perform the second score calculation on the remaining candidate features j in the remaining candidate feature set:
[0118] Score j2 =1 / ((alpha+F j )*(beta+Corr j )).
[0119] Among them, Corr j is the average of the absolute values of the correlation coefficients between feature j and all target features in the Selected set. That is, starting from selecting the second feature, the candidate feature j with the second highest score is selected as the target feature according to the new score until the required preset target number k is reached.
[0120] Specifically, the Selected set that only includes the first target feature is recorded as the first target feature set. In the process of selecting the second target feature, the candidate feature j is correlated with the first target feature in the first target feature set one by one to obtain the correlation coefficient, and further obtain Corr j Then, based on the Corr j Calculate the second score of each candidate feature j, select the candidate feature j with the highest second score as the second target feature, add the second target feature to the first target feature set, and obtain the second target feature set and the remaining candidate feature set that does not include the second target feature.
[0121] Based on the second target feature set and the remaining candidate feature set, a candidate feature j in the remaining candidate feature set is correlated with the two target features in the second target feature set to obtain two correlation coefficients. The average of the absolute values of the two correlation coefficients is calculated as Corr j , and then calculate the second score of the candidate feature j; similarly, calculate the second score of each candidate feature j in the remaining candidate feature set, and select the candidate feature j with the highest second score as the third target feature. Add the third target feature to the second target feature set to obtain an updated second target feature set and the remaining candidate feature set that does not include the third target feature.
[0122] The screening is performed in a similar manner until the number of selected target features reaches a preset target number k, thereby obtaining a first screened training data set of a source project.
[0123] The above-mentioned feature screening is performed on the second project feature sets one by one, thereby obtaining a plurality of first training data sets accordingly.
[0124] It is understandable that in cross-project software defect prediction, if a new project is predicted, data from n other projects can be obtained as training data sets. However, there may be different degrees of differences in data distribution between these source projects and the target projects to be predicted. Therefore, the embodiment of the present application proposes to assign different weights to the prediction models constructed for different projects, as described below.
[0125] According to some embodiments of the present application, Figure 4 , further illustrating step S150, step S150: performing weight allocation processing according to multiple first training data sets and first project feature sets to obtain project model weights corresponding to each source project, including but not limited to steps S151 to S155.
[0126] Step S151: assign a third category number to each sample in the first project feature set, and assign a fourth category number to each sample in the first training data set.
[0127] Step S152: Integrate the first project feature set with the third category number and the first training data set with the fourth category number to obtain a second classification data set.
[0128] Step S153: Establish a classification model based on the second classification data set, and evaluate the classification model to obtain a model performance score Fscorej.
[0129] Step S154: Determine the project model weight according to the model performance score Fscorej.
[0130] Step S155: Calculate the weights of the first training data sets one by one to obtain the project model weights corresponding to the source projects.
[0131] Specifically, the classification model building algorithm used in the process of establishing the classification model in step S153 is random forest. In addition, SVM (support vector machines) algorithm, logistic regression algorithm, neural network algorithm, naive Bayes algorithm and other classification model building algorithms can also be used. Therefore, this application does not make specific restrictions on the classification model building algorithm adopted.
[0132] Specifically, step S154 is: subtract the model performance score Fscorej from 1 to obtain the project model weight.
[0133] Through steps S151 to S155, a project weight allocation strategy is implemented, which can solve the problem of significant distribution differences between different project data in cross-project software defect prediction based on sorting tasks, and reduce the significant distribution differences between different project data.
[0134] An example is given to illustrate the project weight allocation strategy provided in the embodiment of the present application.
[0135] Assume that the first feature set of the extracted target project is P object , NP1, NP2, ... NP n After feature screening, multiple first training data sets are obtained. The first training data set is denoted as NP i (i=1,2,3…,n), then according to NP i The process of solving the project model weights of the constructed prediction model is as follows:
[0136] NP i The predicted value (number of defects) is deleted, and each sample is assigned a category number of 1. object Each sample is assigned a category number of -1 and a category number of NP i and P object Composed of the second classification data set D i2 .
[0137] In the second classification data set D i2 The 5-fold cross validation method is used above, and the random forest is used to establish a classification model for the data set, and Fscore is used as the model measurement indicator. The better the classification model performance, the closer the Fscore is to 1, indicating that the difference between the two data sets is more obvious, and the weight given should be smaller. Assume that the F-score of the 5-fold cross validation is the model performance score F-score i , then give NP i The project model weights of the constructed prediction model are:
[0138] Weight i =1-Fscore i ;
[0139] Among them, i is the i-th first training data set, Fscore i The model performance score of the prediction model built for the i-th first training data set; Weight i The weight assigned to the prediction model constructed for the i-th first training dataset.
[0140] Further explanation of step S140: each first training data set is concatenated with traditional manual features to obtain multiple second training data sets. It can be understood that traditional manual features are manually obtained, such as features such as the number of lines of code.
[0141] It can be understood that for each source project used for training, after the second project feature set is subjected to feature screening, multiple first training data sets are obtained: NP1, NP2, ... NP n; Then it is spliced with traditional manual features to form a new second training data set MP1, MP2, ..., MP n .
[0142] Further explanation of step S150 and step S160, specifically, after obtaining a new second training data set MP i (i=1, 2, 3, ... n), then a regression model is constructed using the random forest method, and a prediction model is constructed based on each second training data set. If there are n second training data sets, n prediction models are constructed, and each prediction model is assigned a project model weight determined by step S150. Based on the project model weights of the n prediction models, the weight coefficient C of each prediction model is re-determined. i Based on the re-determined n prediction models and the weight coefficient C corresponding to each prediction model i and constructing a final defect prediction model; detecting the source code of each module of the target project to be tested based on the defect prediction model, and outputting defect prediction results; the defect prediction results include the number of defects of each module and the module ranking based on the number of defects.
[0143] Among them, the weight coefficient C of each prediction model is re-determined i The process is:
[0144] Calculate the sum of the project model weights of n forecast models The weight coefficient C of the re-determined i-th prediction model i =Weight i / W.
[0145] For example: when n=3, assuming that the calculated project model weights of the three prediction models are 0.2, 0.3, and 0.4 respectively, the actual weight coefficients of each prediction model should be re-determined as: 0.2 / 0.9, 0.3 / 0.9, and 0.4 / 0.9. In this way, when the defect prediction results of the three models for the modules to be tested in the new project are 1, 2, and 5 respectively, the final prediction value (that is, the number of defects in the defect prediction results) should be (0.2+0.3*2+0.4*5) / 0.9=3.11. After obtaining the number of defects for each module, the modules to be tested are sorted based on the number of defects to obtain the module sorting. At this point, the cross-project software defect prediction of the sorting task has been realized.
[0146] In summary, the cross-project software defect prediction method for sorting tasks implemented in the embodiment of the present application proposes a project weight allocation, which solves the problem that there may be significant distribution differences between different project data faced in the cross-project software defect prediction for sorting tasks; and implements a feature screening mechanism for the features extracted from the source code. While considering the importance of the features, it also takes into account the correlation between the features to ensure the effectiveness and representativeness of the selected feature set.
[0147] Second, as Figure 5 As shown, the present application also provides an electronic device 500, including:
[0148] The processor 501 may be implemented by a general-purpose central processing unit, a microprocessor, an application-specific integrated circuit, or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0149] The memory 502 may be implemented in the form of a read-only memory, a static storage device, a dynamic storage device, or a random access memory. The memory 502 may store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 502, and the processor 501 calls and executes the cross-project software defect prediction method for the sorting task of the embodiment of this application;
[0150] Input / output interface 503, used to implement information input and output;
[0151] Communication interface 504, used to realize communication interaction between the present apparatus and other devices, which can be realized by wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.);
[0152] A bus 505 that transmits information between the various components of the device (e.g., the processor 501, the memory 502, the input / output interface 503, and the communication interface 504);
[0153] The processor 501 , the memory 502 , the input / output interface 503 and the communication interface 504 are connected to each other in communication within the device via the bus 505 .
[0154] In a third aspect, an embodiment of the present application provides a storage medium, which is a computer-readable storage medium. The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute a cross-project software defect prediction method for a sorting task such as the above embodiment.
[0155] As a non-transient computer-readable storage medium, the memory can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage devices. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and are implemented to be located in one place, or may also be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0156] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that may be used to store desired information and may be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically include computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0157] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above implementation mode. Technical personnel familiar with the field can also make various equivalent modifications or substitutions under the shared conditions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.
[0158] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above-mentioned implementation mode. Technical personnel familiar with the field can also make various equivalent deformations or substitutions without violating the spirit of the present application. These equivalent deformations or substitutions are all included in the scope defined by the present application.
Claims
1. A cross-project software defect prediction method for sorting tasks, characterized in that: include: Extracting a first project feature set of a target project and a plurality of second project feature sets of a plurality of source projects; Perform feature scoring and feature screening according to the first project feature set and each of the second project feature sets, and correspondingly obtain a plurality of first training data sets; Perform weight allocation processing according to the plurality of the first training data sets and the first project feature sets to obtain project model weights corresponding to the respective source projects; splicing each of the first training data sets with traditional manual features to obtain multiple second training data sets; Performing modeling based on the second training data set and the project model weights to obtain a defect prediction model; The source code of each module of the target project to be tested is input into the defect prediction model to obtain a defect prediction result; wherein the defect prediction result includes the number of defects of each module and the module ranking based on the number of defects.
2. The cross-project software defect prediction method for sequencing tasks according to claim 1, characterized in that: The step of extracting a first project feature set of a target project and a plurality of second project feature sets of a plurality of source projects comprises: Obtaining a first abstract syntax tree of the target project and a plurality of second abstract syntax trees of the plurality of source projects; Traversing all nodes of the first abstract syntax tree to obtain a first node sequence, and traversing all nodes of each of the second abstract syntax trees to obtain a plurality of second node sequences accordingly; Convert the first node sequence into a first numerical vector, and convert the second node sequence into a second numerical vector; The first numerical vector and the second numerical vector after dimension regularization are respectively input into a feature extractor, and the first item feature set and a plurality of the second item feature sets are output.
3. The cross-project software defect prediction method for sequencing tasks according to claim 2, characterized in that: The dimension regularization process includes: Obtaining the vector length of the numerical vector to be input into the bidirectional long short-term memory neural network; When the length of the vector is greater than a preset length threshold, padding the numerical vector to obtain a regularized numerical vector; When the vector length is less than a preset length threshold, the numerical vector is truncated to obtain a regularized numerical vector; wherein the vector length of the regularized numerical vector is equal to the preset length threshold.
4. The cross-project software defect prediction method for sequencing tasks according to claim 2, characterized in that: The feature scoring process and feature screening process are performed according to the first project feature set and each of the second project feature sets, and a plurality of first training data sets are obtained accordingly, including: Assigning a first category number to each sample in the first item feature set; assigning a second category number to each sample in the second item feature set; Integrate the first item feature set with the first category number and the second item feature set with the second category number to obtain a first classification data set; the first classification data set includes a plurality of candidate features; Performing a first scoring calculation process on each candidate feature in the first classification data set to obtain an initial first score for each candidate feature; Determine the candidate feature with the highest first score as a first target feature, obtain a first target feature set including the first target feature and a remaining candidate feature set excluding the first target feature; Performing a second scoring calculation process and a screening process according to the first target feature set and the remaining candidate feature set to obtain a first training data set; the number of target features included in the first training data set is a preset target number; The second project feature sets are screened one by one to obtain a plurality of the first training data sets.
5. The cross-project software defect prediction method for sequencing tasks according to claim 4, characterized in that: The performing a first scoring calculation process on each candidate feature in the first classification data set to obtain an initial first score for each candidate feature includes: In the first classification data set, for each candidate feature j, a data fluctuation value of the candidate feature j is calculated; the data fluctuation value is used to characterize the difference between different categories of data corresponding to the candidate feature j, and the larger the data fluctuation value, the greater the difference; the smaller the data fluctuation value, the smaller the difference; The first score of each candidate feature is calculated according to the data fluctuation value and the first scoring formula; wherein the first scoring formula is: Score j1 =1 / (alpha+F j );Score j1 is the first score, alpha is the preset fluctuation value, F j is the data fluctuation value of candidate feature j.
6. The cross-project software defect prediction method for sequencing tasks according to claim 5, characterized in that: The step of performing a second scoring calculation process and a screening process according to the first target feature set and the remaining candidate feature set to obtain a first training data set comprises: Calculate a feature correlation value between each candidate feature in the remaining candidate feature set and all target features in the first target feature set; the feature correlation value is an average value of the absolute values of correlation coefficients between one candidate feature and all target features in the target feature set; Calculate according to the feature correlation value, the data fluctuation value of the remaining candidate features and the second scoring formula to obtain a second score for each of the candidate features; Determine the candidate feature with the highest second score as the second target feature; According to the second target feature being stored in the first target feature set, an updated second target feature set and an updated remaining candidate feature set are obtained; The next second scoring calculation process and screening process are continued according to the second target feature set and the updated remaining candidate feature set until the number of target features in the second target feature set is equal to the preset target number, and the second target feature set is determined as the first training data set.
7. The cross-project software defect prediction method for sequencing tasks according to claim 6, characterized in that: The second scoring formula is: Score j2 =1 / ((alpha+F j )*(beta+Corr j )); Among them, Score j2 is the second score, alpha is the preset fluctuation value, F j is the data fluctuation value of candidate feature j, beta is the preset feature correlation value, Corr j is the feature related value.
8. The cross-project software defect prediction method for sequencing tasks according to claim 1, characterized in that: The step of performing weight allocation processing according to the plurality of the first training data sets and the first project feature sets to obtain project model weights corresponding to the respective source projects includes: Assigning a third category number to each sample in the first project feature set, and assigning a fourth category number to each sample in the first training data set; Integrate the first item feature set with the third category number and the first training data set with the fourth category number to obtain a second classification data set; Establishing a classification model based on the second classification data set, and evaluating the classification model to obtain a model performance score Fscorej; Determine the project model weight according to the model performance score Fscorej; The weights of the first training data sets are calculated one by one to obtain the project model weight corresponding to each of the source projects.
9. An electronic device, characterized in that: It includes at least one processor and a memory for communicating with the at least one processor; the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the cross-project software defect prediction method for sorting tasks as described in any one of claims 1 to 8.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the cross-project software defect prediction method for sorting tasks as described in any one of claims 1 to 8.
Citation Information
Cited By
Method and device for establishing prediction software defect optimization model and computer equipment
CN121050998A
Method, device and computer device for establishing a predictive software defect optimization model
CN121050998B
