A software defect prediction method based on sampling algorithm optimization and unsupervised clustering

By combining improved T-ADASYN oversampling and Z-Score normalization techniques with the Spectral Clustering unsupervised clustering model, the problem of data class imbalance in unsupervised software defect prediction is solved, achieving fast and accurate defect prediction and improving clustering effect and prediction accuracy.

CN116628526BActive Publication Date: 2026-05-15JIANGXI NORMAL UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310740101.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-21
Publication Date
2026-05-15
Estimated Expiration
2043-06-21

AI Technical Summary

Technical Problem

Existing unsupervised software defect prediction methods suffer from poor clustering performance when faced with imbalanced data classes. This results in insufficient minority class samples, failing to meet the connectivity and Euclidean distance requirements of clustering algorithms and affecting prediction accuracy.

Method used

An improved T-ADASYN oversampling algorithm is used to generate a balanced dataset. Combined with Z-Score normalization and Spectral Clustering unsupervised clustering model, an unsupervised clustering model is constructed through dataset oversampling and normalization. Heuristic methods are used to identify categories, and the F-Score evaluation metric is used to measure prediction accuracy.

Benefits of technology

It enables rapid and accurate prediction of whether software projects contain defects, improves the accuracy of clustering results and sampling effect, and enhances the efficiency of software defect prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116628526B_ABST
    Figure CN116628526B_ABST
Patent Text Reader

Abstract

The application relates to a software defect prediction method based on a sampling algorithm optimization and unsupervised clustering, which comprises the following steps: 1) data set oversampling: according to original data set category proportion information and a set balance coefficient, the data amount required to be generated by the minority class samples is calculated and generated, and a balanced data set is obtained; 2) data set standardization: the balanced data set is subjected to standardization processing, and a standard data set is obtained; 3) unsupervised clustering: a clustering model is constructed, the standard data set is input into the clustering model for clustering operation, and the standard data set is divided into two categories; 4) clustering result confirmation: the two categories divided by clustering are subjected to confirmation category processing, and whether the software represented by the data has defects is judged; and 5) prediction evaluation index: a model evaluation index is constructed, model evaluation index information is acquired, and the accuracy of software defect prediction is measured. The method process design is reasonable, convenient to use, and compared with traditional algorithms, has the advantages that sampling effect is better and clustering result is more accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of machine learning and software defect prediction technology, specifically, a software defect prediction method based on sampling algorithm optimization and unsupervised clustering. Background Technology

[0002] Since the beginning of the 21st century, information technology has developed rapidly, and people have developed a large number of software programs to facilitate our work and lives. As people become increasingly reliant on software systems, developing high-quality software has become increasingly important, and the number of software defects directly determines the quality of a software system and the user experience. A large number of software defects not only drastically reduce user satisfaction but also create significant human and financial pressure on developers in the later stages.

[0003] Researching automated methods for software defects, such as defect prediction, detection, location, debugging, and repair, and developing corresponding automated processes, has significant application value, but also presents numerous research challenges. Software defect prediction is the first step in software defect repair. Before software release, it uses historical data, metrics, and known defects to predict potential defects that may still exist in the software, thereby narrowing the testing scope, allowing developers to focus on fixing defects, and improving software development efficiency.

[0004] In recent years, software defect prediction has received widespread attention and importance. Existing research on software defect prediction can be categorized into three types based on the classification algorithms: supervised, semi-supervised, and unsupervised. Unsupervised methods are widely used because they do not require labeled initial data. However, few researchers have considered the impact of data class imbalance on the model in unsupervised software defect prediction. In common software defect prediction datasets, the number of defective items often represents only a small fraction of the total. This leads to insufficient minority class samples during clustering, causing the connectivity and Euclidean distance between software entities to fail to meet the requirements of various clustering algorithms, resulting in clustering results that do not meet expectations. Summary of the Invention

[0005] The purpose of this invention is to address the shortcomings of existing technologies by providing a software defect prediction method based on sampling algorithm optimization and unsupervised clustering. This method can perform clustering operations based on the metric information of software project entities, thereby quickly and accurately predicting whether they contain software defects.

[0006] To achieve the above objectives, this invention provides a software defect prediction method based on sampling algorithm optimization and unsupervised clustering, comprising the following steps:

[0007] Step S1. Dataset oversampling: Based on the data class ratio information in the original dataset and the set balance coefficient, the improved T-ADASYN oversampling algorithm is used to calculate and generate the amount of data that needs to be generated for the minority class samples, thus obtaining a balanced dataset;

[0008] Step S2. Dataset Standardization: The balanced dataset generated in Step S1 is standardized using Z-Score standardization to obtain a standard dataset;

[0009] Step S3. Unsupervised clustering: Construct an unsupervised Spectral Clustering model. Input the standard dataset obtained in step S2 into the clustering model. The clustering model performs clustering operations on the input dataset, thereby dividing the standard dataset into two classes.

[0010] Step S4. Clustering result confirmation: Using heuristic methods, the two clusters are confirmed to determine whether the software represented by the data has defects.

[0011] Step S5. Prediction Evaluation Indicators: Construct model evaluation indicators, obtain model evaluation indicator information, and use them to measure the accuracy of software defect prediction during optimization and testing.

[0012] Specifically, in step S1, the minority class samples are first found based on the Euclidean distance. Find the k nearest neighbors, then randomly select one of the k neighbors to generate new data, and then find the nearest neighbor to the minority class sample based on Euclidean distance. For k points at medium distances, new data is generated by randomly selecting one point from the k points. The original data and the newly generated data are then combined to obtain a balanced dataset. The steps are as follows:

[0013] Step S11. Based on the input raw dataset and the set balance coefficients... Calculate the number of samples G that need to be generated for each sample;

[0014] (1);

[0015] in, For the majority class sample size, For the minority class sample size, ,like If the value is 1, then the ratio of positive to negative samples after sampling is 1:1;

[0016] Step S12. For each minority class sample Its value is calculated using Euclidean distance. One neighbor; record the sample of The majority class sample proportion among the neighbors is ,but

[0017] (2);

[0018] in, for The number of samples belonging to the majority class among the neighbors:

[0019] Step S13. For Standardization is performed to obtain each weight ;

[0020] (3);

[0021] Step S14. Calculate each minority class sample Number of synthesized samples required ;

[0022] (4);

[0023] Step S15. Based on each minority class sample The quantity to be synthesized First, generate the nearest neighbor samples. ;

[0024] (5);

[0025] in, It is a synthetic sample. It is the first in the minority class One sample, From of A minority class sample randomly selected from the nearest neighbor samples. Random numbers;

[0026] Step S16. Generate minority class samples Medium-distance samples ;

[0027] (6);

[0028] in, It is a synthetic sample. It is the first in the minority class One sample, From of A minority class sample randomly selected from the intermediate neighbor samples. Random numbers;

[0029] Step S17: Combine the original data and the newly generated data to obtain the balanced dataset D. 、 :

[0030] D 、 =D+N+M (7;

[0031] Where N is the set of nearest neighbors generated from all minority class samples, and M is the set of intermediate neighbors generated from all minority class samples.

[0032] In step S2, the oversampled balanced dataset will be standardized before clustering. The Z-Score standardization algorithm will be used to standardize all data to the range [0-1], resulting in a standard balanced dataset. The specific process is as follows:

[0033] use Represents the first of all software entities within the project. The value of a metric, , Indicates the first The first software entity Given a metric value, where n is the number of software entities within the project, then we have:

[0034] (8);

[0035] in, yes The mean, yes Standard deviation;

[0036] The standardized data conforms to a standard normal distribution with a mean of 0 and a standard deviation of 1.

[0037] Specifically, the process of dividing the standard dataset into two categories in step S3 is as follows:

[0038] Step S31. Build the Spectral Clustering unsupervised clustering model and set the number of cluster output categories;

[0039] Step S32. Select the Spectral Clustering unsupervised clustering model, and the clustering output is 2 classes:

[0040] 1) Construct a weighted adjacency matrix of the weighted graph of software entities. Sum-degree matrix :

[0041] (9);

[0042] (10);

[0043] in, , Representing software entities and The metric vector, Indicates the first The first software entity One metric value;

[0044] 2) According to and Calculate the Laplace matrix :

[0045] (11);

[0046] 3) For the Laplace matrix Eigenvalues ​​are obtained by performing eigenvalue decomposition. ;

[0047] 4) Select The second smallest eigenvector Using 0 as the threshold Divide into two categories:

[0048] (12);

[0049] 5) Finally, output the result array T containing only the two categories 0 and 1.

[0050] In step S4, the clustering is divided into two classes. The average software metric of all entities in each class is calculated. The class with the larger average is marked as defective, and the other class is marked as defect-free. Specifically:

[0051] For the two categories 0 and 1, calculate the total sum of the software entity metrics in categories 0 and 1 respectively. Then divide the sum by the number of software entities in each category to obtain the average entity value for the two categories. According to the heuristic method, defective entities usually have larger values ​​than non-defective entities. Therefore, the category with the larger average entity value is defective, and the other category is non-defective.

[0052] In step S5, model evaluation metrics are constructed and information on these metrics is obtained. The F-Score is then used as the evaluation metric to measure the accuracy of software defect prediction during optimization and testing.

[0053] F-Score (13);

[0054] Wherein, TP represents the number of defect-free samples predicted as defect-free; FP represents the number of defective samples predicted as defect-free; and FN represents the number of defect-free samples predicted as defective.

[0055] On the other hand, the present invention also provides a prediction system based on the above-mentioned software defect prediction method, including a data oversampling module, a data standardization module, an unsupervised clustering module, a clustering result confirmation module, and a model evaluation module;

[0056] The data oversampling module is used to calculate the amount of data to be generated for minority class samples based on the data category ratio information in the original dataset and the pre-set balance coefficient, and then generate and output a balanced dataset.

[0057] The data standardization module is used to standardize the balanced dataset generated by the data oversampling module and output a standard dataset.

[0058] The unsupervised clustering module is used to perform clustering operations on the standard dataset output by the data standardization module, thereby dividing the standard dataset into two classes.

[0059] The clustering result confirmation module is used to confirm the two categories into which the clusters are divided and to determine whether the software represented by the data has any defects.

[0060] The model evaluation module is used to measure the accuracy of software defect prediction based on built-in evaluation metrics.

[0061] Compared with the prior art, the beneficial effects of the present invention are:

[0062] 1. This invention constructs a software defect prediction system based on oversampling and unsupervised clustering, which can perform clustering operations based on the measurement information of software project entities, thereby quickly and accurately predicting whether they contain software defects.

[0063] 2. This invention provides a software defect prediction method based on oversampling and unsupervised clustering. It involves oversampling the original software entity metric dataset using the T-ADASYN oversampling algorithm to obtain a class-balanced dataset, standardizing the balanced dataset using the Z-Score algorithm, performing binary partitioning of the dataset using the Spectral Clustering unsupervised clustering model, confirming the clustering categories, and evaluating the prediction results. Compared with traditional algorithms, this model method has the advantages of better sampling performance and more accurate clustering results. Attached Figure Description

[0064] Figure 1 This is a flowchart of the software defect prediction method based on oversampling and unsupervised clustering of the present invention;

[0065] Figure 2 This is a diagram showing the architecture of the software defect prediction system based on oversampling and unsupervised clustering, as presented in this invention. Detailed Implementation

[0066] The present invention will now be described in detail with reference to specific embodiments. These embodiments will help those skilled in the art to further understand the present invention, but do not limit the invention in any way. It should be noted that those skilled in the art can make several changes and improvements without departing from the concept of the present invention. These all fall within the scope of protection of the present invention.

[0067] like Figure 1 As shown, this invention provides a software defect prediction method based on sampling algorithm optimization and unsupervised clustering, comprising the following steps:

[0068] Step S1. Dataset oversampling: Based on the data class ratio information in the original dataset and the set balance coefficient, the improved T-ADASYN oversampling algorithm is used to calculate and generate the amount of data that needs to be generated for the minority class samples, thus obtaining a balanced dataset;

[0069] Step S2. Dataset Standardization: The balanced dataset generated in Step S1 is standardized using Z-Score standardization to obtain a standard dataset;

[0070] Step S3. Unsupervised clustering: Construct an unsupervised Spectral Clustering model. Input the standard dataset obtained in step S2 into the clustering model. The clustering model performs clustering operations on the input dataset, thereby dividing the standard dataset into two classes.

[0071] Step S4. Clustering result confirmation: Using heuristic methods, the two clusters are confirmed to determine whether the software represented by the data has defects.

[0072] Step S5. Prediction Evaluation Indicators: Construct model evaluation indicators, obtain model evaluation indicator information, and use them to measure the accuracy of software defect prediction during optimization and testing.

[0073] like Figure 2 As shown, this embodiment also provides a prediction system based on the above software defect prediction method, including a data oversampling module, a data standardization module, an unsupervised clustering module, a clustering result confirmation module, and a model evaluation module;

[0074] The data oversampling module is used to calculate the amount of data to be generated for minority class samples based on the data category ratio information in the original dataset and the pre-set balance coefficient, and then generate and output a balanced dataset.

[0075] The data standardization module is used to standardize the balanced dataset generated by the data oversampling module and output a standard dataset.

[0076] The unsupervised clustering module is used to perform clustering operations on the standard dataset output by the data standardization module, thereby dividing the standard dataset into two classes.

[0077] The clustering result confirmation module is used to confirm the two categories into which the clusters are divided and to determine whether the software represented by the data has any defects.

[0078] The model evaluation module is used to measure the accuracy of software defect prediction based on built-in evaluation metrics.

[0079] Example 1

[0080] A software defect prediction method based on sampling algorithm optimization and unsupervised clustering includes the following steps:

[0081] Step S1. Dataset oversampling: Based on the data class ratio information in the original dataset and the set balance coefficient, the improved T-ADASYN oversampling algorithm is used to calculate and generate the amount of data that needs to be generated for the minority class samples, thus obtaining a balanced dataset;

[0082] Step S11. Based on the input raw dataset and the set balance coefficients... Calculate the number of samples G that need to be generated for each sample;

[0083] (1);

[0084] in, For the majority class sample size, For the minority class sample size, ,like If the value is 1, then the ratio of positive to negative samples after sampling is 1:1;

[0085] Step S12. For each minority class sample Its Euclidean distance is calculated One neighbor; record the sample of The majority class sample proportion among the neighbors is ,but

[0086] (2);

[0087] in, for The number of samples belonging to the majority class among the neighbors:

[0088] Step S13. For Standardization is performed to obtain each weight ;

[0089] (3);

[0090] Step S14. Calculate each minority class sample Number of synthesized samples required ;

[0091] (4);

[0092] Step S15. Based on each minority class sample The quantity to be synthesized First, generate the nearest neighbor samples. ;

[0093] (5);

[0094] in, It is a synthetic sample. It is the first in the minority class One sample, From of A minority class sample randomly selected from the nearest neighbor samples. Random numbers;

[0095] Step S16. Generate minority class samples Medium-distance samples ;

[0096] (6);

[0097] in, It is a synthetic sample. It is the first in the minority class One sample, From of A minority class sample randomly selected from the intermediate neighbor samples. Random numbers;

[0098] Step S17: Combine the original data and the newly generated data to obtain the balanced dataset D. 、 :

[0099] D 、 =D+N+M (7)

[0100] Where N is the set of nearest neighbors generated from all minority class samples, and M is the set of intermediate neighbors generated from all minority class samples.

[0101] Step S2. Dataset Standardization: The balanced dataset generated in Step S1 is standardized using Z-Score standardization to obtain a standard dataset;

[0102] use Represents the first of all software entities within the project. The value of a metric, , Indicates the first The first software entity Given a metric value, where n is the number of software entities within the project, then we have:

[0103] (8);

[0104] in, yes The mean, yes Standard deviation;

[0105] The standardized data conforms to a standard normal distribution with a mean of 0 and a standard deviation of 1.

[0106] Step S3. Unsupervised clustering: Construct an unsupervised Spectral Clustering model. Input the standard dataset obtained in step S2 into the clustering model. The clustering model performs clustering operations on the input dataset, thereby dividing the standard dataset into two classes.

[0107] Step S31. Build the Spectral Clustering unsupervised clustering model and set the number of cluster output categories;

[0108] Step S32. Select the Spectral Clustering unsupervised clustering model, and the clustering output is 2 classes:

[0109] 1) Construct a weighted adjacency matrix of the weighted graph of software entities. Sum-degree matrix :

[0110] (9);

[0111] (10);

[0112] in, , Representing software entities and The metric vector, Indicates the first The first software entity One metric value;

[0113] 2) According to and Calculate the Laplace matrix :

[0114] (11);

[0115] 3) For the Laplace matrix Eigenvalues ​​are obtained by performing eigenvalue decomposition. ;

[0116] 4) Select The second smallest eigenvector Using 0 as the threshold Divide into two categories:

[0117] (12);

[0118] 5) Finally, output the result array T containing only the two categories 0 and 1.

[0119] Step S4. Clustering result confirmation: Using heuristic methods, the two clusters are confirmed to determine whether the software represented by the data has defects.

[0120] For the two categories 0 and 1, calculate the total sum of the software entity metrics in categories 0 and 1 respectively. Then divide the sum by the number of software entities in each category to obtain the average entity value for the two categories. According to the heuristic method, defective entities usually have larger values ​​than non-defective entities. Therefore, the category with the larger average entity value is defective, and the other category is non-defective.

[0121] Step S5. Predictive Evaluation Indicators: Construct model evaluation indicators, obtain model evaluation indicator information, and use them to measure the accuracy of software defect prediction during optimization and testing;

[0122] By constructing model evaluation metrics and obtaining model evaluation metric information, the F-Score is used as an evaluation metric to measure the accuracy of software defect prediction during optimization and testing.

[0123] F-Score (13);

[0124] Wherein, TP represents the number of defect-free samples predicted as defect-free; FP represents the number of defective samples predicted as defect-free; and FN represents the number of defect-free samples predicted as defective.

[0125] The preferred implementation of the present invention has been described in detail above, but the present invention is not limited to the described embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.

Claims

1. A software defect prediction method based on sampling algorithm optimization and unsupervised clustering, characterized in that, Includes the following steps: Step S1. Dataset oversampling: Based on the data class ratio information in the original dataset and the set balance coefficient, the improved T-ADASYN oversampling algorithm is used to calculate and generate the amount of data that needs to be generated for the minority class samples, thus obtaining a balanced dataset; Step S11. Based on the input original dataset D and the set balance coefficients... Calculate the number of samples G that need to be generated for each sample; (1); in, For the majority class sample size, For the minority class sample size, ,like If the value is 1, then the ratio of positive to negative samples after sampling is 1:1; Step S12. For each minority class sample Its Euclidean distance is calculated One neighbor; record the sample of The majority class sample proportion among the neighbors is ,but (2); in, for The number of samples belonging to the majority class among the neighbors: Step S13. For Standardization is performed to obtain each weight ; (3); Step S14. Calculate each minority class sample Number of samples needed for synthesis ; (4); Step S15. Based on each minority class sample Quantity to be synthesized First, generate the nearest neighbor samples. ; (5); in, It is a synthetic sample. It is the first in the minority class One sample, From of A minority class sample randomly selected from the nearest neighbor samples. Random numbers; Step S16. Generate minority class samples Medium-distance samples ; (6); in, It is a synthetic sample. It is the first in the minority class One sample, From of A minority class sample randomly selected from the intermediate neighbor samples. Random numbers; Step S17: Combine the original data and the newly generated data to obtain the balanced dataset D. 、 : D 、 =D+N+M (7); Where N is the set of nearest neighbors generated from all minority class samples, and M is the set of intermediate neighbors generated from all minority class samples; Step S2. Dataset Standardization: The balanced dataset generated in Step S1 is standardized using Z-Score standardization to obtain a standard dataset; Step S3. Unsupervised clustering: Construct an unsupervised Spectral Clustering model. Input the standard dataset obtained in step S2 into the clustering model. The clustering model performs clustering operations on the input dataset, thereby dividing the standard dataset into two classes. Step S4. Clustering result confirmation: Using heuristic methods, the two clusters are confirmed to determine whether the software represented by the data has defects. Step S5. Prediction Evaluation Indicators: Construct model evaluation indicators, obtain model evaluation indicator information, and use them to measure the accuracy of software defect prediction during optimization and testing.

2. The software defect prediction method based on sampling algorithm optimization and unsupervised clustering according to claim 1, characterized in that, In step S2, the oversampled balanced dataset will be standardized before clustering. The Z-Score standardization algorithm will be used to standardize all data to the range [0-1], resulting in a standard balanced dataset. The specific process is as follows: use Represents the first of all software entities within the project. The value of a metric, , Indicates the first The first software entity Given a metric value, where n is the number of software entities within the project, then we have: (8); in, yes The mean, yes Standard deviation; The standardized data conforms to a standard normal distribution with a mean of 0 and a standard deviation of 1.

3. The software defect prediction method based on sampling algorithm optimization and unsupervised clustering according to claim 1, characterized in that, In step S4, the clustering is divided into two classes. The average software metric of all entities in each class is calculated. The class with the larger average is marked as defective, and the other class is marked as defect-free. Specifically: For the two categories 0 and 1, calculate the total sum of the software entity metrics in categories 0 and 1 respectively. Then divide the sum by the number of software entities in each category to obtain the average entity value for the two categories. According to the heuristic method, defective entities usually have larger values ​​than non-defective entities. Therefore, the category with the larger average entity value is defective, and the other category is non-defective.

4. The software defect prediction method based on sampling algorithm optimization and unsupervised clustering according to claim 1, characterized in that, In step S5, model evaluation metrics are constructed and information on these metrics is obtained. The F-Score is then used as the evaluation metric to measure the accuracy of software defect prediction during optimization and testing. F-Score (13); Wherein, TP represents the number of defect-free samples predicted as defect-free; FP represents the number of defective samples predicted as defect-free; and FN represents the number of defect-free samples predicted as defective.

5. A prediction system employing the software defect prediction method as described in any one of claims 1-4, characterized in that, It includes a data oversampling module, a data standardization module, an unsupervised clustering module, a clustering result confirmation module, and a model evaluation module; The data oversampling module is used to calculate the amount of data to be generated for minority class samples based on the data category ratio information in the original dataset and the pre-set balance coefficient, and then generate and output a balanced dataset. The data standardization module is used to standardize the balanced dataset generated by the data oversampling module and output a standard dataset. The unsupervised clustering module is used to perform clustering operations on the standard dataset output by the data standardization module, thereby dividing the standard dataset into two classes. The clustering result confirmation module is used to confirm the two categories into which the clusters are divided and to determine whether the software represented by the data has any defects. The model evaluation module is used to measure the accuracy of software defect prediction based on built-in evaluation metrics.