Method, device and computer device for establishing a predictive software defect optimization model

By calculating the correlation coefficients of software defect features to generate weight vectors, and through mutation and crossover combinations, samples are filtered and sorted, the model bias problem caused by imbalanced datasets is solved, achieving more efficient software defect prediction and repair.

CN121050998BActive Publication Date: 2026-01-23ELECTRIC POWER RES INST CHINA SOUTHERN POWER GRID CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511599522.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-04
Publication Date
2026-01-23
Estimated Expiration
2045-11-04

AI Technical Summary

Technical Problem

When faced with imbalanced datasets, existing software defect prediction models are prone to information loss and model bias due to traditional undersampling or oversampling methods. Furthermore, they overemphasize the weight of a single feature while ignoring the contribution of the overall features of the sample, resulting in poor prediction performance.

Method used

By calculating the correlation coefficient between the software defect prediction features and the labeled data, a first weight vector is generated, and a second weight vector is generated through mutation and crossover. Sub-vectors that meet the preset conditions are selected, and the samples are sorted based on the final weight vector. The majority class samples are removed to generate a balanced dataset, which is finally used to train the software defect optimization model.

Benefits of technology

The undersampling process has been optimized, improving the accuracy and robustness of software defect prediction and helping developers identify and fix software defects more efficiently.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121050998B_ABST
    Figure CN121050998B_ABST
Patent Text Reader

Abstract

The application relates to a method and device for establishing a software defect prediction optimization model, a computer device, a storage medium and a computer program product. The method comprises the following steps: obtaining a software defect unbalanced data set; performing feature extraction on the unbalanced data set to obtain software defect prediction features, calculating the correlation coefficient between the software defect prediction features and corresponding labeled data, and calculating the software defect prediction feature weight to form a first weight vector; generating a mutation weight vector based on the mutation of the first weight vector, crossing and combining the first weight vector, and generating a second weight vector; comparing the first weight vector and the second weight vector, screening a subvector that meets a preset condition to form an optimal weight vector; sorting the samples in the unbalanced data set based on the optimal weight vector, removing the samples that meet the preset condition, and generating a balanced data set; and using the balanced data set for model training to obtain a prediction software defect optimization model. The method can be used to establish a prediction software defect optimization model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software engineering technology, and in particular to a method, apparatus, computer device, computer-readable storage medium, and computer program product for establishing an optimization model for predicting software defects. Background Technology

[0002] In the process of software development and maintenance, establishing a software defect prediction model is a crucial technology. It can help development teams discover potential defects in software in advance, thereby fixing them at an early stage and reducing the risks and costs after software release.

[0003] In building software defect prediction models, the software defect data often exhibits class imbalance, meaning the number of samples with no defects or minor defects far exceeds the number of samples with severe defects. This leads to poor performance of the software defect prediction model. Traditional defect prediction methods typically employ undersampling or oversampling techniques to address this issue, but these suffer from information loss and model bias. To resolve these problems, traditional techniques involve weighting the features of the samples and selectively undersampling based on sample importance, thereby reducing information loss and improving the predictive performance of the defect prediction model.

[0004] However, existing feature-weighted undersampling methods often overemphasize the weight of individual features while neglecting the contribution of the overall features of the sample. This can easily lead to the exclusion of key samples during sampling, thereby weakening the performance of software defect prediction models. Therefore, there is an urgent need for a method to construct an optimized software defect prediction model to effectively address these issues. Summary of the Invention

[0005] Therefore, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium, and computer program product capable of establishing a predictive software defect optimization model to address the aforementioned technical problems.

[0006] Firstly, this application provides a method for establishing an optimization model for predicting software defects, including:

[0007] Obtain an imbalanced dataset of software defects; extract features from the imbalanced dataset of software defects to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0008] A mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are cross-combined to generate a second weight vector.

[0009] Compare each component vector in the first weight vector and the second weight vector, select the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions;

[0010] Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset.

[0011] The software defect balanced dataset is used to train the software defect prediction optimization model, thus obtaining the software defect prediction optimization model.

[0012] In one embodiment, weights for at least one software defect prediction feature are calculated based on a correlation coefficient to form a first weight vector, including:

[0013] Based on the absolute value of the correlation coefficient, the weight of at least one software defect prediction feature is determined, and the weights of the at least one software defect prediction feature are combined to generate a first weight vector.

[0014] In one embodiment, a mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are intersected to generate a second weight vector, including:

[0015] Based on any three component vectors of the first weight vector, a mutation scaling factor is introduced to calculate the mutation weight vector.

[0016] The first weight vector is cross-combined with multiple sub-vectors in the mutated weight vector to generate the second weight vector.

[0017] In one embodiment, each component vector in the first weight vector and the second weight vector is compared, and component vectors that meet preset conditions are selected. The final weight vector is then formed based on these component vectors, including:

[0018] Based on the preset objective function, evaluate the fitness of all sub-vectors in the first weight vector and the second weight vector;

[0019] Compare the fitness of all component vectors in the first weight vector with the fitness of all component vectors in the second weight vector, select all component vectors whose fitness meets the preset conditions, form the target weight vector, replace the first weight vector with the target weight vector, and continue to execute the steps based on any three component vectors of the first weight vector and the subsequent steps until the preset maximum number of iterations is reached or the fitness improvement reaches the preset threshold, and use the corresponding target weight vector as the final weight vector.

[0020] In one embodiment, based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet preset conditions are removed to generate a balanced software defect dataset, including:

[0021] Imbalanced datasets for software defects contain majority class samples and minority class samples;

[0022] The features of all samples in the imbalanced software defect dataset are combined with the final weight vector to calculate the weighted score of all samples in the imbalanced software defect dataset. Based on the weighted score, all samples in the imbalanced software defect dataset are sorted, keeping the number of minority class samples unchanged, and removing some majority class samples that meet the preset conditions until the number of majority class samples is consistent with the number of minority class samples, thus generating a balanced software defect dataset.

[0023] In one embodiment, a balanced dataset is used to train an optimization model for predicting software defects, resulting in an optimization model for predicting software defects, including:

[0024] The software defect balanced dataset is divided into a training set and a validation set;

[0025] The software defect model is trained using a training set, and then the performance of the trained software defect model is evaluated using a validation set to obtain an optimized model for predicting software defects.

[0026] Secondly, this application also provides an apparatus for establishing a predictive software defect optimization model, comprising:

[0027] The calculation module is used to acquire an imbalanced software defect dataset; extract features from the imbalanced software defect dataset to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; and calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0028] The generation module is used to generate a mutated weight vector based on the mutation of the first weight vector, and to cross-combine the first weight vector and the mutated weight vector to generate a second weight vector.

[0029] The comparison module is used to compare each sub-vector in the first weight vector with each sub-vector in the second weight vector, filter out the sub-vectors that meet the preset conditions, and form a weight vector based on the sub-vectors that meet the preset conditions.

[0030] The sorting module is used to sort the samples in the imbalanced software defect dataset based on the weight vector, remove samples that meet the preset conditions, and generate a balanced software defect dataset.

[0031] The training module is used to train an optimization model for predicting software defects using a balanced software defect dataset, thereby obtaining the optimization model for predicting software defects.

[0032] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0033] Obtain an imbalanced dataset of software defects; extract features from the imbalanced dataset of software defects to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0034] A mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are cross-combined to generate a second weight vector.

[0035] Compare each component vector in the first weight vector and the second weight vector, select the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions;

[0036] Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset.

[0037] The software defect balanced dataset is used to train the software defect prediction optimization model, thus obtaining the software defect prediction optimization model.

[0038] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:

[0039] Obtain an imbalanced dataset of software defects; extract features from the imbalanced dataset of software defects to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0040] A mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are cross-combined to generate a second weight vector.

[0041] Compare each component vector in the first weight vector and the second weight vector, select the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions;

[0042] Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset.

[0043] The software defect balanced dataset is used to train the software defect prediction optimization model, thus obtaining the software defect prediction optimization model.

[0044] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:

[0045] Obtain an imbalanced dataset of software defects; extract features from the imbalanced dataset of software defects to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0046] A mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are cross-combined to generate a second weight vector.

[0047] Compare each component vector in the first weight vector and the second weight vector, select the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions;

[0048] Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset.

[0049] The software defect balanced dataset is used to train the software defect prediction optimization model, thus obtaining the software defect prediction optimization model.

[0050] The aforementioned method, apparatus, computer equipment, computer-readable storage medium, and computer program product for establishing a predictive software defect optimization model firstly acquire an imbalanced software defect dataset; extract features from the imbalanced software defect dataset to obtain at least one software defect prediction feature, calculate the correlation coefficient between the at least one software defect prediction feature and its corresponding labeled data, and calculate the weights of the at least one software defect prediction feature based on the correlation coefficients to form a first weight vector; generate a mutated weight vector based on the first weight vector, and cross-combine the first weight vector and the mutated weight vector to generate a second weight vector; secondly, compare each component vector in the first weight vector and the second weight vector, select component vectors that meet preset conditions, and form a final weight vector based on the component vectors that meet the preset conditions; thirdly, sort the samples in the imbalanced software defect dataset based on the final weight vector, remove samples that meet the preset conditions, and generate a balanced software defect dataset; finally, use the balanced software defect dataset to train the predictive software defect optimization model to obtain the predictive software defect optimization model. Therefore, by optimizing the feature weighting mechanism in the undersampling process, the undersampling process is optimized, and a software defect prediction optimization model is established, which effectively improves the accuracy and robustness of software defect prediction and helps developers identify and fix software defects more efficiently. Attached Figure Description

[0051] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0052] Figure 1 This is a flowchart illustrating a method for establishing a predictive software defect optimization model in one embodiment.

[0053] Figure 2 This is a graphical illustration of a method for establishing a predictive software defect optimization model in one embodiment;

[0054] Figure 3 This is a flowchart illustrating a method for establishing a predictive software defect optimization model in another embodiment.

[0055] Figure 4 A structural block diagram of an apparatus for establishing a predictive software defect optimization model in one embodiment;

[0056] Figure 5 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0057] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0058] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.

[0059] In one exemplary embodiment, such as Figure 1 As shown, a method for establishing a predictive software defect optimization model is provided. This embodiment illustrates the application of this method to a terminal, which can be, but is not limited to, various personal computers, laptops, smartphones, tablets, drones, low-altitude aircraft, IoT devices, and portable wearable devices. IoT devices can be smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. Portable wearable devices can be smartwatches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. In this embodiment, the method includes the following steps:

[0060] Step 102: Obtain the imbalanced software defect dataset; extract features from the imbalanced software defect dataset to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0061] Imbalanced software defect datasets refer to a situation where the number of samples containing defects differs significantly from the number of samples without defects in the software defect dataset used for training software defect models.

[0062] Specifically, the correlation coefficient is the Pearson correlation coefficient, a statistic that measures the strength of the linear relationship between at least one software defect prediction feature and its corresponding labeled data, usually denoted by r. The correlation coefficient should be between -1 and +1, indicating the degree of correlation between the two variables. When the correlation coefficient is close to +1, it indicates a strong positive correlation, where one variable increases as the other increases; when the correlation coefficient is close to -1, it indicates a strong negative correlation, where one variable decreases as the other increases; when the correlation coefficient is close to 0, it indicates almost no linear relationship. The corresponding labeled data are binary labels, indicating whether the software contains defects. A linear relationship exists between the software defect prediction feature and its corresponding labeled data, and the correlation coefficient quantifies this linear relationship, evaluating the predictive power of the feature. The first weight vector provides an initial starting point for the subsequent optimization process, also known as a candidate solution. When evaluating defect prediction features, the candidate solution guides selective undersampling of the imbalanced software defect dataset.

[0063] For example, obtaining an imbalanced software defect dataset requires acquiring a software defect dataset, identifying defective and non-defective samples in the dataset based on the corresponding labeled data, and forming the imbalanced software defect dataset. Feature extraction from the imbalanced software defect dataset yields at least one software defect prediction feature, which is based on a feature selection algorithm that extracts the most predictive software defect prediction feature from the imbalanced software defect dataset.

[0064] Step 104: Generate a mutated weight vector based on the mutation of the first weight vector, and cross-combine the first weight vector and the mutated weight vector to generate a second weight vector.

[0065] For example, mutation refers to generating new mutated component vectors from all component vectors of the first weight vector through a weighted differencing operation. Specifically, the purpose of mutation is to generate new component vectors from all component vectors of the current first weight vector.

[0066] For example, cross-combination refers to crossing the mutated vector with all the sub-vectors in the current first weight vector to generate a new vector, namely the second weight vector.

[0067] Step 106: Compare each sub-vector in the first weight vector and the second weight vector, select the sub-vectors that meet the preset conditions, and form the final weight vector based on the sub-vectors that meet the preset conditions.

[0068] For example, the fitness of each sub-vector in the first weight vector and the second weight vector is evaluated, and the fitness of each sub-vector in the first weight vector and the second weight vector is compared to select the sub-vector with higher fitness to form the final weight vector.

[0069] Step 108: Based on the final weight vector, sort the samples in the imbalanced software defect dataset, remove samples that meet the preset conditions, and generate a balanced software defect dataset.

[0070] Specifically, imbalanced software defect datasets contain majority class samples and minority class samples. The majority class samples are those without defects in the imbalanced software defect dataset, while the minority class samples are those with defects in the imbalanced software defect dataset. Generally, 95%-99% of the samples in an imbalanced software defect dataset belong to the majority class, and only 1%-5% belong to the minority class.

[0071] In this context, a balanced software defect dataset refers to a software defect dataset where the majority and minority class samples are balanced through undersampling or oversampling to make the number of majority class samples equal to the number of minority class samples. Specifically, undersampling involves reducing the number of majority class samples to make it equal to the number of minority class samples before training the model; oversampling involves increasing the number of minority class samples to make it equal to the number of majority class samples before training the model.

[0072] Optionally, by selectively removing some majority class samples that meet preset conditions, the imbalanced software defect dataset can be transformed into a balanced software defect dataset.

[0073] Step 110: Use the software defect balance dataset to train the software defect prediction optimization model to obtain the software defect prediction optimization model.

[0074] For example, a balanced dataset is divided into a training set and a validation set. An appropriate machine learning algorithm is selected based on the size of the training set to learn the patterns in the training set. Then, the trained software defect model is validated using the validation set to obtain an optimized model for predicting software defects.

[0075] The above method for establishing a software defect prediction optimization model involves the following steps: First, an imbalanced software defect dataset is obtained. Features are extracted from the imbalanced dataset to obtain at least one software defect prediction feature. The correlation coefficient between this feature and its corresponding labeled data is calculated. Based on the correlation coefficient, the weights of the at least one software defect prediction feature are calculated to form a first weight vector. A mutated weight vector is generated based on the first weight vector. The first weight vector and the mutated weight vector are then combined to generate a second weight vector. Second, each component vector in the first and second weight vectors is compared, and component vectors that meet preset conditions are selected. These component vectors form the final weight vector. Third, based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet preset conditions are removed to generate a balanced software defect dataset. Finally, the balanced software defect dataset is used to train the software defect prediction optimization model to obtain the model. Therefore, by optimizing the feature weighting mechanism in the undersampling process, the undersampling process is optimized, and a software defect prediction optimization model is established. This effectively improves the accuracy and robustness of software defect prediction, helping developers to more efficiently identify and fix software defects.

[0076] In an exemplary embodiment, calculating the weights of at least one software defect prediction feature based on the correlation coefficient to form a first weight vector includes: determining the weights of at least one software defect prediction feature based on the absolute value of the correlation coefficient, and combining the weights of the at least one software defect prediction feature to generate the first weight vector.

[0077] Specifically, the absolute value of the correlation coefficient ensures that regardless of whether the linear relationship between the software defect prediction feature and the corresponding labeled data is positive or negative, the calculated weight of the software defect prediction feature will reflect the strength of its correlation with the corresponding labeled data. For example, the larger the absolute value of the correlation coefficient, the stronger the correlation between the software defect prediction feature and the corresponding labeled data, and the larger the weight of the software defect prediction feature, indicating that the software defect prediction feature is more important in the software defect prediction task.

[0078] In this embodiment, by determining the weights of software defect prediction features based on the correlation coefficient, it is possible to identify which feature is more important for the software defect prediction task. This will play a key role in the subsequent weight vector generation and sample selection process. Furthermore, the method of determining the weights by using the absolute value of the correlation coefficient ensures the objectivity and accuracy of the feature weights and avoids weight cancellation or misjudgment caused by positive and negative correlation.

[0079] In one embodiment, a mutated weight vector is generated based on the mutation of a first weight vector, and the first weight vector and the mutated weight vector are intersected to generate a second weight vector for the features of software defect prediction. This includes: based on any three component vectors of the first weight vector, introducing a mutation scaling factor to calculate the mutated weight vector; and intersecting and combining the first weight vector with multiple component vectors in the mutated weight vector to generate the second weight vector.

[0080] Specifically, three component vectors are randomly selected from the first weight vector, and a mutation scaling factor is introduced. The mutated component vectors are then calculated using the following formula:

[0081]

[0082] in, Indicates the first A mutated individual, , , It is three different sub-vectors randomly selected from the first weight vector. F is the mutation scaling factor, which is usually set between 0 and 1. All the mutated sub-vectors are combined into the mutated weight vector.

[0083] Specifically, the weight values ​​of the mutated weight vectors are determined by a certain probability when combining all the component vectors in the first weight vector with all the mutated component vectors in the mutated weight vector. The cross-combination operation calculates the component vectors of the second weight vector according to the following formula:

[0084]

[0085] in, This represents the component vector of the second weight vector, where CR is the crossover probability, typically set to 0.7 or 0.8. It is a randomly generated number. It is a randomly selected dimension, ensuring that at least one dimension comes from the mutated weight vector.

[0086] Combine all the subvectors of the second weight vector to generate the second weight vector.

[0087] In this embodiment, by introducing a mutation scaling factor to mutate the component vectors of the first weight vector, and combining the mutated component vectors with the first weight component vectors using crossover probabilities, a more diverse and adaptive second weight vector can be generated. This mutation and crossover mechanism helps to explore better solutions in the weight vector space, thereby improving the accuracy of subsequent software defect prediction models.

[0088] In one embodiment, comparing each component vector in the first weight vector and the second weight vector, selecting component vectors that meet preset conditions, and forming a final weight vector based on the component vectors that meet the preset conditions includes: evaluating the fitness of all component vectors in the first weight vector and the second weight vector based on a preset objective function; comparing the fitness of all component vectors in the first weight vector and the fitness of all component vectors in the second weight vector, selecting all component vectors whose fitness meets the preset conditions, forming a target weight vector, replacing the first weight vector with the target weight vector, and continuing to execute the steps based on any three component vectors of the first weight vector and subsequent steps until a preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold, and using the corresponding target weight vector as the final weight vector.

[0089] The preset objective function is the fitness function, which consists of multiple evaluation metrics, such as accuracy. ), accuracy ( ), recall rate ( The predictive performance of an individual is comprehensively evaluated by the harmonic mean (F-measure) of precision and recall and the area under the operating characteristic curve (AUC). The fitness function can combine the values ​​of multiple indicators into a single scoring indicator, fitness, by weighted summation.

[0090] For example, the fitness function is:

[0091]

[0092] in, , ..., It is the weight of each indicator. Let be the accuracy of all component vectors in the first and second weight vectors in the defect prediction task. For accuracy, For recall rate, The harmonic mean of precision and recall. The area under the working characteristic curve, For fitness.

[0093] Specifically, the fitness of all sub-vectors in the first weight vector and the fitness of all sub-vectors in the second weight vector are compared. Sub-vectors with higher fitness are selected, and all selected sub-vectors are used to form the target weight vector.

[0094] Specifically, the first weight vector is replaced with the target weight vector, and the steps based on any three sub-vectors of the first weight vector and the subsequent steps are continued until the preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold. The corresponding target weight vector is then used as the final weight vector. This process ensures that the target weight vector with higher fitness is selected in each iteration, and a final weight vector with the best performance is obtained. When the final weight vector appears, the iteration converges, indicating that the fitness change becomes very small or the maximum number of iterations is reached.

[0095] In this embodiment, through multiple iterations, the most suitable final weight vector is selected through evolution, enabling the final weight vector to achieve optimal performance in the software defect prediction task. This iterative evolution mechanism based on the fitness function not only improves the model's accuracy in predicting software defects but also enhances the model's robustness across different datasets. Simultaneously, this mechanism effectively avoids the local optima problem caused by improper initial weight settings in traditional methods, further improving the model's generalization ability.

[0096] In one embodiment, based on the final weight vector, samples in the imbalanced software defect dataset are sorted, and samples that meet preset conditions are removed to generate a balanced software defect dataset. This includes: the imbalanced software defect dataset contains majority class samples and minority class samples; combining the features of all samples in the imbalanced software defect dataset with the final weight vector to calculate a weighted score for all samples in the imbalanced software defect dataset; sorting all samples in the imbalanced software defect dataset based on the weighted score; keeping the number of minority class samples unchanged; removing some majority class samples that meet preset conditions; until the number of majority class samples is consistent with the number of minority class samples, thereby generating a balanced software defect dataset.

[0097] For example, by combining the features and weight vectors of all samples in the imbalanced software defect dataset, a weighted score of all samples in the imbalanced software defect dataset is calculated. Based on the weighted scores of all samples in the imbalanced software defect dataset, all samples in the imbalanced software defect dataset are sorted. The sorting result can generate a new sample list in which the samples are arranged from high to low weighted scores.

[0098] Specifically, in the sample list, since the minority class samples are few in number in the software defect imbalanced dataset and are important for model learning, it is necessary to keep the number of minority class samples unchanged. Then, select several majority class samples that contribute less to model learning and remove them according to their ranking from low to high until the number of majority class samples and minority class samples are consistent, thus achieving optimized feature weighted undersampling.

[0099] Optionally, the majority class sample features in the imbalanced software defect dataset can be combined with the final weight vector to calculate the weighted score of the majority class samples. Based on the weighted score, the majority class samples are sorted, and some majority class samples that meet the preset conditions are removed until the number of majority class samples is consistent with the number of minority class samples, thereby generating a balanced software defect dataset.

[0100] In this embodiment, a weighted score is calculated by combining the final weight vector with sample features, and the samples are ranked based on the score. Simultaneously, while keeping the number of minority class samples unchanged, some majority class samples are removed, achieving effective balancing of the imbalanced software defect dataset. This method retains the minority class samples crucial for model learning in the imbalanced software defect dataset, removes the majority class samples that contribute less to the software defect prediction model, optimizes the dataset distribution, and thus improves the efficiency and accuracy of subsequent model training. Moreover, this process ensures the balance of the dataset, helping the software defect prediction model to better learn the features of software defects, thereby improving the accuracy of software defect prediction.

[0101] In one embodiment, using a balanced software defect dataset to train an optimization model for predicting software defects to obtain an optimization model for predicting software defects includes: dividing the balanced software defect dataset into a training set and a validation set; training the software defect model using the training set; and then using the validation set to evaluate the performance of the trained software defect model to obtain an optimization model for predicting software defects.

[0102] The validation set, also known as the test set, is used to evaluate the performance of the trained software defect balance dataset, as the training set constitutes the majority of the dataset. The software defect prediction optimization model is a supervised learning model based on neural networks or support vector machines, capable of learning the patterns of potential defects in the software defect balance dataset and outputting defect prediction results.

[0103] Optionally, the software defect model can be trained using a training set. Common algorithms for this process include logistic regression, support vector machine (SVM), decision tree, and random forest. When the software defect balanced dataset is small or linearly separable, simpler algorithms such as logistic regression and support vector machine (SVM) are chosen. When the software defect balanced dataset is complex, more complex algorithms such as decision tree and random forest are chosen.

[0104] Optionally, during training, the software defect model will learn how to make predictions based on the features input to the training set. For software defect prediction problems, the model will learn the mapping relationship between the input software defect prediction features (such as code attributes, historical defect data, etc.) and the output labeled data (such as whether a defect has occurred). The model will adjust its parameters through different training techniques (such as gradient descent, regularization, etc.) to minimize the prediction error. During training, the trained software defect model is obtained by minimizing the loss function between the predicted value and the true value.

[0105] The loss function is the mean squared error (MSE) loss function, and the calculation formula is as follows:

[0106]

[0107] in, This is the actual value. For predicted values, This represents the number of samples.

[0108] Specifically, after training, the performance of the trained software defect prediction model is evaluated using a validation set to determine its predictive effectiveness.

[0109] For example, common evaluation metrics include accuracy, precision, recall, F1 score, and AUC. In the evaluation process, a confusion matrix is ​​used to visually demonstrate the predictive performance of the software defect prediction model across different categories. The confusion matrix displays the number of true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN) predicted by the software defect prediction model.

[0110] In this embodiment, the software defect balanced dataset enables the model to learn the characteristics of software defects more comprehensively during training, avoiding model bias caused by data imbalance. At the same time, the performance evaluation of the validation set can ensure the stability and reliability of the model in practical applications. The final software defect prediction optimization model can predict software defects more accurately.

[0111] The following is for reference. Figure 2 and Figure 3 The method for establishing a software defect prediction and optimization model of this application will be further illustrated by a specific embodiment.

[0112] First, obtain a software defect dataset, such as... Figure 2As shown, there are seven samples A, B, C, D, and E. Defect samples F and G and non-defect samples A, B, C, D, and E in the software defect dataset are identified by binary classification labels. Based on the software defect dataset, software defect prediction features that play an important role in defect prediction are extracted by methods such as information gain or chi-square test. Then, the data needs to be cleaned to remove irrelevant features and fill missing values ​​to obtain an imbalanced software defect dataset.

[0113] Next, the correlation coefficients between all software defect prediction features and binary classification labels are calculated. Based on the Pearson coefficient, the weights of all software defect prediction features are calculated to form a first weight vector. Based on the first weight vector, a mutation vector factor is introduced to calculate a mutation weight vector. Then, the first weight vector and the mutation weight vector are cross-combined to generate a second weight vector. Using the fitness function, the fitness of all sub-vectors in the first weight vector and the fitness of all sub-vectors in the second weight vector are calculated and compared one-to-one. The sub-vector in the weight vector with higher fitness is selected, and all sub-vectors with higher fitness are combined to form a target weight vector. Subsequently, the first weight vector is replaced with the target weight vector, and the steps based on any three sub-vectors of the first weight vector and subsequent steps are continued until the preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold. The corresponding target weight vector is then used as the final weight vector.

[0114] Next, the features of all samples in the imbalanced software defect dataset are combined with the final weight vector to calculate the weighted score of all samples in the imbalanced software defect dataset. Based on the weighted score, all samples in the imbalanced software defect dataset are sorted to obtain a new sample list in which all samples are arranged from high to low weighted score, such as... Figure 2 The dataset is composed of F, G, B, C, E, D, and A. Then, keeping the number of minority class samples F and G unchanged, the majority class samples are removed from low to high according to their ranking until the number of majority class samples is consistent with the number of minority class samples. That is, E, D, and A are removed. This generates a software defect balanced dataset, at which point only F, G, B, and C exist in the dataset.

[0115] Finally, the software defect balanced dataset is divided into training sets F, G, and B, and a validation set C. The training set data is input into the software defect prediction model, and the model parameters are optimized and updated using the gradient descent method to obtain the optimized software defect prediction model. Finally, the validation set C is used, and C is input into the obtained trained software defect prediction model to obtain the software defect prediction results. Finally, C is used to evaluate whether the prediction results of the software defect prediction model in the software defect prediction task are accurate. In this way, an accurate optimized software defect prediction model is finally obtained.

[0116] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.

[0117] Based on the same inventive concept, this application also provides an apparatus for establishing a predictive software defect optimization model to implement the method for establishing a predictive software defect optimization model as described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method. Therefore, the specific limitations of one or more apparatus embodiments for establishing a predictive software defect optimization model provided below can be found in the limitations of the method for establishing a predictive software defect optimization model above, and will not be repeated here.

[0118] In one exemplary embodiment, such as Figure 4 As shown, an apparatus 400 for establishing a predictive software defect optimization model is provided, comprising: a calculation module 402, a generation module 404, a comparison module 406, a sorting module 408, and a training module 410, wherein:

[0119] The calculation module 402 is used to acquire an imbalanced software defect dataset; perform feature extraction on the imbalanced software defect dataset to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; and calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0120] The generation module 404 is used to generate a mutated weight vector based on the mutation of the first weight vector, and to cross-combine the first weight vector and the mutated weight vector to generate a second weight vector.

[0121] The comparison module 406 is used to compare each sub-vector in the first weight vector and the second weight vector, filter out the sub-vectors that meet the preset conditions, and form a weight vector based on the sub-vectors that meet the preset conditions.

[0122] The sorting module 408 is used to sort the samples in the imbalanced software defect dataset based on the weight vector, remove samples that meet the preset conditions, and generate a balanced software defect dataset.

[0123] Training module 410 is used to train an optimization model for predicting software defects using a balanced software defect dataset, thereby obtaining an optimization model for predicting software defects.

[0124] In one embodiment, the calculation module is further configured to determine the weight of at least one software defect prediction feature based on the absolute value of the correlation coefficient, and combine the weights of the at least one software defect prediction feature to generate a first weight vector.

[0125] In one embodiment, the generation module is further configured to introduce a mutation scaling factor based on any three sub-vectors of the first weight vector, calculate the mutation weight vector, and cross-combine the first weight vector with multiple sub-vectors in the mutation weight vector to generate the second weight vector.

[0126] In one embodiment, the comparison module is further configured to evaluate the fitness of all sub-vectors in the first weight vector and the second weight vector based on a preset objective function; compare the fitness of all sub-vectors in the first weight vector and the fitness of all sub-vectors in the second weight vector, select all sub-vectors whose fitness meets a preset condition, form a target weight vector, replace the first weight vector with the target weight vector, and continue to execute the steps based on any three sub-vectors of the first weight vector and the subsequent steps until a preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold, and use the corresponding target weight vector as the final weight vector.

[0127] In one embodiment, the sorting module is further configured to: ...

[0128] In one embodiment, the training module is further configured to divide the software defect balanced dataset into a training set and a validation set; train the software defect model using the training set, and then evaluate the performance of the trained software defect model using the validation set to obtain an optimized model for predicting software defects.

[0129] Each module in the aforementioned apparatus for establishing a predictive software defect optimization model can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the corresponding operations of each module.

[0130] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 5 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores software defect data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When executed by the processor, the computer program implements a method for establishing a predictive software defect optimization model.

[0131] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0132] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0133] Obtain an imbalanced dataset of software defects; extract features from the imbalanced dataset of software defects to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0134] A mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are cross-combined to generate a second weight vector.

[0135] Compare each component vector in the first weight vector and the second weight vector, select the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions;

[0136] Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset.

[0137] The software defect balanced dataset is used to train the software defect prediction optimization model, thus obtaining the software defect prediction optimization model.

[0138] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the weights of at least one software defect prediction feature based on the absolute value of the correlation coefficient, and combining the weights of the at least one software defect prediction feature to generate a first weight vector.

[0139] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on any three sub-vectors of the first weight vector, a mutation scaling factor is introduced to calculate the mutation weight vector; the first weight vector is cross-combined with multiple sub-vectors in the mutation weight vector to generate a second weight vector.

[0140] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on a preset objective function, evaluate the fitness of all component vectors in the first weight vector and the second weight vector; compare the fitness of all component vectors in the first weight vector and the fitness of all component vectors in the second weight vector, select all component vectors whose fitness satisfies a preset condition, form a target weight vector, replace the first weight vector with the target weight vector, continue to execute any three component vectors based on the first weight vector and subsequent steps, until a preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold, and use the corresponding target weight vector as the final weight vector.

[0141] In one embodiment, when the processor executes the computer program, it further performs the following steps: the software defect imbalance dataset contains majority class samples and minority class samples; the features of all samples in the software defect imbalance dataset are combined with the final weight vector to calculate the weighted score of all samples in the software defect imbalance dataset; based on the weighted score, all samples in the software defect imbalance dataset are sorted, keeping the number of minority class samples unchanged, and removing some majority class samples that meet preset conditions until the number of majority class samples is consistent with the number of minority class samples, thereby generating a software defect balanced dataset.

[0142] In one embodiment, when the processor executes the computer program, it further performs the following steps: dividing the software defect balanced dataset into a training set and a validation set; training the software defect model using the training set, and then evaluating the performance of the trained software defect model using the validation set to obtain a predictive software defect optimization model.

[0143] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:

[0144] Obtain an imbalanced dataset of software defects; extract features from the imbalanced dataset of software defects to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0145] A mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are cross-combined to generate a second weight vector.

[0146] Compare each component vector in the first weight vector and the second weight vector, select the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions;

[0147] Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset.

[0148] The software defect balanced dataset is used to train the software defect prediction optimization model, thus obtaining the software defect prediction optimization model.

[0149] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: when the processor executes the computer program, it further performs the following steps: based on the absolute value of the correlation coefficient, it determines the weight of at least one software defect prediction feature, and combines the weights of at least one software defect prediction feature to generate a first weight vector.

[0150] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: based on any three sub-vectors of the first weight vector, a mutation scaling factor is introduced to calculate the mutation weight vector; the first weight vector is cross-combined with multiple sub-vectors in the mutation weight vector to generate a second weight vector.

[0151] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: based on a preset objective function, evaluate the fitness of all sub-vectors in the first weight vector and the second weight vector; compare the fitness of all sub-vectors in the first weight vector and the fitness of all sub-vectors in the second weight vector, select all sub-vectors whose fitness satisfies a preset condition, form a target weight vector, replace the first weight vector with the target weight vector, continue to execute any three sub-vectors based on the first weight vector and subsequent steps, until a preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold, and use the corresponding target weight vector as the final weight vector.

[0152] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: the software defect imbalance dataset contains majority class samples and minority class samples; the features of all samples in the software defect imbalance dataset are combined with the final weight vector to calculate the weighted score of all samples in the software defect imbalance dataset; based on the weighted score, all samples in the software defect imbalance dataset are sorted, keeping the number of minority class samples unchanged, and removing some majority class samples that meet preset conditions until the number of majority class samples is consistent with the number of minority class samples, thereby generating a software defect balanced dataset.

[0153] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: dividing the software defect balancing dataset into a training set and a validation set; training the software defect model using the training set, and then evaluating the performance of the trained software defect model using the validation set to obtain a predictive software defect optimization model.

[0154] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:

[0155] Obtain an imbalanced dataset of software defects; extract features from the imbalanced dataset of software defects to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector.

[0156] A mutated weight vector is generated based on the mutation of the first weight vector, and the first weight vector and the mutated weight vector are cross-combined to generate a second weight vector.

[0157] Compare each component vector in the first weight vector and the second weight vector, select the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions;

[0158] Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset.

[0159] The software defect balanced dataset is used to train the software defect prediction optimization model, thus obtaining the software defect prediction optimization model.

[0160] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: determining the weights of at least one software defect prediction feature based on the absolute value of the correlation coefficient, and combining the weights of the at least one software defect prediction feature to generate a first weight vector.

[0161] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: based on any three sub-vectors of the first weight vector, a mutation scaling factor is introduced to calculate the mutation weight vector; the first weight vector is cross-combined with multiple sub-vectors in the mutation weight vector to generate a second weight vector.

[0162] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: based on a preset objective function, evaluate the fitness of all sub-vectors in the first weight vector and the second weight vector; compare the fitness of all sub-vectors in the first weight vector and the fitness of all sub-vectors in the second weight vector, select all sub-vectors whose fitness satisfies a preset condition, form a target weight vector, replace the first weight vector with the target weight vector, continue to execute any three sub-vectors based on the first weight vector and subsequent steps, until a preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold, and use the corresponding target weight vector as the final weight vector.

[0163] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: the software defect imbalance dataset contains majority class samples and minority class samples; the features of all samples in the software defect imbalance dataset are combined with the final weight vector to calculate the weighted score of all samples in the software defect imbalance dataset; based on the weighted score, all samples in the software defect imbalance dataset are sorted, keeping the number of minority class samples unchanged, and removing some majority class samples that meet preset conditions until the number of majority class samples is consistent with the number of minority class samples, thereby generating a software defect balanced dataset.

[0164] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: dividing the software defect balancing dataset into a training set and a validation set; training the software defect model using the training set, and then evaluating the performance of the trained software defect model using the validation set to obtain a predictive software defect optimization model.

[0165] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0166] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0167] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A method for establishing a predictive software defect optimization model, characterized in that, The method includes: Obtain an imbalanced software defect dataset; perform feature extraction on the imbalanced software defect dataset to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; calculate the weight of the at least one software defect prediction feature based on the correlation coefficient, and form a first weight vector. A mutated weight vector is generated based on the mutation of the first weight vector, and a second weight vector is generated by cross-combining the first weight vector and the mutated weight vector. Compare each component vector in the first weight vector and the second weight vector, filter out the component vectors that meet the preset conditions, and form the final weight vector based on the component vectors that meet the preset conditions; Based on the final weight vector, the samples in the imbalanced software defect dataset are sorted, and samples that meet the preset conditions are removed to generate a balanced software defect dataset. The software defect balanced dataset is used to train the software defect prediction optimization model to obtain the software defect prediction optimization model. The step of generating a mutated weight vector based on the mutation of the first weight vector, and intersecting the first weight vector with the mutated weight vector to generate a second weight vector, includes: based on any three component vectors of the first weight vector, introducing a mutation scaling factor to calculate the mutated weight vector; and intersecting and combining the first weight vector with multiple component vectors of the mutated weight vector to generate a second weight vector. The step of comparing each component vector in the first weight vector and the second weight vector, selecting component vectors that meet preset conditions, and forming a final weight vector based on the component vectors that meet the preset conditions includes: evaluating the fitness of all component vectors in the first weight vector and the second weight vector based on a preset objective function; comparing the fitness of all component vectors in the first weight vector and the fitness of all component vectors in the second weight vector, selecting all component vectors whose fitness meets the preset conditions, forming a target weight vector, replacing the first weight vector with the target weight vector, and continuing to execute the steps based on any three component vectors of the first weight vector and subsequent steps until a preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold, and using the corresponding target weight vector as the final weight vector.

2. The method according to claim 1, characterized in that, The step of calculating the weights of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector includes: Based on the absolute value of the correlation coefficient, the weights of the at least one software defect prediction feature are determined, and the weights of the at least one software defect prediction feature are combined to generate a first weight vector.

3. The method according to claim 1, characterized in that, The step of sorting the samples in the imbalanced software defect dataset based on the final weight vector, removing samples that meet preset conditions, and generating a balanced software defect dataset includes: The imbalanced software defect dataset contains majority class samples and minority class samples; The features of all samples in the imbalanced software defect dataset are combined with the final weight vector to calculate the weighted score of all samples in the imbalanced software defect dataset. Based on the weighted score, all samples in the imbalanced software defect dataset are sorted, keeping the number of minority class samples unchanged, and removing some majority class samples that meet preset conditions, until the number of majority class samples is consistent with the number of minority class samples, thus generating a balanced software defect dataset.

4. The method according to claim 1, characterized in that, The step of using the balanced software defect dataset to train an optimization model for predicting software defects, thereby obtaining the optimization model for predicting software defects, includes: The software defect balanced dataset is divided into a training set and a validation set; The software defect model is trained using the training set, and then the performance of the trained software defect model is evaluated using the validation set to obtain the optimized predictive software defect model.

5. An apparatus for establishing a predictive software defect optimization model, characterized in that, The device includes: The calculation module is used to acquire an imbalanced software defect dataset; extract features from the imbalanced software defect dataset to obtain at least one software defect prediction feature; calculate the correlation coefficient between the at least one software defect prediction feature and the corresponding labeled data; and calculate the weight of the at least one software defect prediction feature based on the correlation coefficient to form a first weight vector. The generation module is used to generate a mutated weight vector based on the mutation of the first weight vector, and to cross-combine the first weight vector with the mutated weight vector to generate a second weight vector. The comparison module is used to compare each sub-vector in the first weight vector with each sub-vector in the second weight vector, filter out the sub-vectors that meet the preset conditions, and form the final weight vector based on the sub-vectors that meet the preset conditions. The sorting module is used to sort the samples in the imbalanced software defect dataset based on the final weight vector, remove samples that meet preset conditions, and generate a balanced software defect dataset. The training module is used to train the software defect balanced dataset to predict the software defect optimization model, thereby obtaining the software defect prediction optimization model. The generation module is further configured to, based on any three component vectors of the first weight vector, introduce a mutation scaling factor to calculate the mutated weight vector; and cross-combine the first weight vector with multiple component vectors in the mutated weight vector to generate a second weight vector. The comparison module is further configured to evaluate the fitness of all sub-vectors in the first weight vector and the second weight vector based on a preset objective function; compare the fitness of all sub-vectors in the first weight vector with the fitness of all sub-vectors in the second weight vector, select all sub-vectors whose fitness satisfies a preset condition, form a target weight vector, replace the first weight vector with the target weight vector, and continue to execute the steps based on any three sub-vectors of the first weight vector and subsequent steps until a preset maximum number of iterations is reached or the fitness improvement reaches a preset threshold, and use the corresponding target weight vector as the final weight vector.

6. The apparatus according to claim 5, characterized in that, The calculation module is also used to determine the weight of the at least one software defect prediction feature based on the absolute value of the correlation coefficient, and combine the weights of the at least one software defect prediction feature to generate a first weight vector.

7. The apparatus according to claim 5, characterized in that, The sorting module is further configured to: include majority class samples and minority class samples in the imbalanced software defect dataset; combine the features of all samples in the imbalanced software defect dataset with the final weight vector to calculate the weighted score of all samples in the imbalanced software defect dataset; sort all samples in the imbalanced software defect dataset based on the weighted score, keep the number of minority class samples unchanged, remove some majority class samples that meet preset conditions, until the number of majority class samples is consistent with the number of minority class samples, and generate a balanced software defect dataset.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 4.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Cross-project software defect prediction method for sorting tasks, electronic equipment and medium

    CN118550825A

  • Aging defect prediction method for intra-class and inter-class height imbalance

    CN118839249A