Adaptive border density weighted oversampling and software defect prediction method

By using an adaptive boundary density-weighted oversampling method, the problems of insufficient diversity and class overlap in synthetic samples are solved, generating more diverse synthetic samples and improving the accuracy and reliability of the software defect prediction model, especially performing well on extremely imbalanced datasets.

CN122195800APending Publication Date: 2026-06-12HANGZHOU DIANZI UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU DIANZI UNIV
Filing Date
2026-03-17
Publication Date
2026-06-12

AI Technical Summary

Technical Problem

Existing oversampling methods cannot simultaneously address the risks of insufficient diversity in synthetic samples and class overlap, resulting in insufficient accuracy and reliability of software defect prediction models.

Method used

An adaptive boundary density-weighted oversampling method is adopted to evaluate the importance of defective samples by fusing boundary factors and density factors in two dimensions. The number and method of synthesized samples are dynamically adjusted, and a dual-center overlap control mechanism is constructed to mitigate the risk of class overlap and generate more diverse synthesized samples.

Benefits of technology

It significantly improves the accuracy and reliability of software defect prediction models, especially demonstrating high predictive power under extremely imbalanced datasets, improving the F1 score, and enhancing the model's adaptability and robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122195800A_ABST
    Figure CN122195800A_ABST
Patent Text Reader

Abstract

The application discloses a method for oversampling and software defect prediction based on adaptive boundary density weighting. First, according to the proportion of non-defect samples in the k-nearest neighbors of each defect sample in the original software defect prediction data and the average Euclidean distance between the defect sample and the k-nearest neighbor defect sample, a weight is assigned to the defect sample, then the number of synthetic samples of each defect sample is allocated according to the weight, and the generated resources are tilted to the difficult-to-classify samples. Then, the defect samples are divided into high and low density regions according to the median of the density factor, the interpolation coefficient range of the two types of regions is dynamically adjusted to ensure the diversity of the synthetic samples; then a double reference system of defect center and non-defect center is constructed, the overlap risk is determined combined with the adaptive threshold of boundary perception, and the risk samples are adjusted in a specific direction, finally, the model is trained using the oversampled data set, which improves the accuracy of software defect prediction, and has high robustness in extreme imbalance, different dimensions and other scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the fields of software engineering and machine learning technology, and relates to preprocessing technology for software defect prediction data with both class imbalance and class overlap. Specifically, it relates to an oversampling and software defect prediction method based on adaptive boundary density weighting. Background Technology

[0002] The core objective of Software Defect Prediction (SDP) is to identify defect-prone modules in a software system, helping developers allocate limited testing resources more effectively, shorten testing cycles, and reduce development costs. In recent years, machine learning methods, with their powerful pattern recognition capabilities, have become the mainstream technology for building SDP models. By learning the association between features and labels in historical defect data, they can predict the defect risk of new modules. However, SDP datasets generally suffer from a significant imbalance between the number of non-defect samples and defect samples, resulting in a severe imbalance between the majority and minority classes. Traditional machine learning methods, which optimize overall accuracy, are inherently biased towards the majority class, easily misclassifying defect samples as non-defect samples, severely impacting the model's practical application value.

[0003] To address the class imbalance problem, researchers have proposed three core strategies: cost-sensitive methods, ensemble methods, and data-level methods. Cost-sensitive methods incentivize defective samples by imposing a higher misclassification cost, guiding the model to focus on the minority class. Ensemble methods improve the stability of defect identification by combining multiple strategies to build a composite model. Data-level methods adapt traditional classifiers by rebalancing the dataset distribution without modifying the model structure, offering good versatility and ease of use. These methods include undersampling (removing non-defective samples) and oversampling (synthesizing defective samples). Oversampling methods, which preserve the original data information and avoid the loss of key features caused by undersampling, have become a more advantageous solution.

[0004] The core idea of ​​oversampling methods is to generate defect samples containing effective feature information, providing the model with more sufficient basis for minority class learning. However, existing oversampling methods cannot simultaneously solve the two core problems of insufficient diversity of synthetic samples and class overlap. On the one hand, most methods use fixed interpolation rules, lacking adaptability to the local data distribution of defect samples. This leads to the generation of redundant samples in high-density areas of defect samples, causing overfitting, while in low-density areas of defect samples, it is difficult to fully explore the feature space, resulting in insufficient diversity of synthetic samples and failing to provide the model with comprehensive learning basis. On the other hand, most methods lack effective overlap risk control mechanisms, and synthetic samples are prone to falling into overlapping areas where non-defect samples are located, further blurring class boundaries and reducing the model's classification accuracy.

[0005] Therefore, there is an urgent need for an oversampling technique that can simultaneously improve the diversity of synthetic samples and effectively mitigate the risk of class overlap, so as to overcome the limitations of existing methods and improve the accuracy and reliability of software defect prediction. Summary of the Invention

[0006] To address the shortcomings of existing technologies, this invention proposes an oversampling and software defect prediction method based on adaptive boundary density weighting. By fusing boundary factors and density factors from two dimensions, the method comprehensively quantifies the difficulty in classifying defective samples and allocates synthesis slots accordingly, ensuring that generation resources are tilted towards samples that are difficult to classify. Simultaneously, by constructing a collaborative mechanism of density adaptive interpolation and dual-center overlap control, the method dynamically adjusts the number and synthesis method of synthesized samples in different regions, increasing the diversity of synthesized samples. Furthermore, dual-center overlap control identifies samples with class overlap risks and makes targeted adjustments, effectively mitigating class overlap and achieving a dual optimization of increased diversity and reduced class overlap.

[0007] The software defect prediction oversampling method based on adaptive boundary density weighting includes the following steps:

[0008] Step 1: For the original software defect dataset with imbalanced class distribution, extract sample features and labels.

[0009] Step 2: For each defective sample, calculate the proportion of non-defective samples in its k nearest neighbors as the boundary factor B(i), calculate the average Euclidean distance between it and the k nearest neighbor defective samples as the density factor D(i), and fuse the boundary factor B(i) and the density factor D(i) through a nonlinear fusion strategy. After normalization, the importance weight W(i) of the defective sample is obtained.

[0010] Step 3: Allocate the number of synthetic samples to each defective sample based on the importance weight W(i) to ensure that the number of generated samples matches the importance of the samples.

[0011] Step 4: Using the median density factor of the defect samples as the boundary, divide the defect samples into high-density and low-density regions. Adaptively adjust the interpolation coefficient range based on the distribution characteristics of the two types of regions, assigning smaller interpolation coefficients to defect samples in high-density regions and larger interpolation coefficients to defect samples in low-density regions. Then, based on the interpolation coefficients, generate initial synthetic samples through linear interpolation, adapting the synthesis process to the data characteristics of each region and achieving diversity in the initial synthetic samples.

[0012] Step 5: Set the boundary-aware fuzzy coefficients based on the boundary factors of the defect samples. Construct a dual-center reference system, using the feature mean of the k nearest neighbor defect samples of the defect sample as the defect center and the feature mean of the k non-defect nearest neighbors as the non-defect center. Calculate the Euclidean distance from the initial synthetic sample to the two centers respectively, and determine the overlap risk by combining the boundary-aware fuzzy coefficients. Adjust the risk samples along the direction of the defect center.

[0013] Step 6: Repeat steps 4 and 5. For each defect sample, generate a synthetic sample according to the allocated number of synthetic samples. Merge the final synthetic sample with the original dataset to obtain a class-balanced dataset, thus completing the oversampling of the software defect prediction dataset.

[0014] The software defect prediction method based on adaptive boundary density weighted oversampling is used to oversample defect samples in the original software defect dataset with imbalanced class distribution. The resulting balanced class dataset is used as the training set to train the defect prediction model, which is then used to output the defect prediction results of unknown software modules.

[0015] Compared with the prior art, the present invention has the following beneficial effects:

[0016] 1. By fusing boundary factors and density factors, the weight of defective samples is evaluated, and the difficulty of classifying defective samples is comprehensively quantified. The number of generation of each defective sample is allocated according to the weight. The weight is positively correlated with the learning difficulty. The higher the weight, the more synthesis slots are allocated to the sample, ensuring that generation resources are tilted towards difficult-to-classify samples.

[0017] 2. Using a density-adaptive interpolation mechanism, the density factor, in addition to participating in the calculation of sample importance weights and determining the allocation of the number of generated samples, is also used to divide defective samples into high-density and low-density regions, dynamically adjusting the range of interpolation coefficients for the two types of regions. This results in fewer samples being generated in high-density regions and limiting the generation range to avoid redundancy, while more samples are generated in low-density regions and allow for moderate extrapolation to expand the feature space, thereby increasing the diversity of synthetic samples.

[0018] 3. Construct a dual reference system of defect centers and non-defect centers, combine it with boundary-aware adaptive thresholds to accurately determine overlapping risks, and orient risk samples along the direction of defect centers to make risk samples move away from non-defect centers and closer to defect centers to clarify classification boundaries, thereby alleviating category overlap. Attached Figure Description

[0019] Figure 1 The flowchart shows the software defect prediction oversampling method based on adaptive boundary density weighted oversampling.

[0020] Figure 2 This is a schematic diagram of density adaptive interpolation.

[0021] Figure 3 This is a schematic diagram of dual-center overlap control. Detailed Implementation

[0022] The present invention will be further explained below with reference to the accompanying drawings;

[0023] like Figure 1 As shown, the software defect prediction oversampling method based on adaptive boundary density weighting achieves reasonable oversampling of the software defect dataset through a process of two-factor sample weight evaluation, density adaptive sample generation, and dual-center overlap control. Specifically, it includes the following steps:

[0024] Step 1: This embodiment uses the ant-1.3, camel-1.6, EQ, ivy-2.0, JDT, Lucene, Mylyn, PDE, tomcat, and xalan-2.4 datasets as the original data sources, covering various software defect prediction projects with different characteristics such as extreme imbalance scenarios, complex distributions, and high-dimensional features.

[0025] Extract features and labels from the original data, and perform min-max standardization on the features.

[0026] Step 2: Calculate the boundary factor for each defect sample. With density factor The boundary factor Calculate defect samples The proportion of non-defect samples in the k-nearest neighbors is used to measure the boundary properties of the samples, the boundary factor. Larger values ​​indicate defective samples The closer to the class boundary, the more difficult it is for the model to learn, and therefore the higher the priority of generation.

[0027]

[0028] in, For defect samples The j-th k-nearest neighbor sample in the entire dataset, The label is for the sample, where 0 indicates a non-defective sample and 1 indicates a defective sample. This is an indicator function.

[0029] The density factor Calculate defect samples The average Euclidean distance between the sample and its k nearest neighbor defect sample is used to measure the density characteristics of the region where the sample is located; density factor. Larger values ​​indicate defective samples The sparser the region, the more difficult it is for the model to learn and the higher its generation priority.

[0030]

[0031] in, It is a defective sample The l-th defect k-nearest neighbor sample.

[0032] To comprehensively reflect the defect samples The boundary and density characteristics are analyzed using a nonlinear fusion strategy to integrate the boundary factors. With density factor Merge into weights :

[0033]

[0034] in, This indicates the number of defective samples.

[0035] Step 3: Apply the weights obtained in Step 2 Perform normalization, and then for each defect sample Allocate synthesis quantity :

[0036]

[0037] in, Represents the normalized weights. round( ) is the rounding function. The target total number of defective samples is generated.

[0038] As a preferred embodiment, when the total number of synthesized samples initially allocated to all defective samples deviates from the target total number of samples generated... When there is a shortage, the number of high-value samples generated is increased by one in descending order of weight; when there is an excess, the number of low-value samples generated is reduced by one in ascending order of weight, until the total number of synthesized samples matches the target total number of generated samples.

[0039] Step 4, as follows Figure 2 As shown, the median density factor of all defective samples is used. The defect samples are divided into high-density and low-density regions, with the density factor serving as the boundary. Based on the different distribution characteristics of the two types of regions, the standard deviation of the density factor is used to determine their distribution. Adaptive adjustment of interpolation coefficients The range of values ​​for:

[0040] ① It is a low-density area. This allows for moderate extrapolation, increasing the diversity of generated samples.

[0041] ② High-density area To avoid overlap with synthetic samples.

[0042] For defective samples By using its nearest neighbor samples with defects Linear interpolation yields preliminary synthesized samples. :

[0043]

[0044] in, A random number that fits within the range of interpolation coefficients.

[0045] Step 5: Based on the defect sample boundary factor Calculate the fuzzy coefficients of boundary sensing :

[0046]

[0047] For boundary samples, The threshold is more lenient to avoid most generated samples being misclassified as high-risk; for internal samples, the threshold is more stringent to avoid class overlap in generated samples.

[0048] like Figure 3 As shown, a dual-center reference system is constructed to include defective samples. The characteristic mean of the k nearest neighbors of a defect is used as the defect center. The feature mean of the k non-defect nearest neighbors is used as the non-defect center. Calculate the preliminary synthetic samples generated in step 4 respectively. Euclidean distance to the two centers and When the conditions are met At that time, the preliminary synthesized sample was determined. There is a risk of class overlap. Preliminary synthetic samples with this risk of overlap... Along the direction of the defect center The unit direction vector v is adjusted to obtain the final synthetic sample. :

[0049]

[0050] Wherein, the step size t is determined by the initial synthesized sample The distance difference to the two centers is determined as follows:

[0051]

[0052] This strategy effectively alleviates category overlap while preserving the true feature distribution of defective samples to a certain extent.

[0053] Step 6: Repeat steps 4 and 5. For each defect sample, generate a synthetic sample according to the allocated number of synthetic samples. Merge the final synthetic sample with the original dataset to obtain a class-balanced dataset, thus completing the oversampling of the software defect prediction dataset.

[0054] The software defect prediction method based on adaptive boundary density weighted oversampling merges the synthetic samples obtained by the above oversampling method with the original dataset to obtain a class-balanced dataset, which is then used as the training set to train the defect prediction model and output the defect prediction results.

[0055] To demonstrate the effectiveness of this method, an SVM classifier was used with default parameters. All k-nearest neighbors were fixed at k=5, and 5-fold cross-validation was employed to ensure good generalization ability and stability. Comparative experiments were conducted with commonly used methods in existing related techniques, using the F1 score as the evaluation metric. The experimental results are shown in Table 1.

[0056] Table 1

[0057]

[0058] Compared to commonly used sampling techniques in the field of defect prediction, this method, combined with an SVM classifier, demonstrates superior performance across various test tasks, achieving an average F1 score of 0.4660, significantly higher than ADASYN's 0.4135, MWMOTE's 0.3991, and MAHAKIL's 0.3874, showcasing its strong adaptability to defect prediction tasks. Particularly noteworthy is its significantly superior F1 score on the extremely imbalanced dataset Lucene, where defects comprise only 9.3% of the dataset. This score is 2.12 times that of the second-best method, MAHAKIL, 2.63 times that of MWMOTE, and 2.39 times that of ADASYN, proving its efficient prediction capabilities in extremely imbalanced scenarios.

[0059] Furthermore, experimental results show that while ADASYN can alleviate general class imbalance, its optimization is insufficient in extreme imbalance scenarios. MWMOTE relies on the majority class sample distribution assumption, limiting its performance in complex distribution scenarios. MAHAKIL is more suitable for low-dimensional balanced data, but its generalization ability decreases in high-dimensional feature scenarios. Our proposed method, through two-factor quantification of hard-to-classify sample features, adaptive sample synthesis strategy, and class overlap control, can more accurately capture potential defect patterns, demonstrating high robustness and efficiency in various software defect prediction projects with different characteristics.

Claims

1. A software defect prediction oversampling method based on adaptive boundary density weighting, characterized in that: For each defect sample x in the original software defect dataset i The proportion of non-defect samples in its k nearest neighbors is used as the boundary factor B(i), and the average Euclidean distance between it and the k nearest neighbor defective samples is used as the density factor D(i). The defective sample x is then obtained through nonlinear fusion and normalization. i Importance weight W(i), based on the importance weight W(i) for each defect sample x i Allocate the number of synthetic samples; Using the median density factor as the boundary, defect samples are divided into high-density and low-density regions. Defect samples in high-density regions are assigned smaller interpolation coefficients, while those in low-density regions are assigned larger interpolation coefficients. Initial synthetic samples are generated through linear interpolation under the control of the interpolation coefficients. Calculate the fuzzy coefficient based on the boundary factor B(i); use the feature mean of the k nearest neighbor defect samples of the defect sample as the defect center, and the feature mean of the k non-defect nearest neighbors as the non-defect center, calculate the Euclidean distance from the initial synthetic sample to the two centers respectively, and determine the overlap risk of the initial synthetic sample in combination with the fuzzy coefficient, and adjust the risk samples along the defect center direction; for each defect sample, generate synthetic samples according to the allocated number of synthesis samples and perform overlap risk judgment and adjustment to complete the oversampling of the software defect prediction dataset.

2. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 1, characterized in that: The boundary factor B(i) and density factor D(i) are respectively: in, For defect samples The j-th k-nearest neighbor sample in the entire dataset, for The label 0 indicates a non-defective sample; For indicator functions; It is a defective sample The l-th defect k-nearest neighbor sample.

3. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 1, characterized in that: The importance weight W(i) is: in, This indicates the number of defect samples in the original software defect dataset.

4. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 3, characterized in that: For each defect sample x, the importance weight W(i) is used. i Allocate the number of synthetic samples : in, Represents the normalized weights; round( ) is the rounding function. The target total number of defective samples is generated.

5. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 4, characterized in that: When the total number of synthesized samples initially allocated from all defective samples is less than the target total number of samples generated. At that time, the number of synthesized samples generated for each defective sample is incremented by one in descending order of weight. When the total number of synthesized samples exceeds the target total number of samples generated, the process continues. At that time, the number of synthesized samples generated for each defective sample is decreased by one in ascending order of weight, until the sum of the number of synthesized samples for all defective samples equals the target total number of generated samples. Consistent.

6. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 1, characterized in that: According to the defect sample The density factor D(i) adaptively adjusts the interpolation coefficients. The range of values ​​for: ① Defective samples It belongs to a low-density area. ; ② Defective samples It belongs to a high-density area. ; in, , These represent the standard deviation and median of the density factor, respectively.

7. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 6, characterized in that: Defect samples Initial synthetic sample generated from seed sample for: in, It is a defective sample The l-th defect k-nearest neighbor sample.

8. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 1, characterized in that: According to the defect sample boundary factor Calculate the fuzzy coefficients of boundary sensing : When satisfied At that time, the preliminary synthesized sample was determined. There is a risk of class overlap. Adjustments are made along the unit direction vector v pointing to the defect center to obtain the final synthetic sample. , These represent defect samples respectively. The Euclidean distance from the defect center and the non-defect center.

9. The software defect prediction method based on adaptive boundary density weighted oversampling as described in claim 8, characterized in that: The final synthetic sample for: 。 10. A software defect prediction method based on adaptive boundary density weighted oversampling, characterized in that: For the original software defect dataset with imbalanced class distribution, oversampling is performed according to any one of the methods described in claims 1 to 9, and the resulting class-balanced dataset is used as the training set to train a defect prediction model, which is used to output the defect prediction results of unknown software modules.