A multi-source heterogeneous cross-project software defect prediction method
Through the multi-source spectral embedding mapping algorithm, the heterogeneous cross-project software defect data is mapped to the same feature space, solving the problem that new projects lack historical data and heterogeneous data is difficult to predict, and achieving high-accurate multi-source heterogeneous cross-project software defect prediction.
Patent Information
- Application Number
- CN202210541022.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-17
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2042-05-17
AI Technical Summary
It is difficult for the prior art to effectively predict software defects for new projects, especially in the absence of sufficient historical defect data, and a lack of effective heterogeneous cross-project software defect prediction model.
The multi-source spectral embedding mapping algorithm is used to map data from different feature spaces to the same feature space, thereby solving the problem of heterogeneous cross-project software defect data unavailable and realizing multi-source heterogeneous cross-project software defect prediction.
By standardizing the defect data of multiple source projects with the defect data of the target projects, sample labeling, class imbalance processing and weight initialization, and using the multi-source spectral embedding mapping algorithm for data mapping and machine learning model training, the accuracy and efficiency of cross-project software defect prediction are significantly improved.
Smart Images

Figure CN114968774B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of heterogeneous cross-project software defect prediction, and more specifically to a multi-source heterogeneous cross-project software defect prediction method. Background Art
[0002] Software defect prediction technology can use the historical data of software defects to configure and manage test resources in a forward-looking manner. By mining and analyzing the historical defect data of the software, a software defect prediction model is constructed to predict the defect tendency of the tested software module, and finally achieve the purpose of optimizing the allocation of test resources and improving the quality of software products. Software defect tendency prediction refers to the prediction model dividing software modules into defect-prone modules or non-defect-prone modules. Assuming that the prediction results of the prediction model have high accuracy, the limited test resources can be tilted towards defect-prone modules based on the prediction results, focusing on and giving priority to testing those defect-prone modules. To predict the defect tendency of equipment software, sufficient historical defect data is required to train the prediction model, and the new prediction data should follow the same distribution as the training data. Usually, this kind of defect prediction is called project-based software defect prediction. However, for a new project, it is difficult to effectively predict project-based software defects because there is no or very little defect data. Through analysis, in actual software development scenarios, software defect prediction mainly faces the following problems:
[0003] Problem 1: The large amount of accumulated defect data cannot provide data support for the newly developed software, and the advantages of historical data are not fully utilized.
[0004] In the past software phase review, testing, and maintenance processes, a large amount of historical data related to software defects has been accumulated. These data can reflect the current level of development of software engineering to a certain extent, and may provide a reference for subsequent software reliability work. At the same time, when a new software is developed, it is impossible to build a defect prediction model that meets the requirements because there is relatively little defect data for the new project. To address this problem, other software defect data can be used to build a defect prediction model, and cross-project software defect prediction methods can be studied. While improving the prediction accuracy, the utilization rate of software defect historical data can also be improved, and abnormalities can be discovered and eliminated in a timely manner.
[0005] Problem 2: There is currently a lack of effective heterogeneous cross-project software defect prediction models.
[0006] The data accumulated from years of software testing makes cross-project software defect prediction possible. At the same time, cross-project software defect prediction plays an important role in improving software development and testing efficiency and rationally allocating software development and testing resources. However, in actual applications, due to the different development processes, programming languages, application fields, and developer experience of different software, the defect characteristics between different projects are heterogeneous, that is, their metrics are often inconsistent; and the data distribution between the source project and the target project is also very different. Therefore, by migrating the relevant knowledge of historical defect data to the target project and constructing a feature space mapping algorithm for heterogeneous data, the software defect prediction problem caused by the different metrics between the source project and the target project can be effectively solved, ensuring and improving the rationality and accuracy of the cross-project software defect prediction method. Summary of the invention
[0007] In view of this, the present invention provides a multi-source heterogeneous cross-project software defect prediction method, which maps data from different feature spaces into the same feature space through a multi-source spectral embedding mapping algorithm, fundamentally solving the problem of unavailability of heterogeneous cross-project software defect data and realizing multi-source heterogeneous cross-project software defect prediction technology.
[0008] In order to achieve the above object, the present invention adopts the following technical solution:
[0009] A multi-source heterogeneous cross-project software defect prediction method, comprising:
[0010] Standardize the original defect data of multiple source projects and the original defect data of target projects;
[0011] Mark the sample labels of the standardized data;
[0012] Perform class imbalance processing on the source project defect data and the target project defect data after sample label processing;
[0013] Initialize the weight of defect data of each source project;
[0014] The defect data of the source project and the defect data of the target project after class imbalance processing are used as the input of the multi-source spectrum embedding mapping algorithm, and the optimal mapping data of the source project and the optimal mapping data of the target project are output;
[0015] According to the sample label marking, the optimal mapping data of the source project and the optimal mapping data of the target project are marked and selected respectively, and the original data of the source project and the original data of the target project are selected;
[0016] Based on the inter-project similarity measurement method, the distance between the original data of each source project and the original data of the target project is measured, and the weight of the defect data of the source project is updated according to the measurement value;
[0017] The optimal mapping data of the source project is used as the input of the machine learning model for training, and the model prediction is performed based on the original data of the target project.
[0018] Preferably, the multi-source spectrum embedding mapping algorithm specifically includes the following steps:
[0019] Initialize the optimal feature space dimension k, and the kernel function is K(x,x);
[0020] Eliminate duplicate samples and samples with missing values in the defective data samples of the source project and the defective data samples of the target project;
[0021] Construct matrix B and symmetric matrix A:
[0022]
[0023] Among them, n is the number of samples of defect data of the source project, and the calculation formula of the sub-matrix in matrix A is as follows:
[0024]
[0025]
[0026]
[0027]
[0028] i,j=1,2,…,n;
[0029] Among them, S i represents the defect data of the i-th source project, T represents the defect data of the target project, and Φ(·) represents a mapping function, and Represent the mapping results on the source data and target data respectively, and Indicates n si ×p space and n T ×q space, K(X,X)=Φ(X)Φ T (X), the weight parameter β is a hyperparameter;
[0030] Calculate the first k eigenvalues of the symmetric matrix A and the corresponding eigenvector V, where k is the number of eigenvalues of the symmetric matrix A greater than 0.001;
[0031] Calculate the optimal projection B Φ(T) and
[0032]
[0033]
[0034] Where l is the number of rows in the matrix V, for example Indicates the first The value of the kth column in the row.
[0035] Preferably, the data is normalized using a z-score or maximum-minimum normalization method.
[0036] Preferably, labeling the standardized data with sample labels specifically includes:
[0037] A column is added to the source project original defect data sample matrix and the target project original defect data sample matrix as a sample label, and the sample label content is 1 and 0, 1 represents the real original data, and 0 represents the non-real generated data.
[0038] Preferably, the class imbalance processing specifically adopts SMOTE oversampling, random undersampling or a method combining oversampling and undersampling.
[0039] Preferably, the weight of each source project defect data is initialized to 1 / n, where n is the number of source project defect data.
[0040] It can be seen from the above technical solution that, compared with the prior art, the present invention discloses a multi-source heterogeneous cross-project software defect prediction method, which fundamentally solves the problem of unavailability of heterogeneous cross-project software defect data and realizes multi-source heterogeneous cross-project software defect prediction technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0042] Figure 1 The accompanying drawing is a flow chart of the multi-source heterogeneous cross-project software defect prediction method provided by the present invention.
[0043] Figure 2 The accompanying drawing shows the sample labeling method provided by the present invention. DETAILED DESCRIPTION
[0044] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0045] The embodiment of the present invention discloses a multi-source heterogeneous cross-project software defect prediction method, such as Figure 1 As shown, including:
[0046] The original defect data of multiple source projects and the original defect data of the target project are normalized; specifically, the z-score or maximum and minimum normalization method is used for data normalization.
[0047] The standardized data is labeled with sample labels; the sample label labeling mainly identifies and distinguishes the original defect data from the generated data. This is because when applying the machine learning model, the test data must be original data, and the present invention needs to oversample the original data before mapping. The original data and the generated data cannot be identified after direct mapping, so a sample label labeling method is needed to identify the original data. Sample label labeling is to add a column as a sample label to the source project defect data sample matrix and the target project defect data sample matrix respectively. Its properties are the same as the failure label of the defect data and are not included in the metric of the defect data. The content of the sample label is 1 and 0, 1 represents the real original data, and 0 represents the non-real generated data. The sample label corresponds to the sample number one by one. In this way, the defect data with a sample label of 1 in the mapped project defect data can be extracted and used as a test set for the cross-project software defect prediction model. The sample label labeling method is as follows: Figure 2 shown.
[0048] The source project defect data and the target project defect data after sample label processing are processed for class imbalance; SMOTE oversampling, random undersampling, or a combination of oversampling and undersampling can be used to process the source project and target project data according to needs. This has two purposes: one is to deal with the class imbalance problem, and the other is to meet the input data requirements of the subsequent multi-source spectrum embedding mapping algorithm MSHeMap.
[0049] Initialize the weight of each source project defect data; specifically, 1 / n, where n is the number of source project defect data.
[0050] The defect data of the source project and the defect data of the target project after class imbalance processing are used as the input of the multi-source spectrum embedding mapping algorithm, and the optimal mapping data of the source project and the optimal mapping data of the target project are output;
[0051] According to the sample label marking, the optimal mapping data of the source project and the optimal mapping data of the target project are marked and selected respectively, and the original data of the source project and the original data of the target project are selected;
[0052] Based on the inter-project similarity measurement method, the distance between the original data of each source project and the original data of the target project is measured, and the weight of the defect data of the source project is updated according to the measurement value; according to the needs, the Euclidean distance, cosine distance, KL divergence, Wasserstein distance and other methods can be used to measure the distance between each source project and the target project, and the weight of the defect data of the source project is updated according to the measurement value.
[0053] The optimal mapping data of the source project is used as the input of the machine learning model for training, and the model is predicted based on the original data of the target project. Specifically, machine learning models such as Logistic regression, SVM, KNN, and Naive Bayes can be used for model training and prediction according to needs.
[0054] Specifically, the core idea of the Multi-Source Spectral Embedding Mapping (MSHeMap) method is to simultaneously map samples of different features in defect data of multiple source items to the same feature space under the premise of minimizing information loss. Its main principles are as follows.
[0055] Given labeled source project defect data and unlabeled target item defect data Among them, n S and n T Represent the number of samples in the source data set and the target data set respectively; Represents the jth sample in the source data set and has a feature dimension of d S ; Indicates that the source data set contains d T The kth sample of a feature; The label of the jth sample in the label source data (where 0 indicates no defect and 1 indicates defect). The purpose of this study is to build a heterogeneous cross-project defect prediction model to predict whether the label of the target data has defects.
[0056] Definition 1: Given the source project defect data S i and the target project defect data T, let Φ(·) represent a mapping function, and Represent the mapping results on the source data and the target data respectively, and further project them on this basis, then the optimal projection and B Φ(T) It can be obtained through the following optimization problem:
[0057]
[0058] Where: L(*,*) represents the distribution difference between the two data sets, express With B Φ(T) The weight parameter β is a hyperparameter. The present invention further defines for:
[0059]
[0060] Assume that when finding the optimal projection, the source data Φ(S i ) and the corresponding mapping matrices of the target data Φ(T) are and P Φ(T) ∈R k×p Then, when searching for the optimal projection, the resulting distribution difference can be measured as follows:
[0061]
[0062] Where: represents the Frobenius norm.
[0063] With the help of the above formula, the optimization objective function can be transformed into the following formula:
[0064]
[0065] In the above formula It has the following properties:
[0066]
[0067] Based on the above formula, and B Φ(T) The closed-form solution of can be obtained by the following theorem.
[0068] Theorem 1: The minimization problem shown in equation (4) is equivalent to the maximization problem shown below:
[0069]
[0070] Where:
[0071]
[0072]
[0073]
[0074]
[0075]
[0076] i, j = 1, 2,…, n.
[0077] Obviously Φ(S i )Φ T (S i ) and Φ(T)Φ T (T) are all symmetric matrices, then A is a symmetric matrix. Therefore, the optimization problem (6) under condition B T There is a closed solution when B=I.
[0078] Theorem 2: (Ky-Fan Theorem) Assume that the eigenvalues of the symmetric matrix A are λ1≥λ2≥…≥λ k , the corresponding eigenvector is V = [v1,…,v k ],but:
[0079]
[0080] Where: X = [v1, v2, ..., v k ]Q, Q is any orthogonal matrix that satisfies matrix multiplication.
[0081] According to Theorem 2, the optimal solution B of the optimization problem (6) is the first k eigenvectors of matrix A.
[0082] Optimal mapping result B Φ(T) and The calculation formula is as follows.
[0083]
[0084]
[0085] where l is the number of rows in the matrix V.
[0086] This example uses software defect data from 6 projects for example verification.
[0087] Table 1 Datasets of six projects
[0088] Project Name Number of metrics Data quantity Number of defective data Project 1 26 312 156(50%) Project 2 26 312 156(50%) Project 3 23 312 156(50%) Project 4 26 312 156(50%) Project 5 26 312 156(50%) Item 6 26 312 156(50%)
[0089] The data of the six projects are mapped to the same feature space using the MSHeMap algorithm.
[0090] Table 2 k values corresponding to different source and target project data
[0091]
[0092] According to previous research results, this example verifies the use of logistic regression classifier (LR) for model training.
[0093] The result B_S obtained by the MSHeMap algorithm is used as the training set of the model, and B_T is used as the test set of the model for instance verification. When predicting cross-project software defects, select a project data sample as the target project and the remaining five projects as source data. Take one of the trainings as an example (project 6 is the target data and project 4 is the source project data).
[0094] In order to evaluate the effect of prediction, its performance evaluation index needs to be calculated. According to the difference between the prediction result and the actual result, there are four situations: the algorithm predicts that the module is defective and the module is actually defective (True Positive, TP); the algorithm predicts that the module is defective and the module is actually non-defective (False Positive, FP); the algorithm predicts that the module is non-defective and the module is actually defective (False Negative, FN); the algorithm predicts that the module is non-defective and the module is actually non-defective (True Negative, TN), as shown in Table 3 below:
[0095] Table 3 Confusion matrix
[0096]
[0097] PD, PF, FM and GM are selected as the performance evaluation indicators for prediction. The specific formula is as follows:
[0098] Recall:
[0099] False alarm rate:
[0100] in,
[0101]
[0102] The model prediction results are shown in Tables 4 to 9, where mean represents the mean value and std represents the standard deviation. Each table is analyzed separately below. Table 4 shows the results of Project 2 to Project 6 as source project data samples and Project 1 as the target project. For PD, Project 6 is the highest at 0.96875, followed by Project 5 at 0.9375; for PF, Project 5 is the best at 0.04487; for FM, Project 5 is the best at 0.869565; for GM, Project 5 is the best at 0.946273. Therefore, based on the comprehensive analysis of the results, for Project 1, Project 5 is the most suitable as the source data for training.
[0103] Table 4 Results of Project 1 for the target project
[0104] Source Project PD PF FM GM Project 2 0.75 0.198718 0.551724 0.775217 Project 3 0.75 0.24359 0.510638 0.753198 Project 4 0.78125 0.25 0.520833 0.765466 Project 5 0.9375 0.044872 0.869565 0.946273 Item 6 0.96875 0.230769 0.626263 0.863245 mean 0.8375 0.19359 0.615805 0.82068 std 0.095607 0.07643 0.133184 0.07383
[0105] Table 5 shows the results of Project 1, Project 3-6 as source project data samples, and Project 2 as target project data. For PD, Project 6 is the highest at 1, followed by Project 5 at 0.941176; for PF, Project 5 is the best at 0.064103; for FM, Project 5 is the best at 0.744186; for GM, Project 5 is the best at 0.938533. Therefore, according to the results analysis, for Project 2, Project 5 is the most suitable as source data for training.
[0106] Table 5 Results of Project 2 for the target project
[0107]
[0108]
[0109] Table 6 shows the results of Project 1, Project 2, Project 4-Project 6 as source project data, and Project 3 as target project data. For PD, Projects 5 and 6 have the highest value of 0.923077; for PF, Project 5 has the best effect of 0.070513; for FM, Project 5 has the best effect of 0.666667; for GM, Project 5 has the best effect of 0.926277. Therefore, according to the analysis of the results, for Project 3, Project 5 is the most suitable as source data for training.
[0110] Table 6 Results of project 3 for the target project
[0111] Source Project PD PF FM GM Project 1 0.615385 0.25641 0.262295 0.676457 Project 2 0.692308 0.179487 0.36 0.753689 Project 4 0.846154 0.230769 0.366667 0.806776 Project 5 0.923077 0.070513 0.666667 0.926277 Item 6 0.923077 0.25 0.375 0.83205 mean 0.8 0.197436 0.406126 0.79905 std 0.124985 0.068969 0.136545 0.082972
[0112] Table 7 shows the results of Project 1-Project 3, Project 5 and Project 6 as source project data, and Project 4 as target project data. For PD, Project 3, 5 and 6 have the highest value of 0.928571; for PF, Project 5 has the best effect of 0.076923; for FM, Project 5 has the best effect of 0.666667; for GM, Project 5 has the best effect of 0.92582. Therefore, according to the analysis of the results, for Project 4, Project 5 is the most suitable as source data for training.
[0113] Table 7 Results of Project 4 as the target project
[0114] Source Project PD PF FM GM Project 1 0.785714 0.224359 0.366667 0.780661 Project 2 0.642857 0.160256 0.375 0.734735 Project 3 0.928571 0.24359 0.4 0.838082 Project 5 0.928571 0.076923 0.666667 0.92582 Item 6 0.928571 0.179487 0.472727 0.872872 mean 0.842857 0.176923 0.456212 0.830434 std 0.114286 0.058273 0.111658 0.067221
[0115] Table 8 shows the results when Items 1 to 4 and 6 are source item data and Item 5 is target item data. For PD, Items 2 and 6 are the highest at 1; for PF, Item 3 is the best at 0.057692; for FM, Item 3 is the best at 0.642857; for GM, Item 2 is the best at 0.954074. Therefore, according to the results analysis, for Item 5, Items 2 and 3 are the most suitable as source data for training.
[0116] Table 8 Results of project 5 for the target project
[0117] Source Project PD PF FM GM Project 1 0.9 0.083333 0.5625 0.908295 Project 2 1 0.089744 0.588235 0.954074 Project 3 0.9 0.057692 0.642857 0.920911 Project 4 0.9 0.083333 0.5625 0.908295 Item 6 1 0.121795 0.512821 0.937126 mean 0.94 0.087179 0.573783 0.92574 std 0.04899 0.020513 0.042311 0.017688
[0118] Table 9 shows the results of project 1 to project 5 as source project data and project 6 as target project data. For PD, project 1, 3, 4 and 5 are the highest 1; for PF, project 5 is 0.064103 and has the best effect; for FM, project 5 is 0.642857 and has the best effect; for GM, project 5 is 0.967418 and has the best effect. Therefore, according to the analysis of the results, for project 6, project 5 is the most suitable as the source data for training.
[0119] Table 9 Results of Project 6 for the target project
[0120] Source Project PD PF FM GM Project 1 1 0.198718 0.367347 0.895144 Project 2 0.777778 0.121795 0.4 0.826467 Project 3 1 0.224359 0.339623 0.880705 Project 4 1 0.153846 0.428571 0.919866 Project 5 1 0.064103 0.642857 0.967418 mean 0.955556 0.152564 0.43568 0.89792 std 0.088889 0.056672 0.107835 0.046306
[0121] In summary, when project 1, project 2, project 3, project 4 and project 6 are used as target projects, the model has the best prediction effect when the source project is project 5. When project 5 is used as the target project, project 2 and project 3 are the most suitable as source data for training. However, it is worth noting that when project 5 is used as the target project, the mean of the results of other projects as source data is higher than that of other projects as target data, which proves that the data quality of project 5 is higher than that of other projects.
[0122] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0123] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A multi-source heterogeneous cross-project software defect prediction method based on spectral embedding mapping, characterized in that: include: Standardize the original defect data of multiple source projects and the original defect data of target projects; Mark the sample labels of the standardized data; Perform class imbalance processing on the source project defect data and the target project defect data after sample label processing; Initialize the weight of defect data of each source project; The defect data of the source project and the defect data of the target project after class imbalance processing are used as the input of the multi-source spectrum embedding mapping algorithm, and the optimal mapping data of the source project and the optimal mapping data of the target project are output; According to the sample label marking, the optimal mapping data of the source project and the optimal mapping data of the target project are marked and selected respectively, and the original data of the source project and the original data of the target project are selected; Based on the inter-project similarity measurement method, the distance between the original data of each source project and the original data of the target project is measured, and the weight of the defect data of the source project is updated according to the measurement value; The optimal mapping data of the source project is used as the input of the machine learning model for training, and the model prediction is performed based on the original data of the target project; The multi-source spectrum embedding mapping algorithm specifically includes the following steps: Initialize the optimal feature space dimension k, and the kernel function is K(x,x); Eliminate duplicate samples and samples with missing values in the defective data samples of the source project and the defective data samples of the target project; Construct matrix B and symmetric matrix A: Among them, n is the number of samples of defect data of the source project, and the calculation formula of the sub-matrix in matrix A is as follows: i,j=1,2,…,n; Among them, S i represents the defect data of the i-th source project, T represents the defect data of the target project, and Φ(·) represents a mapping function, and Represent the mapping results on the source data and target data respectively, and Indicates n si ×p space and n T ×q space, K(X,X)=Φ(X)Φ Τ (X), the weight parameter β is a hyperparameter; Calculate the first k eigenvalues of the symmetric matrix A and the corresponding eigenvector V, where k is the number of eigenvalues of the symmetric matrix A greater than 0.001; Calculate the optimal projection B Φ(T) and where l is the number of rows in the matrix V, Indicates the first The value of the kth column in the row.
2. According to claim 1, a multi-source heterogeneous cross-project software defect prediction method based on spectral embedding mapping is characterized in that: Specifically, the z-score or maximum and minimum standardization methods are used to standardize the data.
3. According to claim 1, a multi-source heterogeneous cross-project software defect prediction method based on spectral embedding mapping is characterized in that: The sample label marking of the standardized data specifically includes: A column is added to the source project original defect data sample matrix and the target project original defect data sample matrix as a sample label. The sample label content is 1 and 0. 1 represents the real original data, and 0 represents the non-real generated data.
4. According to claim 1, a multi-source heterogeneous cross-project software defect prediction method based on spectral embedding mapping is characterized in that: Class imbalance processing specifically adopts SMOTE oversampling, random undersampling or a combination of oversampling and undersampling.
5. According to claim 1, a multi-source heterogeneous cross-project software defect prediction method based on spectral embedding mapping is characterized in that: Initialize the weight of each source project defect data, specifically 1 / n, where n is the number of source project defect data.
6. The multi-source heterogeneous cross-project software defect prediction method based on spectral embedding mapping according to claim 1 is characterized in that: The similarity measurement method between items uses Euclidean distance, cosine distance, KL divergence or Wasserstein distance.
Citation Information
Patent Citations
General data-driven reliability model for software and system and parameter optimizing method
CN102004661A
Heterogeneous cross-project software defect prediction method based on nuclear spectrum mapping migration integration
CN110659207A