Automobile software defect prediction method based on dynamic feature selection and oversampling

Through the granular decision-making entropy dynamic evaluation of feature importance and the intelligent resampling algorithm balanced samples, the problems of simple feature selection and sample imbalance in the existing technology are solved, and the accuracy and generalization ability of automotive software defect prediction are improved.

CN119088700APending Publication Date: 2024-12-06CHONGQING UNIV

Patent Information

Application Number
CN202411208369.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

In the existing automotive software defect prediction method, feature selection is too simple, and the dynamic relationship between features and decision-making features is not considered, which leads to the model being unable to focus on learning key information and cannot effectively balance sample quality and diversity, resulting in the model being in multiple categories and There is insufficient overfitting or generalization capability in a mixed-type data environment.

Method used

The contribution of each feature to the decision feature dynamically evaluates the contribution of each feature to the decision feature, retains important features through dynamic feature selection, and generates new samples for a few types of samples by introducing intelligent resampling algorithms with auxiliary loss and diversity loss, balancing sample quality and diversity , thereby improving the accuracy and generalization ability of the model's defect prediction.

Benefits of technology

Through dynamic feature selection and supersampling technology, the model can focus more on learning key information, improve the interpretability and accuracy of defect prediction, enhance the classification performance and generalization capabilities in multi-class and mixed-type data environments, and reduce the computational complexity And speed up the training process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088700A_ABST
    Figure CN119088700A_ABST
Patent Text Reader

Abstract

The invention discloses an automobile software defect prediction method based on dynamic feature selection and oversampling, which comprises the following steps: acquiring a data set of automobile software defects, and defining a full feature set of the data set; performing data preprocessing on the data set, and dividing the data set into a training set and a test set; dynamically evaluating the contribution of each feature in the full feature set to a decision feature through a granularity decision entropy algorithm, and reserving important features with high information gain; new samples are generated for the minority class samples by introducing an intelligent resampling algorithm of auxiliary loss and diversity loss, and the representativeness and diversity of the minority class samples are enhanced; training the defect prediction model through the training set and testing the test set; and outputting a corresponding defect prediction result based on the characteristic data of the automobile software through the trained defect prediction model. According to the method, the accuracy of automobile software defect prediction and the generalization ability of the model in new data or multi-class and mixed type data environments can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of automobile software defect detection, and in particular to an automobile software defect prediction method based on dynamic feature selection and oversampling. Background Art

[0002] With the increasing degree of automobile electrification, modern cars contain a large number of software and electronic systems, which are responsible for controlling the engine, transmission system, airbag, sound system, driving assistance system, etc., and many cars also support autonomous driving technology. Therefore, software quality and security are crucial to the performance of the car and the safety of passengers.

[0003] In the future, a car's code will reach 500 million lines, so there are inherent risks associated with software in terms of quality, security and privacy. Enterprises need to adopt various software development tools and programs to help developers develop safer and higher-quality software, including using static code analysis tools to reduce quality and security issues in self-developed code, and using software component analysis tools to identify unknown vulnerabilities in open source software. Software-based solutions have brought many benefits to the automotive industry. Using software to drive the various functions of a car can reduce costs, and automotive software defect prediction can better ensure the implementation of software development.

[0004] The patent document with publication number CN115599698A discloses an instant software defect prediction method based on dynamic classifier selection. This method aims at the verification delay, concept drift and class imbalance problems existing in the prior art, and corrects the data labels through the verification delay framework. Then, the data within the project and the cross-project data are filtered and combined to alleviate concept drift while avoiding the prediction bias caused by cross-project data. Then, hierarchical AdaBoost is integrated based on the dynamic classifier selection method, and the classifier trained with the previous data is used to predict the label of the subsequent data. The training prediction process is iterated to solve the problem of imbalanced class distribution of the data stream. Finally, the processed data set is used to train the instant software defect prediction model, effectively improving the prediction performance of the model.

[0005] The patent document with publication number CN116401143A discloses a software testing method and system based on an unbalanced data set, and the method includes the following steps: obtaining sample data of unbalanced software defects and preprocessing the sample data; setting cost sensitivity coefficients for data categories in the sample data according to the imbalance characteristics of the sample data after preprocessing; training a cost-sensitive kernel width learning system classification model according to the sample data including the cost sensitivity coefficient; determining the optimal penalty coefficient through grid search, and determining the target parameters of the model according to the optimal penalty coefficient; constructing a target classification model according to the target parameters, classifying and predicting the test instances through the target classification model, and outputting the prediction results.

[0006] The patent document with publication number CN114490386A discloses a software defect prediction method and system based on information entropy oversampling, the method comprising: obtaining a software defect data set; dividing the data set into a training set and a test set, and calculating the class deterministic entropy of majority class samples and minority class samples in the training set; dividing the majority class samples and minority class samples into safe samples, key samples, and dangerous samples according to the class deterministic entropy, and selecting minority class key samples as seed samples; removing majority class dangerous samples; constraining oversampling of local neighborhoods of minority class key samples; training a software defect prediction model with a new balanced training set, and testing the test set.

[0007] However, the applicant found that the above-mentioned prior art still has the following problems: 1) The feature selection for automotive software defect prediction is too simple, and the dynamic relationship between features (attributes) and decision features (attributes) is not considered, resulting in the model being unable to focus on learning key information. 2) It is unable to effectively balance sample quality and diversity, resulting in the model being overfitted or having insufficient model generalization ability in multi-class and mixed-type data environments. Summary of the invention

[0008] In view of the deficiencies of the above-mentioned prior art, the technical problem to be solved by the present invention is: how to provide an automotive software defect prediction method based on dynamic feature selection and oversampling, dynamically evaluate the contribution of each feature to the decision feature through granular decision entropy, so that the model can focus more on learning key information; generate new samples for minority class samples by introducing an intelligent resampling algorithm with auxiliary loss and diversity loss, and balance the quality and diversity of minority class samples, thereby improving the defect prediction accuracy of the model and its generalization ability in new data or multi-class and mixed type data environments.

[0009] In order to solve the above technical problems, the present invention adopts the following technical solutions:

[0010] A method for predicting automotive software defects based on dynamic feature selection and supersampling, comprising:

[0011] S1: Obtain a dataset of automotive software defects and define the full feature set of the dataset;

[0012] S2: After data preprocessing, the data set is divided into a training set and a test set;

[0013] S3: Perform dynamic feature selection on the training samples in the training set: dynamically evaluate the contribution of each feature in the entire feature set to the decision feature through the granular decision entropy algorithm, and retain important features with high information gain;

[0014] S4: Supersampling the training set: Generate new samples for minority class samples by introducing an intelligent resampling algorithm with auxiliary loss and diversity loss to enhance the representativeness and diversity of minority class samples;

[0015] S5: train the defect prediction model using the processed training set and test the test set;

[0016] S6: Output corresponding defect prediction results based on the characteristic data of the automotive software through the trained defect prediction model.

[0017] Preferably, in step S1, the full feature set includes the following features: number of code lines x1, number of blank lines x2, number of executable lines x3, number of comment lines x4, number of paths x5, basic cyclomatic complexity x6, maximum nesting depth x7, average response time x8, RT 、CPU usage x CPU , Hardware interface error rate x HW 、Memory usage x MU .

[0018] Preferably, in step S2, data preprocessing includes data cleaning and data standardization.

[0019] Preferably, in step S2, 80% of the data set is used as a training set and 20% as a test set.

[0020] Preferably, in step S3, the processing steps of the granular decision entropy algorithm are as follows:

[0021] S301: Select several random feature subsets S from the full feature set n , n is the feature subset S n size;

[0022] S302: For each feature subset S n , calculate the granular decision entropy GDE(D,S n );

[0023] The formula is:

[0024]

[0025] Where: Represented by the feature subset S n The resulting equivalence class division of the data set U; p(E) represents the probability that an object in the equivalence class E belongs to the decision feature D;

[0026] S303: Select GDE (D, S n The target feature subset S is the one with the smallest difference between ) and GDE(D,C). n ;

[0027] The formula is:

[0028]

[0029] GDE(D, C) = ∑ E′∈IND(C) p(E′)log2p(E′);

[0030] Where: IND(C) represents the equivalence class division caused by the full feature set C; p(E′) represents the probability that the object in the equivalence class E′ belongs to the decision feature D;

[0031] S304: Through the target feature subset S n Generate an approximate reduction set R of the full feature set C; the features in the approximate reduction set R are important features;

[0032] The formula is:

[0033] R = {a∈S n |Significance(a,S n \{a},D)>τ};

[0034] Significant ce (a,S n \{a},D)=GDE(D,S n \{a})GDE(D,S n );

[0035]

[0036] Where: Significance(a,S n \{a},D) represents the function used to measure the feature a in the feature subset S n The function of the influence of decision feature D in IND(S n \{a} means the feature subset S after removing feature a n The equivalence class partitioning caused by GDE(D,S n ) represents the feature subset S n The granular decision entropy associated with the decision feature D; τ represents the threshold parameter.

[0037] Preferably, in step S301, the feature subset S is selected by feature importance scoring, expert knowledge method or data-driven method. n The size of n.

[0038] Preferably, in step S4, the specific steps of supersampling are as follows:

[0039] S401: Identify majority class samples and minority class samples in the data set;

[0040] S402: introducing the minority class sample input into the variational autoencoder model trained by the auxiliary loss function and the diversity loss function, and generating new samples through the variational autoencoder model;

[0041] S403: Repeat S401 to S402 until the majority class samples and minority class samples in the data set are balanced.

[0042] Preferably, in step S402, the variational autoencoder model is trained by the following steps:

[0043] S4021: Constructing auxiliary loss functions for variational autoencoder models

[0044] The formula is:

[0045]

[0046] Where: represents the normalized Euclidean distance function, which is used to calculate the distance between samples a and b; s j represents the generated new sample; t and m represent the feature vectors of the input minority class sample and the generated new sample respectively; T i 、M i Represents the i-th feature in the feature vector;

[0047] S4022: Constructing a Diversity Loss Function for a Variational Autoencoder Model

[0048] The formula is:

[0049]

[0050] Where: Represents the mean vector t of the minority class sample set j And the generated new samples s j The cosine similarity between ;

[0051] S4023: Combining the auxiliary loss function and the diversity loss function with the reconstruction loss function of the variational autoencoder model itself to form the overall target loss function of the variational autoencoder model;

[0052]

[0053] Where: represents the overall target loss; o Cross represents the reconstruction loss of the variational autoencoder model itself; α, β, and γ represent the weights of auxiliary loss, diversity loss, and reconstruction loss, respectively;

[0054] S4024: During the training process of the variational autoencoder model, solving the overall target loss function by a gradient descent method, and reversely optimizing the parameters of the variational autoencoder model;

[0055] The formula is:

[0056]

[0057] Where: S represents all generated new sample sets; s j is a single generated new sample;

[0058] S4025: During the training of the variational autoencoder model, dynamically adjust the weights of the auxiliary loss, diversity loss, and reconstruction loss according to the quality and diversity of the new samples generated;

[0059] S4026: Repeat S4024 to S4025 until the variational autoencoder model converges or reaches a preset number of iterations.

[0060] Preferably, in step S5, the defect prediction model includes several base classifiers trained using a random forest model, a decision tree model or an XGBoost model.

[0061] Preferably, in step S5, the training steps of the defect prediction model are as follows:

[0062] S501: Define parameter grid: For each base classifier, define the possible value range of each parameter;

[0063] S502: Systematically test each combination: for each base classifier, train each parameter combination in the parameter grid of the base classifier through the training set, and evaluate the performance of each parameter combination through cross-validation;

[0064] S503: Evaluate model performance: For each base classifier, evaluate the performance of each parameter combination of the base classifier through the test set;

[0065] S504: Select optimal parameters: select the parameter combination with the best performance for each base classifier as its model parameters;

[0066] S505: Apply each base classifier to the test set for testing to obtain the prediction result of each base classifier; select the prediction result with the largest number of occurrences as the defect prediction result finally output by the defect prediction model through a majority voting strategy.

[0067] Compared with the prior art, the automotive software defect prediction method based on dynamic feature selection and supersampling in the present invention has the following beneficial effects:

[0068] The present invention performs dynamic feature selection processing on the training samples in the training set. First, the contribution of each feature to the decision feature is dynamically evaluated through the granular decision entropy algorithm, and then those features with high information gain (the most influential) are screened and retained, and noise and redundant features are excluded, so that the model can focus more on learning key information, thereby improving the generalization ability of the model on new data. Secondly, the features with high information gain are retained to ensure the retention of key information in the decision-making process, so that the model can more effectively capture the key patterns in the data during the training process. These patterns are crucial for distinguishing defective and non-defective software samples, thereby improving the interpretability and accuracy of the model defect prediction. Finally, reducing the number of features directly reduces the computational complexity of the model, so that the amount of data that the model needs to process during the training process is reduced, thereby accelerating the training process; at the same time, through the dynamically selected key features, the decision-making process of the model is more transparent and explainable.

[0069] The present invention performs oversampling on the training set. First, by using the oversampling technology to generate new samples for minority class samples, the problem of data imbalance can be effectively alleviated, so that the model can learn the characteristics of each category equally during the training process, avoiding the prediction bias caused by data imbalance. Secondly, the intelligent resampling algorithm can accurately identify and strengthen the minority class characteristics by introducing auxiliary loss and diversity loss, ensuring that the generated new samples can represent the characteristics of the original minority class samples and have certain differences, balancing the quality and diversity of minority class samples, thereby improving the classification performance and generalization ability of the model in multi-class and mixed-type data environments. Finally, by optimizing the overall objective function of the intelligent resampling algorithm, the overlapping area between minority class samples and majority class samples is reduced, which helps the model to more clearly divide the boundaries of different categories, thereby improving the accuracy and robustness of classification; at the same time, through the training set after oversampling processing, the model can learn a more comprehensive and balanced data distribution, thereby improving its performance on the test set.

[0070] The defect prediction model of the present invention includes several base classifiers trained separately using a random forest model, a decision tree model or an XGBoost model. First, multiple base classifiers are used for integrated learning, and the advantages of different classifiers can be used to complement each other, thereby effectively improving the robustness and accuracy of the model. Secondly, integrated learning can reduce the error caused by data fluctuations or noise in a single classifier by combining the prediction results of multiple base classifiers, thereby improving the stability and reliability of the model; at the same time, different base classifiers have their own characteristics and advantages. Through integrated learning, a suitable classifier combination can be selected according to specific application scenarios and requirements to achieve the best prediction effect (for example, random forest or XGBoost is selected when processing high-dimensional data; decision trees can be selected in scenarios that require high interpretability). Finally, by integrating the prediction results of multiple base classifiers and fusing them using voting or weighted average, the prediction accuracy and robustness of the model can be further improved, which is particularly important for application scenarios such as automotive software defect prediction that require extremely high accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] In order to make the purpose, technical solution and advantages of the invention more clear, the present invention will be further described in detail below with reference to the accompanying drawings, in which:

[0072] Figure 1 and Figure 2 They are respectively the flow chart and logic block diagram of the automotive software defect prediction method based on dynamic feature selection and oversampling. DETAILED DESCRIPTION

[0073] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but only represents selected embodiments of the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention.

[0074] The following is a further detailed description through specific implementation methods:

[0075] Example:

[0076] This embodiment discloses an automobile software defect prediction method based on dynamic feature selection and oversampling.

[0077] like Figure 1 and Figure 2 As shown in the figure, the automotive software defect prediction method based on dynamic feature selection and super sampling includes:

[0078] S1: Obtain a dataset of automotive software defects and define the full feature set (also called full attribute set) of the dataset;

[0079] S2: After data preprocessing, the data set is divided into a training set and a test set;

[0080] S3: Perform dynamic feature (in this embodiment, features can also be called "attributes") selection processing on the training samples in the training set: dynamically evaluate the contribution of each feature in the entire feature set to the decision attribute (decision attribute refers to the attribute used to judge, classify or predict the target variable (or called category, label), which is predetermined according to the data set) through the granular decision entropy algorithm, and retain important features with high information gain;

[0081] S4: Supersampling the training set: Generate new samples for minority class samples by introducing an intelligent resampling algorithm with auxiliary loss and diversity loss to enhance the representativeness and diversity of minority class samples; At the same time, reduce the overlap between minority class samples and majority class samples by optimizing the overall objective function of the intelligent resampling algorithm;

[0082] S5: train the defect prediction model using the processed training set and test the test set;

[0083] S6: Output the corresponding defect prediction results based on the characteristic data of the automobile software through the trained defect prediction model. The characteristic data of the automobile software refers to the important features dynamically selected in step S3, such as the number of executable lines x3, the number of comment lines x4, the number of paths x5, the basic cyclomatic complexity x6, and the CPU usage x CPU , Hardware interface error rate x HW 、Memory usage x MU And other features.

[0084] The present invention performs dynamic feature selection processing on the training samples in the training set. First, the contribution of each feature to the decision feature is dynamically evaluated through the granular decision entropy algorithm, and then those features with high information gain (the most influential) are screened and retained, and noise and redundant features are excluded, so that the model can focus more on learning key information, thereby improving the generalization ability of the model on new data. Secondly, the features with high information gain are retained to ensure the retention of key information in the decision-making process, so that the model can more effectively capture the key patterns in the data during the training process. These patterns are crucial for distinguishing defective and non-defective software samples, thereby improving the interpretability and accuracy of the model defect prediction. Finally, reducing the number of features directly reduces the computational complexity of the model, so that the amount of data that the model needs to process during the training process is reduced, thereby accelerating the training process; at the same time, through the dynamically selected key features, the decision-making process of the model is more transparent and explainable.

[0085] The present invention performs oversampling on the training set. First, by using the oversampling technology to generate new samples for minority class samples, the problem of data imbalance can be effectively alleviated, so that the model can learn the characteristics of each category equally during the training process, avoiding the prediction bias caused by data imbalance. Secondly, the intelligent resampling algorithm can accurately identify and strengthen the minority class characteristics by introducing auxiliary loss and diversity loss, ensuring that the generated new samples can represent the characteristics of the original minority class samples and have certain differences, balancing the quality and diversity of minority class samples, thereby improving the classification performance and generalization ability of the model in multi-class and mixed-type data environments. Finally, by optimizing the overall objective function of the intelligent resampling algorithm, the overlapping area between minority class samples and majority class samples is reduced, which helps the model to more clearly divide the boundaries of different categories, thereby improving the accuracy and robustness of classification; at the same time, through the training set after oversampling processing, the model can learn a more comprehensive and balanced data distribution, thereby improving its performance on the test set.

[0086] The defect prediction model of the present invention includes several base classifiers trained separately using a random forest model, a decision tree model or an XGBoost model. First, multiple base classifiers are used for integrated learning, and the advantages of different classifiers can be used to complement each other, thereby effectively improving the robustness and accuracy of the model. Secondly, integrated learning can reduce the error caused by data fluctuations or noise in a single classifier by combining the prediction results of multiple base classifiers, thereby improving the stability and reliability of the model; at the same time, different base classifiers have their own characteristics and advantages. Through integrated learning, a suitable classifier combination can be selected according to specific application scenarios and requirements to achieve the best prediction effect (for example, random forest or XGBoost is selected when processing high-dimensional data; decision trees can be selected in scenarios that require high interpretability). Finally, by integrating the prediction results of multiple base classifiers and fusing them using voting or weighted average, the prediction accuracy and robustness of the model can be further improved, which is particularly important for application scenarios such as automotive software defect prediction that require extremely high accuracy.

[0087] In order to better introduce the technical solution of the present invention, this embodiment is described through the following parts.

[0088] 1. Data Collection

[0089] In this embodiment, the full feature set includes the following features (or attributes): number of code lines x1, number of blank lines x2, number of executable lines x3, number of comment lines x4, number of paths x5, basic cyclomatic complexity x6, maximum nesting depth x7, average response time x8, and so on. RT 、CPU usage x CPU , Hardware interface error rate x HW 、Memory usage x MU .

[0090] Collect historical data on automotive software defects, including NASA public data sets and data sets from actual automotive software provided by a certain car company. These data have been processed. Since the required training model is a neural network model, the metrics (i.e., features or attributes) of the defect data training set and the defect data test set include:

[0091] Number of lines of code (x1): The total number of lines of code in the code file, including code, comments, and blank lines.

[0092] Number of blank lines (x2): The number of blank lines in the code file.

[0093] Executable lines (x3): The number of lines actually executed in the code file, excluding comments and blank lines.

[0094] Number of comment lines (x4): The number of comment lines in the code file.

[0095] Number of paths (x5): The number of execution paths of the program. A path is a feasible execution path from the starting point to the end point of the program.

[0096] Basic Cyclomatic Complexity (x6): The sum of the cyclomatic complexities of all basic blocks in a program. A basic block is the smallest executable unit in a program that does not contain branch statements or loop statements. Cyclomatic complexity is a measure of program complexity that represents the number of nodes in the program flow graph.

[0097] Maximum nesting depth (x7): The deepest nesting level in the program, which reflects the structural complexity of the code and the design ability of the programmer.

[0098] This embodiment also includes metrics (i.e., features or attributes) specific to automotive software:

[0099] Average response time (x RT ): Measures the program's response and processing capabilities to real-time requirements

[0100] CPU usage (x CPU ): Measures how effectively a program uses resources.

[0101] Hardware interface error rate (x HW ): Measures how well the software uses hardware interfaces and features.

[0102] Memory usage (x MU ): Measures the extent to which a program occupies memory resources while running.

[0103] 2. Data Processing and Division

[0104] In this embodiment, data preprocessing includes data cleaning and data standardization.

[0105] Data cleaning: Identify and handle missing values: Missing data can be handled by interpolation, deletion, or estimation. Correct errors and outliers: Check the consistency and accuracy of the data and correct obvious errors and outliers.

[0106] Data standardization: Use the MinMaxScaler method to normalize the feature data to ensure that all numerical features are on the same scale to improve the stability and performance of model training. Assume that T is a feature in the original dataset, t scaled is the scaled eigenvalue. Then, for each value t in T, its scaled value t scaled , the formula of MinMaxScaler is as follows:

[0107]

[0108] Where min(T) is the minimum value in T, and max(T) is the maximum value in T.

[0109] Specifically, 80% of the data set is used as a training set and 20% as a test set. The training set is used as a data sample for model fitting. Different models are trained using the training set by trying different methods and ideas. The test set is used to evaluate the generalization ability of the final model.

[0110] 3. Granular Decision Entropy (GDE) Algorithm

[0111] In this embodiment, the processing steps of the granular decision entropy algorithm are as follows:

[0112] S301: Select several random feature subsets S from the full feature set n , n is the feature subset S n The size of feature subset S is selected by specific heuristic methods including feature importance scoring, expert knowledge or data-driven methods. n The size of n.

[0113] In this embodiment, the full feature set C = {x1,x2,x3,x4,x5,x6,x7,x RT ,x CPU ,x HW ,x MU}.

[0114] S302: For each feature subset S n , calculate the granular decision entropy GDE(D,S n );

[0115] In this embodiment, granular decision entropy (GDE) is a metric that evaluates the uncertainty of decision features given a subset of features.

[0116] The formula is:

[0117]

[0118] Where: Represented by the feature subset S n The resulting equivalence class division of the data set U (U is used to represent the sample space of the entire data set, which contains all data instances); p(E) represents the probability that an object in the equivalence class E belongs to the decision feature D; equivalence classes divide the data set U into several subsets based on these features.

[0119] In this embodiment, in the granular decision entropy algorithm, equivalence partitioning refers to the process of partitioning a data set according to the granularity of a decision attribute (i.e., different values ​​or classifications of a decision attribute), which helps to simplify the problem, reduce the amount of computation, and help to discover laws and patterns in the data. An equivalence class refers to a subset of input conditions, and the data in the set are equivalent in revealing errors in a program (in software testing) or contributing to the decision process (in the granular decision entropy algorithm).

[0120] S303: Select GDE (D, S n The target feature subset S is the one with the smallest difference between ) and GDE(D,C). n ;

[0121] The formula is:

[0122]

[0123] GDE(D,C)=∑ E′∈IND(C) p(E')log2 p(E');

[0124] Where: IND(C) represents the equivalence class division caused by the full feature set C; p(E′) represents the probability that the object in the equivalence class E′ belongs to the decision feature D. The equivalence class is a feature set grouping jointly determined by all features in the full feature set C;

[0125] In this embodiment, we hope that GDE(D, S) is close to GDE(D, U). The purpose of the above optimization problem is to find a feature subset that can retain the decision feature information to the greatest extent.

[0126] S304: Through the target feature subset S n Generate an approximate reduction set R of the full feature set C; the features in the approximate reduction set R are important features; the calculation of the approximate reduction set is to find a feature subset as small as possible while retaining the information that has the greatest impact on the decision-making features. The features in the approximate reduction set are considered to be the most important for the decision-making process because they retain the main information required for the decision-making features, help simplify the model, reduce overfitting, and improve the model's interpretability and operating efficiency.

[0127] The formula is:

[0128] R = {a∈S n |significance(a,S n \{a},D)>t};

[0129] Significance(a,S n \{a},D)=GDE(D,S n \{a})-GDE(D,Sn );

[0130]

[0131] Where: Significance(a,S n \{a},D) represents the function used to measure the feature a in the feature subset S n The function of the influence on the decision feature D in , the larger the information gain, the more important the feature a is considered to be for classification, and therefore has a higher Significance; IND(S n \{a} means the feature subset S after removing feature a n The equivalence class partitioning caused by GDE(D,S n ) represents the feature subset S n The granular decision entropy associated with the decision feature D; τ represents the threshold parameter.

[0132] For the generation of the approximate reduction set, we consider the impact of each feature on the decision feature D and retain those features whose contribution exceeds a certain threshold. In this way, we not only reduce the dimension of the data, but also ensure that the features that have a significant impact on the target variable are retained, and prepare a high-quality feature set for subsequent model training. The present invention can dynamically evaluate the contribution of each feature to the decision feature and retain those features with high information gain, which not only reduces the complexity of the model, but also ensures the retention of key information in the decision-making process.

[0133] 4. Supersampling

[0134] In this embodiment, the specific steps of supersampling are as follows:

[0135] S401: Identify majority class samples and minority class samples in the data set;

[0136] S402: introducing the minority class sample input into the variational autoencoder model trained by the auxiliary loss function and the diversity loss function, and generating new samples through the variational autoencoder model;

[0137] In this embodiment, the variational autoencoder model (VAEs) used includes an encoder and a decoder. Encoder: maps the input sample to a low-dimensional representation (i.e., embedding) in a latent space, which should be able to capture the key features of the input data. Decoder: reconstructs the input sample from the representation in the latent space. The goal of the decoder is to restore the original input as accurately as possible.

[0138] The training steps of the variational autoencoder model are as follows:

[0139] 1) Input the input sample into the encoder of the variational autoencoder model to obtain the representation in the latent space.

[0140] 2) The latent representation is fed into the decoder to reconstruct the input sample.

[0141] 3) Calculate reconstruction loss, auxiliary loss and diversity loss.

[0142] 4) All loss terms are combined into the total loss and the parameters of the variational autoencoder model are updated through the back-propagation algorithm.

[0143] After training is completed, new representations can be randomly sampled from the latent space and fed into the decoder to generate new samples. Since the latent space of the variational autoencoder model is continuous, an infinite number of new samples can be generated that have a certain degree of diversity while maintaining similarity to the original dataset.

[0144] S403: Repeat S401 to S402 until the majority class samples and minority class samples in the data set are balanced.

[0145] In this embodiment, a density-based clustering method (such as DBSCAN (Density-Based Spatial Clustering of Applications with Noise) or a density peak-based clustering algorithm (such as CFSFDP, Clustering by Fast Search and Find of Density Peaks) can be selected to identify majority class samples and minority class samples in the data set.

[0146] The formula is:

[0147] C=Cluster(X, method='CFSFDP');

[0148] Where: C represents the clustering result obtained from the data set X; method represents the clustering method used.

[0149] Specifically, the CFSFDP clustering algorithm is used to identify different subsets in the minority class sample set and the majority class sample set from the data set, such as internal samples, boundary samples and trap samples.

[0150] For minority class samples belonging to internal samples and boundary samples, new samples are generated by interpolation method.

[0151] For the trap samples, the variational autoencoder model in step S402 is used to generate new samples, ensuring that the new samples are similar to their corresponding trap samples, but have a certain distance from the majority samples to reduce noise.

[0152] The majority class samples are clustered again, and the majority samples located at the boundaries and traps are removed to expand the boundaries between categories.

[0153] Specifically, the variational autoencoder model is trained through the following steps:

[0154] S4021: Constructing auxiliary loss functions for variational autoencoder models The auxiliary loss targets the similarity loss between minority class samples and generated samples. The purpose is to make the generated samples as close as possible to the real minority class samples, thereby improving their representativeness and effectiveness.

[0155] The formula is:

[0156]

[0157] Where: represents the normalized Euclidean distance function, which is used to calculate the distance between samples a and b; s j represents the generated new sample; t and m represent the feature vectors of the input minority class sample and the generated new sample respectively; T i 、M i Represents the i-th feature in the feature vector;

[0158] S4022: Constructing a Diversity Loss Function for a Variational Autoencoder Model Diversity loss targets the difference loss between generated samples, ensuring that the generated samples are not too similar, thereby enhancing the generalization ability of the model.

[0159] The formula is:

[0160]

[0161] Where: Represents the mean vector t of the minority class sample set j And the generated new samples s j The cosine similarity between ;

[0162] S4023: Combining the auxiliary loss function and the diversity loss function with the reconstruction loss function of the variational autoencoder model itself to form the overall target loss function of the variational autoencoder model;

[0163]

[0164] Where: represents the overall target loss; o Cross represents the reconstruction loss of the variational autoencoder model itself; α, β, and γ represent the weights of auxiliary loss, diversity loss, and reconstruction loss, respectively;

[0165] In this embodiment, the reconstruction loss is calculated by a cross entropy loss function.

[0166] S4024: During the training process of the variational autoencoder model, solving the overall target loss function by a gradient descent method, and reversely optimizing the parameters of the variational autoencoder model;

[0167] The formula is:

[0168]

[0169] Where: S represents all generated sample sets; s j is a single generated sample.

[0170] In this embodiment, the characteristics of the generated samples are adjusted by minimizing the overall objective function to achieve the best supersampling effect.

[0171] S4025: During the training of the variational autoencoder model, dynamically adjust the weights of the auxiliary loss, diversity loss, and reconstruction loss according to the quality and diversity of the new samples generated;

[0172] S4026: Repeat S4024 to S4025 until the variational autoencoder model converges or reaches a preset number of iterations.

[0173] 5. Model training and integration

[0174] In this embodiment, the defect prediction model includes several base classifiers trained using a random forest (RF) model, a decision tree model, or an XGBoost (XGB) model.

[0175] Specifically, the training steps of the defect prediction model are as follows:

[0176] S501: Define parameter grid: For each base classifier, define the possible value range of each parameter;

[0177] S502: Systematically test each combination: for each base classifier, train each parameter combination in the parameter grid of the base classifier through the training set, and evaluate the performance of each parameter combination through cross-validation;

[0178] S503: Evaluate model performance: For each base classifier, evaluate the performance of each parameter combination of the base classifier through the test set;

[0179] S504: Select optimal parameters: select the parameter combination with the best performance for each base classifier as its model parameters;

[0180] S505: Apply each base classifier to the test set for testing to obtain the prediction result of each base classifier; select the prediction result with the largest number of occurrences as the defect prediction result finally output by the defect prediction model through a majority voting strategy.

[0181] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit the technical solution. Those skilled in the art should understand that those modifications or equivalent substitutions of the technical solution of the present invention that do not depart from the purpose and scope of the technical solution should be included in the scope of the claims of the present invention.

Claims

1. A method for predicting automotive software defects based on dynamic feature selection and supersampling, characterized in that: include: S1: Obtain a dataset of automotive software defects and define the full feature set of the dataset; S2: After data preprocessing, the data set is divided into a training set and a test set; S3: Perform dynamic feature selection on the training samples in the training set: dynamically evaluate the contribution of each feature in the entire feature set to the decision feature through the granular decision entropy algorithm, and retain important features with high information gain; S4: Supersampling the training set: Generate new samples for minority class samples by introducing an intelligent resampling algorithm with auxiliary loss and diversity loss to enhance the representativeness and diversity of minority class samples; S5: train the defect prediction model using the processed training set and test the test set; S6: Output corresponding defect prediction results based on the characteristic data of the automotive software through the trained defect prediction model.

2. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 1, characterized in that: In step S1, the full feature set includes the following features: number of code lines x1, number of blank lines x2, number of executable lines x3, number of comment lines x4, number of paths x5, basic cyclomatic complexity x6, maximum nesting depth x7, average response time x8, and so on. RT 、CPU usage x CPU , Hardware interface error rate x HW 、Memory usage x MU .

3. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 1, characterized in that: In step S2, data preprocessing includes data cleaning and data standardization.

4. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 1, characterized in that: In step S2, 80% of the data set is used as a training set and 20% as a test set.

5. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 1, characterized in that: In step S3, the processing steps of the granular decision entropy algorithm are as follows: S301: Select several random feature subsets S from the full feature set n , n is the feature subset S n size; S302: For each feature subset S n , calculate the granular decision entropy GDE(D,S n ); The formula is: Where: Represented by the feature subset S n The resulting equivalence class division of the data set U; p(E) represents the probability that an object in the equivalence class E belongs to the decision feature D; S303: Select GDE (D, S n ) with the smallest difference with GDE(D,C) as the target feature subset S n ; The formula is: GDE(D,C)=∑ E′∈IND(C) p(E′)log2p(E′); Where: IND(C) represents the equivalence class division caused by the full feature set C; p(E′) represents the probability that the object in the equivalence class E′ belongs to the decision feature D; S304: Through the target feature subset S n Generate an approximate reduction set R of the full feature set C; the features in the approximate reduction set R are important features; The formula is: R={a∈S n |Significance(a,S n \{a},D)>τ}; Significance(a,S n \{a},D)=GDE(D,S n \{a})-GDE(D,S n ); Where: Significance(a,S n \{a},D) represents the function used to measure the feature a in the feature subset S n The function of the influence of decision feature D in IND(S n \{a} means the feature subset S after removing feature a n The equivalence class partitioning caused by GDE(D,S n ) represents the feature subset S n The granular decision entropy associated with the decision feature D; τ represents the threshold parameter.

6. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 1, characterized in that: In step S301, a feature subset S is selected by feature importance scoring, expert knowledge method or data-driven method. n The size of n.

7. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 1, characterized in that: In step S4, the specific steps of supersampling are as follows: S401: Identify majority class samples and minority class samples in the data set; S402: introducing the minority class sample input into the variational autoencoder model trained by the auxiliary loss function and the diversity loss function, and generating new samples through the variational autoencoder model; S403: Repeat S401 to S402 until the majority class samples and minority class samples in the data set are balanced.

8. The automotive software defect prediction method based on dynamic feature selection and supersampling as claimed in claim 1, characterized in that: In step S402, the variational autoencoder model is trained by the following steps: S4021: Constructing auxiliary loss functions for variational autoencoder models The formula is: Where: represents the normalized Euclidean distance function, which is used to calculate the distance between samples a and b; s j Represents the generated new sample; t, m represent the feature vectors of the input minority class samples and the generated new samples respectively; T i 、M i Represents the i-th feature in the feature vector; S4022: Constructing a Diversity Loss Function for a Variational Autoencoder Model The formula is: Where: Represents the mean vector t of the minority class sample set j And the generated new samples s j The cosine similarity between ; S4023: Combining the auxiliary loss function and the diversity loss function with the reconstruction loss function of the variational autoencoder model itself to form the overall target loss function of the variational autoencoder model; Where: represents the overall target loss; o Cross represents the reconstruction loss of the variational autoencoder model itself; α, β, and γ represent the weights of auxiliary loss, diversity loss, and reconstruction loss, respectively; S4024: During the training process of the variational autoencoder model, solving the overall target loss function by a gradient descent method, and reversely optimizing the parameters of the variational autoencoder model; The formula is: Where: S represents all generated new sample sets; s j is a single generated new sample; S4025: During the training of the variational autoencoder model, dynamically adjust the weights of the auxiliary loss, diversity loss, and reconstruction loss according to the quality and diversity of the new samples generated; S4026: Repeat S4024 to S4025 until the variational autoencoder model converges or reaches a preset number of iterations.

9. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 1, characterized in that: In step S5, the defect prediction model includes several base classifiers trained using a random forest model, a decision tree model, or an XGBoost model.

10. The automotive software defect prediction method based on dynamic feature selection and supersampling according to claim 9, characterized in that: In step S5, the training steps of the defect prediction model are as follows: S501: Define parameter grid: For each base classifier, define the possible value range of each parameter; S502: Systematically test each combination: for each base classifier, train each parameter combination in the parameter grid of the base classifier through the training set, and evaluate the performance of each parameter combination through cross-validation; S503: Evaluate model performance: For each base classifier, evaluate the performance of each parameter combination of the base classifier through the test set; S504: Select optimal parameters: select the parameter combination with the best performance for each base classifier as its model parameters; S505: Apply each base classifier to the test set for testing to obtain the prediction result of each base classifier; select the prediction result with the largest number of occurrences as the defect prediction result finally output by the defect prediction model through a majority voting strategy.

Citation Information

Patent Citations

  • Software defect prediction method and system based on information entropy oversampling

    CN114490386A

  • Software defect prediction method and system based on class association rules

    CN115599698A

  • Software testing method and system based on unbalanced data set

    CN116401143A

Cited By

  • Data set classification method and system based on unbalanced incremental learning

    CN119669862A

  • Defect detection method, device and equipment and storage medium

    CN120725970A