A cross-project software defect prediction method and system
The maximum mean difference algorithm measurement and golden segmentation method select similar source project data, and build a cross-project defect prediction model, solving the negative migration problem caused by the data distribution differences in cross-project software defect prediction, and improving defect recognition performance and accuracy.
Patent Information
- Application Number
- CN202210928904.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-03
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2042-08-03
AI Technical Summary
In cross-project software defect prediction, the difference in data distribution between source project data and target project data leads to negative migration problems, and existing methods are difficult to accurately identify data distribution similarity, especially in high-dimensional data.
The maximum mean difference algorithm is used to measure the data distribution similarity between the target project and the source project data, and the golden segmentation method is used to select source project data similar to the target project data distribution to build a cross-project defect prediction model.
It effectively reduces the negative migration impact of source project data on target project data, improves the defect identification performance and accuracy of cross-project defect prediction model, and ensures the quality and reliability of software products.
Smart Images

Figure CN115168237B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software defect prediction, and in particular to a cross-project software defect prediction method and system. Background Art
[0002] Software defect prediction is one of the key technologies in software quality assurance. Its motivation is to discover defects in software through some economical and efficient technologies to ensure the quality and reliability of software products. With the rapid development of information technology, computer software is widely used in many important fields such as Internet communication, education and training, scientific computing, e-commerce, financial investment, smart home, etc. Software technology has penetrated into all aspects of people's lives. However, in the process of software development, software defects are inevitable. Discovering these defects as early as possible and repairing them is extremely important for the later development and maintenance of software. This makes software defect prediction technology have broad application prospects in identifying software product defects.
[0003] Cross-project defect prediction refers to the use of sufficient historical defect data from other software projects (source projects) to build a prediction model and perform defect prediction for the data of the software project to be tested (target project). When the target project is a newly developed software project or lacks historical defect data, cross-project defect prediction can be used. Since there are usually differences between the source project and the target project, resulting in inconsistent data distribution, when performing cross-project prediction modeling, the target project will face the problem of negative migration of the source project data.
[0004] By selecting source projects that are similar to the target project data, the impact of the negative migration of the source project data on the target project data can be effectively reduced. In recent years, researchers have proposed some methods for selecting source data. Some research works select source project data based on the defect prediction performance of the established model. However, this method requires traversing all projects to find the project that produces the best prediction for other projects as the source. In this process, a part of the target data labels are required for model testing, which will limit the application of this method in practice. Another part of the research work uses distance or correlation metrics to select source project data. However, this type of method only measures distance or correlation, ignoring the distribution of the data, and it is difficult to accurately identify the distribution similarity of two data sets, especially in the case of high-dimensional data, the effect of using distance or correlation will be smaller. Summary of the invention
[0005] The present invention proposes a cross-project software defect prediction method and system. The present invention adopts a maximum mean difference algorithm to select source projects by measuring the distribution similarity between source and target project data, and establishes a cross-project defect prediction model based on the selected source projects, so that the constructed model has higher defect recognition performance, which helps to better ensure the quality and reliability of software products.
[0006] The present invention provides a cross-project software defect prediction method, comprising the following steps:
[0007] Normalizing the target project data of the software to be tested and the source project data of multiple different candidate other software respectively;
[0008] The maximum mean difference method is used to measure the similarity of data distribution between the target project data and each source project data;
[0009] According to the similarity of data distribution between the target project data and each source project data, source project data with similar distribution to the target project data is selected;
[0010] Using the classifier algorithm and based on the selected source project data, a cross-project defect prediction model is constructed;
[0011] The target project data of the software to be tested is predicted based on the constructed cross-project defect prediction model to determine whether the target project data has defects.
[0012] Furthermore, the target project data is the actual operation data of the software project to be tested;
[0013] The source project data is historical defect data of other software projects;
[0014] The actual operation data and historical defect data are both software entity data, and the software entity data is an instance module extracted from the software program code.
[0015] Furthermore, the normalization method is the z-score method, and its calculation method is as follows:
[0016]
[0017] Among them, x i is the raw value of the ith metric of software entity x, μ x is the average value of software entity x, σ x is the standard deviation of software entity x, is x i Normalized value.
[0018] Furthermore, the method of using the maximum mean difference method to measure the similarity of data distribution between the target project data and each source project data includes:
[0019] The maximum mean difference method is used to calculate the maximum mean difference value MMD of the data distribution between the target project data and each source project data. The calculation method is as follows:
[0020]
[0021] in, is the i-th software entity in the source project data;
[0022] It is the software entity data set in the source project data;
[0023] n s is the number of software entities in the source project data;
[0024] is the i-th software entity in the target project data;
[0025] is the software entity dataset in the target project data,
[0026] n t is the number of software entities in the target project data;
[0027] represents the regenerated Hilbert space;
[0028] represents a nonlinear mapping function in the reproducing Hilbert space.
[0029] Furthermore, when the maximum mean difference between the target project data and a certain source project data is smaller, the similarity of the data distribution between the target project data and the source project data is higher, and the distribution of the source project data and the target project data is similar.
[0030] Further, selecting source project data having a distribution similar to the target project data according to the similarity of data distribution between the target project data and each source project data includes:
[0031] The calculated maximum mean difference values MMD between the target project data and each source project data are sorted from small to large;
[0032] The golden section method is used to take the source project data corresponding to the first k maximum mean difference values MMD as the source project data with similar distribution to the target project data.
[0033] Furthermore, the method of using the classifier algorithm and the selected source project data to construct a cross-project defect prediction model includes:
[0034] According to the k source project data with similar distribution to the target project data, the classifier algorithm is used to classify the jth source project data S j Build model on h j , 1≤j≤k, and k classifier models are obtained; the classifier algorithm is a logistic regression classifier;
[0035] According to k classifier models, a cross-project defect prediction model is constructed based on multi-source integration method.
[0036] Furthermore, the classifier algorithm also includes: naive Bayes, nearest neighbor, support vector machine, decision tree, random forest, neural network.
[0037] Furthermore, predicting the target project data of the software to be tested based on the constructed cross-project defect prediction model to determine whether the target project data has defects includes:
[0038] Based on the k established classifier models, the target project data to be predicted are predicted respectively to obtain k prediction results;
[0039] The k prediction results are integrated to obtain the final prediction result of the target project data to be predicted, which is expressed as follows:
[0040]
[0041] in is the prediction result obtained by the classifier model corresponding to the j-th source item;
[0042] It is the prediction result of the target project data to be tested obtained by integrating k classifier models.
[0043] The present invention provides a cross-project software defect prediction system, comprising:
[0044] A data processing module, used for normalizing the target project data and multiple different candidate source project data respectively;
[0045] A data similarity measurement module, used to measure the similarity of data distribution between the target project data and each source project data respectively using the maximum mean difference method;
[0046] A similarity data selection module, for selecting source project data having a distribution similar to the target project data according to the similarity of data distribution between the target project data and each source project data;
[0047] A model building module for building a cross-project defect prediction model using a classifier algorithm and selected source project data;
[0048] The data prediction module is used to predict the target project data of the software to be tested based on the constructed cross-project defect prediction model, and determine whether the target project data has defects.
[0049] Compared with the prior art, the present invention has the following beneficial effects:
[0050] The present invention designs a cross-project software defect prediction method from the perspective of the similarity of the distribution of target project data and source project data. In this method, by using the maximum mean difference method, the similarity of the data distribution between the target project data and each source project data is measured respectively, which is conducive to selecting source project data with high data distribution similarity with the target data project, and constructing a cross-project defect prediction model using a classifier algorithm based on the selected source project data with high data distribution similarity with the target project data, so that the constructed cross-project prediction model has high defect recognition performance and high accuracy, which helps to better ensure the quality and reliability of software products. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0052] Figure 1 A flowchart of a cross-project software defect prediction method provided by the present invention;
[0053] Figure 2 A comparison chart of experimental effects of a cross-project software defect prediction method provided by the present invention and a prediction method in the prior art on the Matthews correlation coefficient MCC and the area under the receiver operating characteristic curve AUC evaluation indicators. DETAILED DESCRIPTION
[0054] The technical solutions in the embodiments of the present invention are clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention, but it should be understood that the protection scope of the present invention is not limited by the specific implementation methods.
[0055] Example 1
[0056] like Figure 1 As shown, the present invention provides a cross-project software defect prediction method, comprising the following steps:
[0057] Step S1: normalizing the target project data of the software to be tested and the source project data of multiple different candidate other software respectively.
[0058] The target project data is the actual operation data of the software project to be tested;
[0059] The source project data is the historical defect data of other software projects;
[0060] Actual operation data and historical defect data are both software entity data. Software entity data is an instance module extracted from the software program code, and can also be a method, class, file, package or code change.
[0061] By normalizing the target project data and a plurality of different candidate source project data respectively, the influence of the difference in dimensions between different measurement elements of the software entities of the target project data and the source project data is eliminated.
[0062] The normalization method used is the z-score method, which is calculated as follows:
[0063]
[0064] Among them, x i is the raw value of the ith metric of software entity x, μ x is the average value of software entity x, σ x is the standard deviation of software entity x, is x i Normalized value.
[0065] Step S2: Using the maximum mean difference method, measure the similarity of data distribution between the target project data and each source project data, including:
[0066] The maximum mean difference method is used to calculate the maximum mean difference value MMD of the data distribution between the target project data and each source project data. The calculation method is as follows:
[0067]
[0068] in, is the i-th software entity in the source project data;
[0069] It is the software entity data set in the source project data;
[0070] n s is the number of software entities in the source project data;
[0071] is the i-th software entity in the target project data;
[0072] is the software entity dataset in the target project data,
[0073] n t is the number of software entities in the target project data;
[0074] represents the regenerated Hilbert space;
[0075] represents a nonlinear mapping function in the reproducing Hilbert space.
[0076] The smaller the maximum mean difference between the target project data and a certain source project data, the higher the similarity of the data distribution between the target project data and the source project data, and the distribution of the source project data and the target project data are similar.
[0077] Step S3: According to the similarity of data distribution between the target project data and each source project data, source project data with similar distribution to the target project data is selected, including:
[0078] Sort the calculated maximum mean difference values MMD between the target project data and each source project data from small to large;
[0079] The golden section method is used to take the source project data corresponding to the first k maximum mean difference values MMD as the source project data with similar distribution to the target project data.
[0080] Step S4: Using the classifier algorithm and based on the selected source project data, a cross-project defect prediction model is constructed, including:
[0081] According to the k source project data with similar distribution to the target project data, the classifier algorithm is used to classify the jth source project data S j Build model on h j , 1≤j≤k, and k classifier models are obtained;
[0082] According to k classifier models, a cross-project defect prediction model is constructed based on multi-source integration method.
[0083] The classifier algorithms include: logistic regression, naive Bayes, nearest neighbor, support vector machine, decision tree, random forest, neural network, etc. The classifier algorithm used in the present invention is a logistic regression classifier.
[0084] Step S5: predicting the target project data of the software to be tested according to the constructed cross-project defect prediction model, and determining whether the target project data has defects, including:
[0085] Based on the established k classifier models, the target project data to be predicted are predicted respectively to obtain k prediction results;
[0086] Integrate the k prediction results to obtain the final prediction result of the target project data to be predicted, which can be expressed as:
[0087]
[0088] in is the prediction result obtained by the classifier model corresponding to the j-th source item;
[0089] It is the prediction result of the target project data to be tested obtained by integrating k classifier models.
[0090] Example 2
[0091] The present invention provides a cross-project software defect prediction system, comprising:
[0092] A data processing module, used for normalizing the target project data and multiple different candidate source project data respectively;
[0093] A data similarity measurement module, used to measure the similarity of data distribution between the target project data and each source project data respectively using the maximum mean difference method;
[0094] A similarity data selection module, for selecting source project data having a distribution similar to the target project data according to the similarity of data distribution between the target project data and each source project data;
[0095] A model building module for building a cross-project defect prediction model using a classifier algorithm and selected source project data;
[0096] The data prediction module is used to predict the target project data of the software to be tested based on the constructed cross-project defect prediction model, and determine whether the target project data has defects.
[0097] The technical solution of the present invention is further described in detail below in conjunction with specific implementation methods.
[0098] 1. Experimental environment configuration: windows10 system, matlab2020b.
[0099] 2. Experimental data: This experiment uses 12 public data sets as experimental data. The detailed information is shown in Table 1:
[0100] Table 1 Datasets used in the experiments
[0101]
[0102] 3. Specific implementation process:
[0103] Input: candidate source project data and target project data.
[0104] Output: Whether each software entity in the target project has defects, 1 indicates that the software entity has defects, and 0 indicates that the software entity does not have defects.
[0105] In the first step, the candidate source project data and target project data are normalized using the z-score method;
[0106] In the second step, for a given target project, 90% of the software entities are randomly selected to calculate the MMD distance with each candidate source project, and this is repeated 30 times. Each MMD distance value is recorded, and the average MMD distance value of each candidate source project is calculated as the similarity measure.
[0107] The third step is to sort the calculated MMD distance values in ascending order, use the golden section method to segment from the minimum value, and select the sources corresponding to the first k smallest MMD distance values as the source projects with the most similar data distribution to the target project;
[0108] The fourth step is to build models based on the selected k source projects using logistic regression classifiers to construct a cross-project defect prediction model based on multi-source integration method;
[0109] The fifth step is to predict the target project data based on the constructed model and obtain the prediction results.
[0110] The maximum mean difference method for selecting source project data in the present invention is evaluated using two performance indicators, Matthews correlation coefficient (MCC) and area under the receiver operating characteristic curve (AUC).
[0111] The calculation formula of MCC is as follows:
[0112]
[0113] Among them, the value range of MCC is -1 to 1. The larger the MCC value, the better the algorithm performance;
[0114] TP is the number of software entities that are actually defective that are predicted to be defective;
[0115] FN is the number of software entities that are actually defective but predicted to be defect-free;
[0116] FP is the number of software entities that are actually defect-free but predicted to be defective;
[0117] TN is the number of software entities that are actually defect-free but are predicted to be defect-free, as shown in Table 2.
[0118] Table 2 Confusion matrix
[0119] Predicted to be defective Predicted to be defect-free Actually defective True positive (TP) False negative (FN) Practically defect-free False positive (FP) True negative (TN)
[0120] AUC represents the area under the receiver operating characteristic curve, and its value range is from 0 to 1. The larger the value, the better the algorithm performance. A value of 0.5 indicates the performance of random guessing.
[0121] Under the same experimental environment, the proposed method is compared with the existing source data selection methods of Distributional characteristics based nearest neighbor selection (DCNNS), Virtual classifier (VC) and Correlation (CORR), and the experimental results are compared on 12 software projects in terms of MCC and AUC indicators.
[0122] Figure 2 The MCC and AUC results of all methods on 12 projects are given, and the figure shows the minimum, first quartile, median, third quartile and maximum value. The vertical bar represents the range from the first to the third quartile, the dot represents the median, and the plus sign represents the outlier. It can be seen from the figure that compared with the existing methods, the method of the present invention can obtain better or similar MCC and AUC results, indicating that the method can select appropriate source project data for the target project data, verifying the feasibility and effectiveness of the method.
[0123] 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 cross-project software defect prediction method, characterized in that: The following steps are involved: Normalizing the target project data of the software to be tested and the source project data of multiple different candidate other software respectively; The maximum mean difference method is used to measure the similarity of data distribution between the target project data and each source project data; According to the similarity of data distribution between the target project data and each source project data, source project data with similar distribution to the target project data is selected; Using the classifier algorithm and based on the selected source project data, a cross-project defect prediction model is constructed; Predict the target project data of the software to be tested based on the constructed cross-project defect prediction model to determine whether the target project data has defects; The target project data is the actual operation data of the software project to be tested; The source project data is historical defect data of other software projects; The actual operation data and historical defect data are both software entity data, and the software entity data is an instance module extracted from the software program code; The normalization method is the z-score method, and its calculation method is as follows: Among them, x i is the raw value of the ith metric of software entity x, μ x is the average value of software entity x, σ x is the standard deviation of software entity x, is x i Normalized value; The method of using the maximum mean difference method to measure the similarity of data distribution between the target project data and each source project data includes: The maximum mean difference method is used to calculate the maximum mean difference value MMD of the data distribution between the target project data and each source project data. The calculation method is as follows: in, is the i-th software entity in the source project data; It is the software entity data set in the source project data; n s is the number of software entities in the source project data; is the i-th software entity in the target project data; is the software entity dataset in the target project data, n t is the number of software entities in the target project data; represents the regenerated Hilbert space; represents a nonlinear mapping function in the reproducing Hilbert space.
2. A cross-project software defect prediction method according to claim 1, characterized in that: The smaller the maximum mean difference between the target project data and a certain source project data is, the higher the similarity of the data distribution between the target project data and the source project data is, and the distribution of the source project data and the target project data is similar.
3. A cross-project software defect prediction method according to claim 2, characterized in that: The selecting source project data having a distribution similar to the target project data according to the similarity of data distribution between the target project data and each source project data comprises: The calculated maximum mean difference values MMD between the target project data and each source project data are sorted from small to large; The golden section method is used to take the source project data corresponding to the first k maximum mean difference values MMD as the source project data with similar distribution to the target project data.
4. A cross-project software defect prediction method according to claim 3, characterized in that: The method of using a classifier algorithm and selected source project data to construct a cross-project defect prediction model includes: According to the k source project data with similar distribution to the target project data, the classifier algorithm is used to classify the jth source project data S j Build model on h j , 1≤j≤k, and k classifier models are obtained; the classifier algorithm is a logistic regression classifier; According to k classifier models, a cross-project defect prediction model is constructed based on multi-source integration method.
5. A cross-project software defect prediction method according to claim 4, characterized in that: The classifier algorithms also include: Naive Bayes, Nearest Neighbor, Support Vector Machine, Decision Tree, Random Forest, Neural Network.
6. A cross-project software defect prediction method according to claim 1, characterized in that: The step of predicting the target project data of the software to be tested according to the constructed cross-project defect prediction model to determine whether the target project data has defects includes: Based on the k classifier models established, the target project data to be predicted are predicted respectively to obtain k prediction results; The k prediction results are integrated to obtain the final prediction result of the target project data to be predicted, which is expressed as follows: in is the prediction result obtained by the classifier model corresponding to the j-th source item; It is the prediction result of the target project data to be tested obtained by integrating k classifier models.
7. A system for implementing the cross-project software defect prediction method according to claim 1, characterized in that: include: A data processing module, used for normalizing the target project data and multiple different candidate source project data respectively; A data similarity measurement module, used to measure the similarity of data distribution between the target project data and each source project data respectively using the maximum mean difference method; A similarity data selection module, for selecting source project data having a distribution similar to the target project data according to the similarity of data distribution between the target project data and each source project data; A model building module for building a cross-project defect prediction model using a classifier algorithm and selected source project data; The data prediction module is used to predict the target project data of the software to be tested based on the constructed cross-project defect prediction model, and determine whether the target project data has defects.
Citation Information
Patent Citations
Workload perception instant software defect prediction method based on linear programming
CN115033493A