Oversampling and software defect prediction method based on space mapping and probability constraint
By using an oversampling method based on spatial mapping and probabilistic constraints, the problems of insufficient sample distribution quality and inadequate characterization of high-dimensional nonlinear structures in existing technologies are solved, enabling the generation of high-quality synthetic samples and improving the accuracy and robustness of software defect prediction models.
Patent Information
- Application Number
- CN202610053835.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-15
- Publication Date
- 2026-05-01
AI Technical Summary
Existing oversampling methods for software defect prediction suffer from insufficient consideration of sample distribution quality, inability to characterize the nonlinear structure of high-dimensional space, and lack of feedback verification, resulting in poor sample generation quality and thus affecting the prediction accuracy of the model.
By employing an oversampling method based on spatial mapping and probabilistic constraints, a posterior probability score system is constructed using kernel density estimation. This system performs low-dimensional projection of the local manifold and adaptive generation of sphere radius adjustment. Combined with manifold consistency and likelihood ratio verification, the quality and representativeness of the synthesized samples are ensured.
It significantly improved the model's sensitivity to key defects, enhanced the diversity and representativeness of synthetic samples, reduced noise interference, improved the model's predictive ability, and reduced the false alarm rate.
Smart Images

Figure CN121958060A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of machine learning technology and relates to dataset processing and software defect prediction, specifically to an oversampling and software defect prediction method based on spatial mapping and probability constraints. Background Technology
[0002] As software becomes increasingly large-scale and complex in logical structure, software defect prediction technology has become an important means of ensuring system reliability. However, in software engineering practice, the proportion of defective modules is usually much lower than that of defect-free modules; that is, the number of minority class samples is much lower than the number of majority class samples. This class imbalance phenomenon causes machine learning models to easily develop prediction bias towards the majority class during training, thus missing critical defective modules.
[0003] Sampling techniques are one of the core strategies for solving class imbalance problems. Oversampling, in particular, balances the dataset by synthesizing new minority class instances, offering significant advantages in preserving original information. However, existing oversampling methods, such as SMOTE and its variants, still have technical shortcomings when processing software defect data. First, most existing seed sample identification methods are based on the local nearest neighbor statistical logic of a single class, ignoring the relationship between minority and majority class samples in the global probability distribution. This leads to the algorithm's inability to accurately locate high-contribution seed samples, generating a large number of low-quality samples. Second, linear interpolation methods directly connect two points in the original high-dimensional space. This flat interpolation method cannot characterize the curved, bifurcated, or multimodal distribution characteristics commonly found in software metric data, ignoring the nonlinear structure of local manifolds. The synthesized samples are mechanically concentrated on the linear segments between the seed point and its nearest neighbors, resulting in insufficient sample representativeness and a collapsed distribution. This not only fails to truly reflect the physical underlying logic of software metrics but also easily introduces redundant feature noise. Finally, existing technologies lack rigorous post-processing verification mechanisms for synthetic samples. After generation, synthetic samples can easily infiltrate the distribution area of most class samples, causing serious class overlap. This not only blurs the decision boundary but may also mislead the classifier into misclassifying defective modules as defective, significantly increasing the false alarm rate of software testing.
[0004] In summary, there is an urgent need for a comprehensive solution that can achieve accurate seed selection based on the differences in the contribution of samples at the decision boundary, local nonlinear sampling, and closed-loop feedback verification. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention proposes an oversampling and software defect prediction method based on spatial mapping and probabilistic constraints. By accurately selecting seeds based on the differences in contribution of samples at the decision boundary, it achieves low-dimensional projection of the local manifold to realize nonlinear perturbation sampling. Combined with global probability distribution verification, it accurately strengthens the decision boundary while ensuring sample authenticity. This addresses the technical deficiencies of existing software defect prediction sampling techniques, such as the lack of consideration for the quality of seed sample distribution, the inability of high-dimensional linear interpolation to characterize complex local manifold structures, and the lack of feedback verification leading to sample infiltration.
[0006] An oversampling method based on spatial mapping and probabilistic constraints specifically includes the following steps:
[0007] Step 1: Impute missing values and standardize the original dataset to eliminate dimensional differences. Then, calculate the class imbalance rate IR of the dataset and set the global sampling rate SR = IR-1 to ensure that the total number of minority class samples is equal to the total number of majority class samples after sampling.
[0008] Step 2: Construct probability density models for the minority and majority classes based on the kernel density estimation (KDE) method, and use the Gaussian kernel function to calculate the probability density estimates of the minority sample x under the minority and majority class distributions. , For each minority class sample, calculate the posterior probability score:
[0009]
[0010] Minority class samples are sorted from largest to smallest according to their posterior probability scores. Samples in the bottom 30% quantile are removed, and samples between the top 30% and 70% quantiles are designated as medium-density Boundary Samples. Samples above the top 30% quantile are designated as high-density Core Samples.
[0011] Step 3: Set the base weight coefficient W for medium-density boundary samples and high-density core samples. base The values are 1.2 and 1.0 respectively. A weighting coefficient based on the posterior probability score Score(x) is introduced to adjust the values for the minority class seed sample x. seed Synthetic sample quota Count(x) seed ):
[0012]
[0013]
[0014] Where M represents the total number of medium-density boundary samples and high-density core samples, and N... total_syn This represents the total number of minority class samples that need to be added, as determined by the global sampling rate SR.
[0015] Step 4: For each minority class seed sample x seed Select the nearest minority class sample x from the original feature space. minor A heterogeneous majority class sample x major A local triplet sample set is formed, and principal component analysis is used to project the triplet onto a 3D local feature subspace. Within this local feature subspace, the minority class seed sample x is calculated. seed With x minor x major The Euclidean distance d between them min With d max Adaptively generate sphere radius R:
[0016]
[0017] Where λ∈[0,1) is the security scaling factor, and η∈[0,1) is the defense factor.
[0018] In the minority seed sample x seed Random samples are taken within a space centered at R and with radius R, and then an inverse transformation is performed to reconstruct a high-dimensional synthetic sample x. syn .
[0019] Step 5: Perform a synthesis on sample x syn Perform relative density retention rate and boundary likelihood ratio verification. If the verification fails, record the number of failures, reduce the values of the safety scaling factor and defense factor, recalculate the generated sphere radius R, and iterate resampling until the number of synthetic samples reaches the synthetic sample quota Count(x). seed ).
[0020] The software defect prediction method based on spatial mapping and probabilistic oversampling first resamples the original software defect dataset using the aforementioned oversampling method based on spatial mapping and probabilistic constraints, balancing the distribution of samples across categories to obtain a balanced training dataset. Then, the DecisionTree classifier is trained in a supervised manner using this balanced training dataset, enabling the classifier to fully learn the essential distribution of defect features. Finally, the trained classifier is used to predict software defects in unknown samples, outputting the category to which the unknown sample belongs.
[0021] The present invention has the following beneficial effects:
[0022] 1. Accurate identification and differentiated weighting of sampling seeds were achieved, significantly improving the model's sensitivity to key defects: By introducing a dual-class kernel density estimation to construct a posterior probability scoring system, and considering the density relationship between the minority and majority classes in the feature space, noise points between the majority and minority classes were identified and eliminated. Simultaneously, seed points located at the decision boundary with high discriminative value were assigned higher sampling weights, ensuring that generation resources were tilted towards information-rich regions. Experiments demonstrate that this accurate seed selection mechanism effectively reduces the generation of low-quality samples due to noise interference, significantly improving the model's defect detection rate on imbalanced datasets.
[0023] 2. Overcoming the limitations of high-dimensional linear interpolation, the authenticity and representativeness of the synthesized samples are ensured through manifold mapping: By utilizing low-dimensional projection techniques in local subspaces, the feature distortion and curse of dimensionality caused by direct sampling in high-dimensional spaces are successfully resolved. Compared to existing techniques that mechanically interpolate on line segments, the 3D spherical domain nonlinear sampling employed can more realistically characterize the bending, bifurcation, and multimodal distribution features present in software metric data. The synthesized samples are no longer limited to line segment distributions but evolve naturally along local manifold trends, greatly enhancing the diversity and representativeness of the samples, and the generated data is more consistent with the physical logic of software metrics.
[0024] 3. A closed-loop verification mechanism with adaptive correction capabilities was constructed, improving the quality of synthesized samples: During the sample generation stage, dual probability constraints of manifold consistency and likelihood ratio were introduced to accurately guide synthesized samples to a safe distribution area, effectively preventing class overlap caused by new samples penetrating into the heart of the majority class. Through an adaptive radius feedback adjustment mechanism, the system can self-correct based on the verification results; if sampling fails, the generation space is automatically shrunk. This closed-loop control mechanism strengthens the decision boundary, significantly improving the model's overall predictive ability for defective samples. Attached Figure Description
[0025] Figure 1 This is a diagram illustrating the overall framework of an oversampling and software defect prediction method based on spatial mapping and probabilistic constraints.
[0026] Figure 2 Flowchart for sample stratification and sample synthesis number allocation;
[0027] Figure 3 This is a diagram showing different distribution examples of local ternary sample groups. Detailed Implementation
[0028] The present invention will be further explained below with reference to the accompanying drawings;
[0029] like Figure 1 As shown, a software defect prediction method based on spatial mapping and probabilistic constraint oversampling is presented, with the following specific steps:
[0030] Step 1: This embodiment uses data from public datasets PROMISE, NASA, and AEEEM as the original data source. First, the original dataset is cleaned, and missing values are filled using the mean of the feature columns. The mean-variance standardization (StandardScaler) is used to scale the features to eliminate differences in units and ensure the consistency of the weights of each dimension when estimating the kernel density.
[0031] The processed data was divided into training and test sets in a 9:1 ratio. Subsequent sampling and model fitting processes were all conducted on the training set to ensure the objectivity of the evaluation results.
[0032] Calculate the class imbalance rate IR=N of the training set. maj / N min , where N maj N represents the number of samples in the majority class. min This represents the number of minority class samples. To ensure the sampled dataset achieves theoretical class balance, the global sampling rate SR = IR-1 is set to ensure the total number of synthetic samples N is balanced. syn =N min ×(IR-1) ensures that the total number of minority class samples after sampling is equal to the total number of majority class samples.
[0033] Step 2, as follows Figure 2 As shown, based on the probability scores and quantile determination of kernel density estimation (KDE), minority class samples in the training set are hierarchically sorted to remove noise interference and accurately identify boundary seeds to achieve differential sampling.
[0034] Step 2-1: For the sample distribution in the standardized feature space, construct probability density models for the minority and majority classes using the kernel density estimation method. Calculate the probability density estimates of the minority class sample point x under the minority and majority class distributions, respectively. , :
[0035]
[0036]
[0037] Where d is the feature dimension, h min For minority class smooth bandwidth, x i_min Let h be the i-th known minority class instance. max For the majority class smooth bandwidth, x j_max Let j be the j-th known majority class instance. For Gaussian kernel function:
[0038]
[0039] Step 2-2: Based on the probability density estimation results, calculate the attribution score for each minority class sample x to characterize the relative purity of the sample under the two competing distributions.
[0040]
[0041] The attribution score theoretically maps the posterior probability that a minority class sample x belongs to the minority class. The higher the value of Score(x), the purer the feature distribution of the minority class sample x. A value close to 0.5 indicates that the sample is in the overlapping boundary region of the two distributions.
[0042] Steps 2-3: To adaptively address the imbalanced characteristics of different software datasets, a quantile method is used to set a dynamic splitting threshold. All minority class samples are sorted from largest to smallest according to their class affiliation score. Samples above the top 30% quantile are designated as high-density core samples. Samples between the top 30% and 70% quantiles are designated as medium-density boundary samples. Samples in the bottom 30% quantile are designated as low-density sparse outlier samples.
[0043] Steps 2-4: Retain high-density core samples and medium-density boundary samples as qualified seed samples and include them in the sampling reference set. For low-density sparse samples (outlier samples), determine them as invalid samples that are deeply embedded in the majority class distribution region or far from the main distribution, and remove them during the sampling stage.
[0044] This two-way density comparison mechanism ensures from the source that the oversampling process will not generate false defective samples in areas with extremely low decision weight.
[0045] Step 3: Dynamically determine the x of each seed sample based on the hierarchical attributes of the seed samples in the sampling reference set and their discriminative value in the feature space. seed The synthetic sample quota is used to achieve non-uniform reinforcement of the defect class distribution:
[0046] Step 3-1: Based on the stratification results of Step 2-3, assign a basic weight coefficient W to the qualified seed samples at different levels. base The underlying weighting coefficient W for medium-density boundary samples. base =1.2, to enhance the classifier's ability to learn the decision boundary. The base weight coefficient W for high-density core samples. base=1.0, to maintain the integrity of the inherent distribution of the minority class.
[0047] Step 3-2: To further refine the synthetic value of each seed sample, a weighting coefficient based on the attribution score Score(x) is introduced for seed sample x. seed The final weight of the synthetic sample quota: Weight(x) seed )for:
[0048]
[0049] Step 3-3: Based on the global sampling rate SR preset in Step 1, calculate the total number N of minority class samples that need to be added to the training set. total_syn :
[0050] N total_syn =N min ×(SR-1)
[0051] Calculate each minority class seed sample x seed Synthetic sample quota Count(x) seed ):
[0052]
[0053] Where M is the total number of minority class seed samples in the sampling reference set. This step ensures that the total number of synthesized samples meets expectations, and that the generation frequency of each seed strictly matches its importance in the probability space.
[0054] Step 4: To address the feature distortion problem caused by traditional oversampling algorithms when performing linear interpolation in high-dimensional feature spaces, a local subspace is constructed and spherical random perturbations are introduced to generate nonlinear new samples along the essential manifold structure of the data distribution.
[0055] Step 4-1: For each minority class seed sample x in the sampling reference set seed The nearest neighbor algorithm is used to retrieve the nearest minority class sample x of the same class in the original D-dimensional feature space. minor A heterogeneous majority class sample x major These three elements together form a local triplet sample set. Principal component analysis is used to transform the coordinates of this triplet, projecting it from the original D-dimensional space to a 3-dimensional local feature subspace, thus obtaining its projected coordinates x. seed =(x u ,x v ,x w The projected principal component orientation is automatically aligned with the orientation of the maximum variance of the local manifold, ensuring that subsequent sampling processes can proceed along the essential geometric structure of the data distribution, effectively avoiding false feature associations caused by blind fluctuations on the original attribute axes.
[0056] Step 4-2: Calculate the minority class seed sample x in the projected 3D subspace. seed With x minor x major The Euclidean distance d between them min With d max To enhance sample diversity while ensuring boundary security, such as Figure 3 As shown, according to d min With d max The size relationship is used to adaptively generate the sphere radius R:
[0057] ①Safe Expansion Mode: If d min <d max This indicates that the minority seed sample x seed Within a defective cluster, the generation space can appropriately extend across existing neighbors to enhance generalization:
[0058] R=d min +λ×(d max -d min )
[0059] Where λ∈[0,1) is the safety scaling factor.
[0060] ② Boundary contraction mode: If d max ≤d min This indicates that the minority seed sample x seed Sensitive regions located at the boundary between categories need to have their radius reduced to prevent sample penetration.
[0061] R=η×d max
[0062] Where η∈[0,1) is the defense factor.
[0063] Step 4-3, Minority class seed sample x seed =(x u ,x v ,x w Using y as the center of a sphere and radii calculated to R in step 4-2, random sampling is performed in the 3D local feature subspace to synthesize sample x. new 3D spherical coordinates (p) u ,p v ,p w )for:
[0064]
[0065] in, For a random radius, It is the azimuth angle. It is the polar angle.
[0066] Step 4-4: Based on the inverse transformation matrix of the coordinate transformation in principal component analysis in Step 4-1, synthesize the points x in the 3D subspace. new Mapping back to the original D-dimensional feature space yields the final high-dimensional synthetic sample x. syn The synthesized sample, through nonlinear mapping of the local manifold, not only preserves the nonlinear correlation between the original features, but also enhances the expressive power of the minority class near the decision boundary through spatial reconstruction.
[0067] Step 5: Through dual verification of manifold consistency and boundary likelihood ratio, ensure that the synthetic samples can both realistically simulate the defect class distribution and effectively strengthen the decision boundary.
[0068] Step 5-1: Using the kernel density estimation method in Step 2, calculate the synthetic sample x. syn With the corresponding minority class seed sample x seed Probability density estimate under minority class distribution , Calculate the relative density retention rate (RelativeDensity):
[0069]
[0070] Set a fidelity threshold γ. If Relative_Density < γ, then the sample x is considered synthetic. syn Distribution collapse occurred, meaning the data deviated from the effective distribution manifold of the defective data, and these points were considered invalid sparse points and were discarded. To prevent synthesized samples from deviating from the effective distribution region due to nonlinear projection bias, the local manifold structure of their parent seed samples was verified.
[0071] Step 5-2: To address the common class overlap problem in software defect data, a likelihood ratio criterion is introduced, based on the synthesized sample x. syn Probability density estimates for minority and majority class distributions , Calculate the boundary probability score p border :
[0072]
[0073] Set the boundary constraint interval [α, β], if p border <α, therefore the synthetic sample x is considered to be syn Deep within the majority class sample territory, these are illegal samples that can interfere with the classifier's judgment. If p border >β, therefore the synthetic sample x is considered to be syn Samples that are too close to the minority class core and lack discriminatory power are considered redundant and should be removed. If p border ∈[α,β], synthesize sample xsyn These are considered high-quality boundary support samples and are retained.
[0074] Step 5-3, when synthesizing sample x syn If a sample fails to simultaneously satisfy both the manifold consistency and likelihood ratio constraints, and is thus judged as needing to be removed in step 5-1 or step 5-2, a feedback adjustment mechanism for the radius R of the generated sphere is triggered to ensure that qualified samples can still be produced under complex distributions.
[0075] First, record the current minority class seed sample x. seed The number of consecutive sampling failures within the neighborhood is counted. When the number of sampling failures exceeds the preset upper limit, it is considered that the current generated sphere radius R has touched the hard boundary or manifold fracture zone of the majority class. The values of the safety scaling factor and defense factor are reduced, and the process returns to step 4-2 to recalculate the generated sphere radius R. A new synthetic sample is generated based on the updated generated sphere radius R until the generated sample successfully passes the double verification of steps 5-1 and 5-2, or the maximum number of attempts is reached.
[0076] Step 6: Once the set sampling rate is reached, the resulting balanced dataset is input into the DecisionTree classifier, and 10-fold cross-validation is used for optimization. Finally, the performance is validated using the G-mean and AUC metrics on the test set. To demonstrate the effectiveness of this method, the experimental results are compared with commonly used methods in the prior art, as shown in Table 1.
[0077] Table 1
[0078]
[0079] G-mean is the geometric mean of the minority class recall and the majority class recall. Its physical meaning lies in comprehensively evaluating the balance of the model's ability to identify positive and negative samples. A high value for this metric is achieved only when the model effectively suppresses false positives from defective modules while also suppressing false positives from normal modules. AUC is the area under the ROC curve. The horizontal axis of the ROC curve represents the false positive rate, and the vertical axis represents the true positive rate. A larger AUC value indicates a more robust overall discriminative performance of the model under different decision thresholds. As shown in Table 1, compared with existing techniques, our method significantly improves both G-mean and AUC, indicating that the classifier trained on the resampled training set using our method not only effectively reduces false negatives from the minority class but also maintains a low false positive level, demonstrating superior classification performance.
Claims
1. An oversampling method based on spatial mapping and probabilistic constraints, characterized in that: Calculate the class imbalance rate IR of the original dataset and set the global sampling rate SR = IR-1; A probability density model is constructed based on the kernel density estimation method, and the probability density estimate of each minority sample x under the minority and majority class distributions is calculated. , For each minority class sample, calculate the posterior probability score: Based on the posterior probability scores, the minority class samples are divided into three levels: high-density core samples, medium-density marginal samples, and low-density sparse samples; high-density core samples and medium-density marginal samples are selected as seed samples for the minority class. seed Set the basic weight coefficient W according to the level to which the sample belongs. base Calculate x for each minority class seed sample seed Synthetic sample quota Count(x) seed ): Where M represents the total number of minority class seed samples, N total_syn This represents the total number of minority class samples that need to be added, as determined by the global sampling rate SR. For each minority class seed sample x seed Select the nearest minority class sample x from the original feature space. minor A heterogeneous majority class sample x major This forms a local triplet sample group, which is then projected onto a lower-dimensional local feature subspace. Within this local feature subspace, the minority class seed sample x is calculated. seed With x minor x major The Euclidean distance d between them min With d max Adaptively generate sphere radius R: Where λ∈[0,1) is the security scaling factor, and η∈[0,1) is the defense factor; In the minority seed sample x seed Random samples are taken within a space centered at R and with radius R, and then an inverse transformation is performed to reconstruct a high-dimensional synthetic sample x. syn For the synthetic sample x syn Perform relative density retention rate and boundary likelihood ratio verification. If the verification fails, reduce the radius R of the generated sphere by changing the values of the safety scaling factor and defense factor, and iterate resampling until the number of synthetic samples reaches the synthetic sample quota Count(x). seed ).
2. The oversampling method based on spatial mapping and probability constraints as described in claim 1, characterized in that: The probability density estimate of the minority class sample x under the minority and majority class distributions , for: Where, N min The number of minority class samples is represented by d, where d is the feature dimension and h is the number of minority class samples. min For minority class smooth bandwidth, x i_min For the i-th known minority class instance; N maj h represents the number of samples in the majority class. max For the majority class smooth bandwidth, x j_max For the j-th known majority class instance; This is the Gaussian kernel function.
3. The oversampling method based on spatial mapping and probability constraints as described in claim 1, characterized in that: Samples with posterior probability scores above the top 30 percentile are designated as high-density core samples, samples between the top 30% and 70% percentiles are designated as medium-density marginal samples, and samples in the bottom 30% percentiles are designated as low-density sparse samples.
4. The oversampling method based on spatial mapping and probability constraints as described in claim 3, characterized in that: The base weight coefficient for high-density core samples is set to 1.0, and the base weight coefficient for medium-density marginal samples is set to 1.
2.
5. The oversampling method based on spatial mapping and probability constraints as described in claim 1, characterized in that: Principal component analysis is used to project local ternary sample groups from the original dimensional space to a 3-dimensional local feature subspace.
6. The oversampling method based on spatial mapping and probability constraints as described in claim 1, characterized in that: The relative density retention rate verification is performed by: setting a fidelity threshold γ; and using a probability density model constructed using the kernel density estimation method to calculate the synthetic sample x. syn With the corresponding minority class seed sample x seed Probability density estimate under minority class distribution , Calculate the relative density retention rate (RelativeDensity): If Relative_Density < γ, the verification fails.
7. The oversampling method based on spatial mapping and probability constraints as described in claim 1, characterized in that: The boundary likelihood ratio verification is performed by: setting a boundary constraint interval [α, β]; and using a probability density model constructed using the kernel density estimation method to calculate the synthetic sample x. syn Probability density estimates for minority and majority class distributions , Calculate the boundary probability score p border : If p border <α or p border If the value is greater than β, the verification fails.
8. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1 to 7.
9. A software defect prediction method based on spatial mapping and probabilistic constraint oversampling, characterized in that: The original software defect dataset is resampled using an oversampling method based on spatial mapping and probability constraints as described in any one of claims 1 to 7 to balance the distribution of samples in each category, thereby obtaining a training dataset with balanced samples. Subsequently, the classifier is trained in a supervised manner using the balanced training dataset; finally, the trained classifier is used to predict software defects in unknown samples and output the category to which the unknown samples belong.
10. The software defect prediction method based on spatial mapping and probabilistic constraint oversampling as described in claim 9, characterized in that: The classifier shown is DecisionTree.