Source project selection method and defect prediction method for cross-project software defect prediction
By constructing a multi-project dataset and SMOreg algorithm to predict evaluation index values, combined with TCA+ transfer learning method, the most suitable source project is determined, which solves the problem of difficulty in selecting training data in cross-project software defect prediction, and improves the accuracy of defect prediction and stability.
Patent Information
- Application Number
- CN202410996680.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-11-12
AI Technical Summary
The problem of difficult selection of training data in cross-project software defect prediction leads to instability of transfer learning methods.
A multi-project data set was constructed, paired evaluation index values and project characteristics were extracted, and a model was established through the SMOreg algorithm, and the evaluation index values were predicted to determine the most suitable source project, and defect prediction was performed in combination with the transfer learning method TCA+.
It effectively solves the problem of difficulty in selecting training data, improves the accuracy of defect prediction and model stability, ensures the optimality of source project selection, and improves the performance of cross-project defect prediction.
Smart Images

Figure CN118940135A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of cross-project software defect prediction, and more specifically, relates to a source project selection method and a defect prediction method for cross-project software defect prediction. Background Art
[0002] Software defect prediction is an important research direction in the field of software engineering. Its purpose is to help developers find and fix potential defects in the software in a timely manner during the software development process, thereby improving the quality and reliability of the software. In modern software development, software quality is a crucial aspect, because software defects can not only cause system crashes and functional failures, but also may cause serious security issues and economic losses. Therefore, the research and application of effective defect prediction technology has important practical significance.
[0003] In the past few decades, software defect prediction mainly refers to the traditional Within-Project Defect Prediction (WPDP), which has received extensive attention and research. WPDP mainly relies on the method of machine learning (ML). By learning from historical data, a prediction model is established and applied to subsequent versions of the same project for defect prediction. The basic assumption of this method is that different versions of the same project have similar features and defect patterns, so defects in future versions can be predicted by analyzing the data of historical versions.
[0004] However, the WPDP method requires a large amount of labeled data (i.e., historical data of known defects) to train the prediction model. Second, WPDP assumes that different versions of the same project have similar features and defect patterns, but this assumption does not always hold true in practice. As the project develops, factors such as changes in the code base, the introduction of new features, and changes in the development team will lead to feature differences between different versions, thus affecting the accuracy of the prediction model.
[0005] In order to solve the limitations of the WPDP method, cross-project defect prediction (CPDP) has gradually become a research hotspot in recent years. The CPDP method uses data from other projects to perform defect prediction to solve the problems of insufficient data and feature differences. The core idea of CPDP is that although there are differences between different projects, they still have certain similarities in certain features and defect patterns, so the effect of defect prediction can be improved through cross-project data migration and learning.
[0006] The main challenge of cross-project defect prediction is how to effectively select source projects and migrate the data of source projects to target projects. To this end, researchers have proposed a variety of transfer learning methods, which can establish a mapping relationship between source projects and target projects, thereby achieving effective data migration and feature sharing. However, transfer learning methods still have instability problems, that is, unstable performance will be generated due to different selections of training data. Therefore, source selection and combined transfer learning methods are widely used to ensure that the selected source projects can maximize the prediction performance of the target project, and make good use of the characteristics of transfer learning to solve the instability problem of transfer learning. Summary of the invention
[0007] The technical problem to be solved by the present invention is to provide a source project selection method for cross-project software defect prediction, which solves the problem of difficulty in selecting training data in cross-project defect prediction.
[0008] The technical solution adopted by the present invention to solve the above technical problems is: a source project selection method for cross-project software defect prediction.
[0009] Build and prepare multi-project datasets;
[0010] For each project in the multi-project data set, extract the paired evaluation index values, perform normalization, extract the median of the source project features and the median of the target project features, and form a project feature median vector;
[0011] Establish a vector consisting of the median value of the target project feature, the median value of the source project feature, and the evaluation index value, and use the collection of all new vectors as a training set;
[0012] The training set is input into the SMOreg algorithm to establish a model, and then the collection of the median vectors of the project features is used as a test set to predict the evaluation index value;
[0013] Determine the source project that best suits the target project based on the predicted evaluation index value.
[0014] According to the above method, the construction and preparation of the multi-project dataset are specifically as follows:
[0015] Taking the specific version of a project as the unit, select the open source cross-project defect prediction multi-project collection as the data set, and ensure that the types and quantities of features selected for different projects are the same; when performing defect prediction, exclude the situation where the source project and the target project are different versions of the same project.
[0016] According to the above method, the method for extracting the evaluation index value is specifically as follows:
[0017] Two different projects are selected from the data set as the source project and the target project respectively, and then the transfer learning method is applied, and then the Logistic model is established for prediction.
[0018] According to the above method, the method used for normalization processing is the z-score method.
[0019] According to the above method, the method for establishing a training set is specifically as follows:
[0020] A new vector is established by merging the source project feature median vector, the target project feature median vector and the corresponding evaluation index value in order, and the collection of all new vectors is used as the training set.
[0021] According to the above method, the method for selecting the source project that best suits the target project is as follows:
[0022] The evaluation index values are sorted, and the source project corresponding to the highest evaluation index value is the best source project for the target project.
[0023] As a second aspect, the present invention also provides a cross-project software defect prediction method based on a combination of source selection and transfer learning, which uses the source project selection method mentioned above in the inventive content of the present invention to determine the source project that best suits the target project; the corresponding source project and target project are added to the transfer learning method TCA+, and a Logistic regression model is established for defect prediction.
[0024] According to the above defect detection method: the F1-Score and AUC indicators are used to evaluate the performance of the software defect prediction method.
[0025] A third aspect of the present invention provides a computer-readable storage medium.
[0026] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the cross-project software defect prediction method based on a combination of source selection and transfer learning as described above.
[0027] A fourth aspect of the present invention provides a computer device.
[0028] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the cross-project software defect prediction method based on the combination of source selection and transfer learning as described above is implemented.
[0029] The beneficial effects of the present invention are:
[0030] The present invention proposes a new source project selection method, which extracts paired evaluation index values and project feature medians by constructing and preparing a multi-project data set, adding the source project and target project in the multi-project data set to the transfer learning method, normalization processing, etc. The extracted data is composed into vectors, the collection of vectors is used as the training set, and the project feature median vector is used as the test set to predict the evaluation index value, thereby determining the source project that best suits the target project, avoiding the situation where it is difficult to select training data in cross-project defect prediction.
[0031] The present invention also provides a method combination of optimal source selection and transfer learning in cross-project defect prediction, namely, a source selection method combined with a transfer learning method TCA+, which solves the instability problem of the transfer learning method. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A flow chart of a source project selection method according to an embodiment of the present invention;
[0033] Figure 2 A flow chart of a defect prediction method according to an embodiment of the present invention;
[0034] Figure 3 A schematic diagram of the source item selection method of the present invention;
[0035] Figure 4 This is the F1-Score graph obtained by using different source selection combined transfer learning technology in the present invention;
[0036] Figure 5 This is the Accuracy graph obtained by using different source selection combination transfer learning technology in the present invention. DETAILED DESCRIPTION
[0037] The following is a clear and complete description of the technical solutions in the embodiments of the invention in conjunction with the drawings in the embodiments of the invention. Obviously, the described embodiments are only part of the embodiments of the invention, not all of the embodiments. Based on the embodiments of the invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the invention.
[0038] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present application should have the common meanings understood by persons having ordinary skills in the field to which the present disclosure belongs.
[0039] In order to facilitate the understanding of this application document, the following keywords need to be explained as follows:
[0040] TLearnings: A collection of TCA+ methods, BDA methods, JDA algorithms, and KMM methods.
[0041] TCA+ method: By learning an optimal inter-domain mapping, the feature space of the source domain and the target domain is mapped to a shared low-dimensional representation space, so that the data distribution of the two domains in this space is as close as possible;
[0042] BDA method: The domain adaptation problem is transformed into an optimization problem. The goal is to minimize the data distribution difference between the source domain and the target domain, including the marginal distribution difference and the conditional distribution difference. At the same time, matrix techniques and regularization are introduced to control the model complexity.
[0043] JDA algorithm: By minimizing the marginal distribution difference between domains, a unified projection space is learned to make the distribution between the source domain and the target domain more similar;
[0044] KMM method: It is a non-parametric domain adaptation method that aims to make the performance of the model on the target domain comparable to that on the source domain by adjusting the sample weights of the target domain.
[0045] TP (True Positive): True positive, the number of instances correctly predicted by the model as positive;
[0046] FP (False Positive): False positive examples, the number of instances that the model incorrectly predicts as positive;
[0047] TN (True Negative): True negative examples, the number of instances correctly predicted by the model as negative;
[0048] FN (False Negative): False negative examples, the number of instances that the model incorrectly predicts as negative;
[0049] Precision: The proportion of all instances predicted to be positive that are actually positive.
[0050] The calculation formula is:
[0051]
[0052] Recall: The proportion of instances that are correctly predicted to be positive among all instances that are actually positive.
[0053] The calculation formula is:
[0054]
[0055] F1-Score is the harmonic mean of Precision and Recall, which is used to evaluate model performance when there is class imbalance. The calculation formula is:
[0056]
[0057] AUC: The area under the ROC curve, which is used to evaluate the overall performance of the classification model.
[0058] The present invention provides a source project selection method for cross-project software defect prediction, such as Figure 1 As shown, the following steps are included:
[0059] S1. Build and prepare multi-project datasets. The specific implementation process is as follows:
[0060] We selected 41 versions from 13 projects from the open source PROMISE repository as the dataset, as listed in Table 1, where #Class represents the number of class files; #Defect represents the number of defective classes; %Defect represents the percentage of defective classes; the dataset is based on a specific version of a project, and ensures that the types and quantities of features selected for different projects are the same. When making predictions, we should exclude the case where the source project and the target project are different versions of the same project.
[0061] Table 1 Multi-project dataset
[0062]
[0063]
[0064] S2. Use the source selection method to select training items for the target item to form a training set and a test set, specifically:
[0065] S2.1. For each project in the multi-project data set, extract the paired evaluation index values, perform normalization, extract the median of the source project features and the median of the target project features, and form the project feature median vector. The specific implementation process is as follows:
[0066] Each project in the data set is used as the source project and the target project respectively, and two different projects are selected from the data set as the source project i and the target project j respectively, excluding the case where the source project and the target project are different versions of the same project. The transfer learning method is applied to establish a Logistic model for prediction and obtain the evaluation index value Mij.
[0067] S2.2. Normalize the project features, extract their medians, and form the project feature median vector. The specific implementation process is as follows:
[0068] Each feature column of each item in the dataset is normalized using the z-score method.
[0069] The calculation method of the z-score method is:
[0070]
[0071] In the formula, x i is the original value of the ith metric of feature x, μ is the mean value of item feature x, σ is the standard deviation of item feature x, is x i Normalized value.
[0072] {X1, X2, ..., Xn} is the given source project set; Median(Xi') is the source project feature median vector, Median(Xj') is the target project feature median vector, and Mij is the evaluation index value.
[0073] According to the normalized result, the median of each column feature is extracted to form the feature median vector of the project. For a given source project set {X1, X2, ..., Xn}, for each project Xi, let Xi'=zscore(Xi), Median(Xi') is the vector composed of the median of all feature measurement values of Xi'.
[0074] S2.3. Establish a vector consisting of the median value of the source project feature, the median value of the target project feature and the evaluation index value. The collection of vectors is used as the training set. The specific implementation process is as follows:
[0075] According to the project feature median vector obtained in step S2.2 and the paired evaluation index values obtained in step S2.1, for all projects in the data set, excluding the combination of source and target projects as different versions of the same project, the source project feature median vector Median(Xi'), the target project feature median vector Median(Xj') and the corresponding evaluation index value Mij are sequentially combined to create a new vector. The new vectors obtained from all combinations are collected to create a training data set.
[0076] S2.4. Input the training set into the SMOreg algorithm to build a model, and then use the collection of the median vectors of the project features as the test set to predict the evaluation index value. The specific implementation process is as follows:
[0077] Input the training data set obtained in step S2.3 into the SMOreg algorithm to build the model. According to the median vectors of each project feature Median(Xi') obtained in step S2.2, merge them into a new vector in the order of the source project feature median vector Median(Xi') and the target project feature median vector Median(Xj'). The collection of new vectors is used as a test set and input into the SMOreg model for prediction to obtain the evaluation index value Mij'.
[0078] S2.5. Determine the source project that best suits the target project based on the predicted evaluation index value. The specific implementation process is as follows:
[0079] According to the predicted evaluation index values Mij' of target projects of different source project combinations obtained in step S2.4, these evaluation index values are sorted from high to low, and the source project i corresponding to the highest evaluation index value MAX(Mij') is the best source project for the target project j.
[0080] The present invention also provides a cross-project software defect prediction method based on a combination of source selection and transfer learning, which is specifically implemented as follows:
[0081] T1. Select the most appropriate source project based on the source project selection method.
[0082] T2. Add the selected source project and target project to the optimal transfer learning method TCA+.
[0083] The reason why the present invention chooses the transfer learning method TCA+ is that it has the best effect. It is specifically certified by the following methods:
[0084] Select a transfer learning method from the TLearnings set, select the best source project for each project according to the source project selection method described in step S2 based on the dataset constructed in step S1, add the selected source project and target project together to the transfer learning method, build a Logistic model, obtain the F1-Score and AUC performance parameters, and calculate the average performance of all projects under the transfer learning method. When all transfer learning methods are combined with the source project selection method, we evaluate the best transfer learning method on 41 datasets. The results of the four combinations are shown in Tables 2 and 3. Regardless of the performance of F1-Score or AUC, after the source project is selected by the source project selection method, the transfer learning method TCA+ can obtain the best results.
[0085] Table 2 F1-Score values of the source project selection method for the four transfer learning methods
[0086]
[0087]
[0088] Table 3 AUC values of the source project selection method for the four transfer learning methods
[0089]
[0090]
[0091]
[0092] T3. Establish a Logistic regression model for defect prediction.
[0093] Under the same experimental environment, the method of the present invention is compared with the existing source selection methods SPE, KNN-TDS, Median_zscore, CFPS, and Bellwether combined transfer learning method set. The performance is also compared by F1-Score and AUC indicators on 41 versions of data sets from 13 projects.
[0094] Figure 4 and Figure 5 A box plot comparison of different source selection method combinations and different transfer learning methods is given. Whether in F1-Score or AUC, it can be seen that the source project selection method combination TCA+ performs best in box distribution, median, and mean, leading all other combinations. According to the above results, the prediction method provided by the present invention has good prediction performance.
[0095] This embodiment also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps in the source project selection method and defect prediction method for cross-project software defect prediction as described above are implemented.
[0096] This embodiment also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the source project selection method and defect prediction method for cross-project software defect prediction as described above are implemented.
[0097] The present invention proposes a new source project selection method, establishes a mapping relationship between the source project and the target project, and utilizes cross-project data resources to achieve effective data migration and feature sharing. The present invention also combines source selection and the optimal transfer learning method for software defect detection, ensuring that the selected source project can maximize the prediction performance of the target project while making good use of the characteristics of transfer learning, overcoming the limitations of the traditional WPDP method and improving the accuracy of defect prediction. The present invention can not only effectively solve the problem of insufficient data in software project defect prediction, but also improve the generalization ability and practical application value of the prediction model.
[0098] Finally, it should be noted that what is disclosed above is only a specific embodiment of the present invention, but the embodiment of the present invention is not limited thereto, and any changes that can be conceived by those skilled in the art should fall within the protection scope of the present invention.
Claims
1. A source project selection method for cross-project software defect prediction, characterized by: Build and prepare multi-project datasets; For the projects in the multi-project data set, extract the paired evaluation index values, perform normalization, extract the median of the source project features and the median of the target project features, and form the project feature median vector; Establish a vector consisting of the median value of the target project feature, the median value of the source project feature, and the evaluation index value, and use the collection of all new vectors as a training set; The training set is input into the SMOreg algorithm to establish a model, and then the collection of the median vectors of the project features is used as a test set to predict the evaluation index value; Determine the source project that best suits the target project based on the evaluation index value.
2. The source project selection method according to claim 1, characterized in that: When building and preparing multi-project datasets, we select a multi-project collection of open source cross-project defect prediction as the dataset based on the specific version of a project, and ensure that the types and quantities of features selected for different projects are the same; When performing defect prediction, exclude the case where the source project and the target project are different versions of the same project.
3. The source project selection method according to claim 1, characterized in that: The specific method for extracting the evaluation index value is: select two different projects from the data set as the source project and the target project respectively, then apply the transfer learning method, and then establish a Logistic model for prediction.
4. The source project selection method according to claim 1, characterized in that: The normalization process adopts the z-score method.
5. The source project selection method according to claim 1, characterized in that: The training set is established in the following manner: a source project feature median vector, a target project feature median vector and a corresponding evaluation index value are combined in order to establish a new vector, and the collection of all new vectors is used as the training set.
6. The source project selection method according to claim 1, characterized in that: The method for selecting the source project that best suits the target project is specifically: sorting the evaluation index values, and the source project corresponding to the highest evaluation index value is the best source project for the target project.
7. A cross-project software defect prediction method based on a combination of source selection and transfer learning, characterized in that: Using the source project selection method described in any one of claims 1 to 6 to determine the source project that best suits the target project; The corresponding source and target projects are added to the transfer learning method TCA+, and a Logistic regression model is established for defect prediction.
8. The cross-project software defect prediction method based on the combination of source selection and transfer learning according to claim 7, characterized in that: The F1-Score and AUC indicators are used to evaluate the performance of software defect prediction methods.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the cross-project software defect prediction method based on the combination of source selection and transfer learning as described in claim 8 is implemented.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the cross-project software defect prediction method based on the combination of source selection and transfer learning as described in claim 8 is implemented.
