Defect prediction method capable of being interpreted and related equipment
By calculating the difference between the actual defect rate and the expected defect rate of each code module in the software project, evaluating its defect tendency and sorting, the problem of poor interpretability of defect prediction results in the prior art is solved, and the efficiency of software defect repair is improved.
Patent Information
- Application Number
- CN202510361564.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-26
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2045-03-26
AI Technical Summary
Existing software defect prediction methods rely on complex machine learning models, resulting in poor interpretability of defect prediction results, reducing developers' trust in explanations, and potentially generating inaccurate or misleading explanations.
By constructing the defect dataset, the difference between the actual defect rate and the expected defect rate of each code module is calculated, the feature defect score is obtained, and all code module features are sorted to evaluate their defect tendency and importance.
Improve the interpretability of defect prediction models, enhance the accuracy and stability of explanations, and enable developers to trust and rely more on prediction results, thereby improving the efficiency of software defect repair.
Smart Images

Figure CN119883869A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the technical field of software analysis and defect prediction, and in particular, to an explainable defect prediction method and related equipment. Background Art
[0002] Interpretability is a key aspect of practical defect prediction. Existing workload-aware software defect prediction (predicting whether a code module has defects) methods use defect datasets (features of code modules and the number of defects in the module) to train a defect prediction model. The model is usually a complex machine learning model, such as a deep learning model. Finally, the code modules are ranked based on the prediction results. However, the black-box decision process of these models leads to poor interpretability of the prediction results.
[0003] In order to improve the interpretability of defect prediction models, in recent years, researchers have begun to use model-independent explanation methods (such as local interpretability methods (LIME, Local Interpretable Model-agnostic Explanations) or machine learning model explanation tools (SHAP, SHapley Additive exPlanations)) to explain a single prediction result. For a new code module, the defect prediction model predicts its defect probability. Then, a model-independent explanation method (such as LIME) is used to explain the prediction result. These explanation methods generate explanations based on complex perturbation mechanisms.
[0004] Specifically, in order to generate feature importance for a specific prediction, these methods usually modify the instance to be explained and observe the changes in the model output. The explanation method outputs the contribution of each feature to the prediction result, that is, the feature importance. However, these explanation methods have some problems: first, they treat the prediction model as a black box, which reduces the developer's trust in the explanation; second, these methods rely on complex perturbation mechanisms and may generate inaccurate or even misleading explanations; finally, the generated explanations may be unstable due to randomness. Summary of the invention
[0005] The embodiments of the present application provide an explainable defect prediction method and related devices for explainably describing the decision-making process in software defect prediction.
[0006] A first aspect of an embodiment of the present application provides an explainable defect prediction method, comprising: Constructing a defect data set based on historical data of the software project to be analyzed, and obtaining each code module to be analyzed in the software project to be analyzed and a code module feature corresponding to each code module to be analyzed from current data of the software project to be analyzed; wherein the code module feature is used to characterize a numerical feature of the code module to be analyzed; If the module characteristic value of any code module characteristic in any code module to be analyzed is the target characteristic value, determine the actual defect rate and expected defect rate of any code module characteristic in any code module to be analyzed according to the defect data set; wherein the expected defect rate is the ratio of the total number of code module lines of all defective code modules whose module characteristic values in the defect data set are the target characteristic value to the total number of code module lines of all defective code modules in the defect data set, and the actual defect rate is the ratio of the total number of code module defects of all defective code modules whose module characteristic values in the defect data set are the target characteristic value to the total number of code module defects of all defective code modules in the defect data set; the defect data set includes the total number of code module lines and the total number of code module defects corresponding to different module characteristic values, and the total number of code module lines and the total number of code module defects corresponding to all defective code modules; the defective code module is the code module in the defect data set; Calculating a difference between the actual defect rate and the expected defect rate to obtain a feature defect score of any code module feature in any code module; Calculating feature defect scores of all code module features in any code module to be analyzed to obtain a module defect score of any code module to be analyzed; wherein the module defect score is used to characterize the defect tendency of the code module to be analyzed; After obtaining the module defect scores of all the code modules to be analyzed, all the module defect scores are sorted, so as to process all the code modules to be analyzed in the software project to be analyzed in order from large to small.
[0007] A second aspect of an embodiment of the present application provides an explainable defect prediction device, including: CPU, memory, input and output interfaces, wired or wireless network interfaces, and power supply; The memory is a short-term storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute instruction operations in the memory to perform the explainable defect prediction method described in the first aspect.
[0008] A third aspect of an embodiment of the present application provides a computer-readable storage medium, which includes instructions. When the instructions are executed on a computer, the computer executes the explainable defect prediction method described in the first aspect.
[0009] A fourth aspect of an embodiment of the present application provides a computer program product, which includes instructions. When the instructions are executed on a computer, the computer executes the explainable defect prediction method described in the first aspect.
[0010] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages: through an interpretable defect prediction method disclosed in the embodiments of the present application, the defect tendency and defect score of each code module in the software project are evaluated by calculating the deviation between the actual defect rate and the expected defect rate, and the defect scores are sorted, thereby indicating the importance of module features to the defect score of the code module, and the evaluation process can be explained, thereby improving the accuracy and stability of the explanation. At the same time, developers can adjust the code modules in sequence according to the sorting order, thereby improving the efficiency of software defect repair. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0012] Figure 1 A schematic diagram of a ScoringDP system architecture disclosed in an embodiment of the present application; Figure 2 A schematic diagram of a flow chart of an explainable defect prediction method disclosed in an embodiment of the present application; Figure 3 A schematic flow chart of another explainable defect prediction method disclosed in an embodiment of the present application; Figure 4 A schematic flow chart of another explainable defect prediction method disclosed in an embodiment of the present application; Figure 5 A schematic flow chart of another explainable defect prediction method disclosed in an embodiment of the present application; Figure 6 A schematic flow chart of another explainable defect prediction method disclosed in an embodiment of the present application; Figure 7 A logic diagram of a code module scoring algorithm disclosed in an embodiment of the present application; Figure 8A schematic diagram of a module feature scoring algorithm disclosed in an embodiment of the present application; Fig. 9 A schematic diagram of an actual defect rate estimation based on a window disclosed in an embodiment of the present application; Fig.10 This is an example diagram for explaining the feature importance of ScoringDP disclosed in an embodiment of the present application; Fig.11 A Chinese-English comparison chart of the feature name of a module feature; Fig.12 A schematic diagram of the structure of an explainable defect prediction system disclosed in an embodiment of the present application; Fig.13 This is a schematic diagram of the structure of an explainable defect prediction device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0013] Software defect prediction is an important research area in software engineering, which aims to predict which modules may have defects by analyzing the characteristics of code modules (such as code complexity, number of lines of code, etc.). Traditional defect prediction methods usually rely on complex machine learning models (such as deep learning models) to improve prediction performance. However, these models often lack interpretability, resulting in reduced trust in the prediction results by developers, which in turn affects their application in practice.
[0014] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0015] See also Figure 1 , Figure 1 Schematic diagram of the system architecture of ScoringDP disclosed in the embodiment of this application. Figure 1 It can be seen that the embodiment of the present application is mainly a method for implementing defect prediction by scoring each code module. Specifically, in order to sort the code modules in the software project, the defect prediction scoring system (ScoringDP, ScoringDefect Prediction) first calculates a score for each code module, and then sorts the modules according to these scores. These scores are called defect scores. Figure 1The process of calculating defect scores for ScoringDP, where the defect score of a code module is an aggregation of the defect scores of its features. The defect score of a module feature can indicate the importance of the module feature to the defect score of the code module. The defect dataset can be constructed based on the historical change data of the code module (obtained from analysis of the code repository); if the historical data is insufficient, the data set can be constructed using data from similar projects, and there is no specific restriction here. It should also be noted that module features mainly describe various properties of the code, such as cohesion, coupling, complexity or scale. For example, the average method complexity (AMC), the average cyclomatic complexity (AVG CC), or the number of lines of code (LOC), etc., which are not described in detail here. For details, please refer to Fig.11 , Fig.11 The following is a Chinese-English comparison chart of the feature name of a module feature. For the convenience of description, this will not be repeated in the following.
[0016] To solve the technical problems mentioned above, please refer to Figure 2 , Figure 2 The flowchart of an explainable defect prediction method disclosed in the embodiment of the present application includes steps 201 to 205.
[0017] 201. Construct a defect data set based on historical data of the software project to be analyzed, and obtain each code module to be analyzed in the software project to be analyzed and a code module feature corresponding to each code module to be analyzed from current data of the software project to be analyzed.
[0018] In this embodiment, a defect data set is constructed by using the historical data of the software project to be analyzed, and then, by analyzing the current data of the software project to be analyzed, all the code modules to be analyzed in the software project to be analyzed and the code module features of each code module to be analyzed are obtained. It should be noted that the code module features are used to characterize the numerical features of the code modules to be analyzed. The software project to be analyzed is the software project to be analyzed in this embodiment, and specifically, the defects of the software project need to be analyzed and predicted.
[0019] In one specific embodiment, in combination Figure 1As shown, in the process of analyzing a software project, it is necessary to construct a data set in combination with the historical data of the software project or the data of similar projects, wherein the data set can be understood as a defect data set, which is a tabular data set, each row represents a code module, and at the same time, the code module has one or more numerical feature descriptions, such as the number of lines of code LOC and cyclomatic complexity, etc., which are not specifically limited here. Furthermore, it can be understood that if each row in the defect data set D represents a code module cm, and the code module cm is described by m numerical features, then the defect data set D includes m features and a corresponding label, representing the defect data of the module. Therefore, it can be understood that the defect data set includes the total number of code module lines and the total number of code module defects of the code module. And the total number of code module lines and the total number of code module defects on the software project.
[0020] 202. When the module feature value of any code module feature in any code module to be analyzed is the target feature value, determine the actual defect rate and the expected defect rate of any code module feature in any code module to be analyzed according to the defect data set.
[0021] Furthermore, when the module feature value of any code module feature in any code module to be analyzed in the software project to be analyzed satisfies the target feature value, each code module feature in each code module to be analyzed can be analyzed according to the total number of code module lines, the total number of code module lines, the total number of code module defects and the total number of code module defects in the defect data set, and then the actual defect rate and expected defect rate of each code module feature are obtained. It should be noted that the expected defect rate is the ratio of the total number of code module lines of the defective code module to the total number of code module lines of all defective code modules in the defect data set, and the actual defect rate is the ratio of the total number of code module defects of the defective code module in the defect data set to the total number of code module defects of all defective code modules in the defect data set. The defective code module is the code module in the defect data set, and the code module to be analyzed is the code module in the software project to be analyzed.
[0022] In one specific embodiment, ScoringDP can calculate the defect score of a code module feature by quantifying the deviation between two defect rates: the actual defect rate and the expected defect rate. For a module feature value fv of a code module feature f, the expected defect rate is defined as the ratio of the total number of code lines of the code module when the module feature value of the code module feature f is fv to the total number of code lines of all code modules in the defect data set. The calculation of the expected defect rate is based on an intuitive assumption that the defects in a software project are evenly distributed among the code lines of all code modules in the project. Similarly, the actual defect rate is defined as the ratio of the total number of defects in those code modules when the module feature value of the code module feature f is fv to the total number of defects in all code modules. For ease of understanding, the definitions of the expected defect rate and the actual defect rate will not be described later.
[0023] Furthermore, since the calculation of the expected defect rate is based on an intuitive assumption that defects in a software project are evenly distributed among the lines of code in all code modules within the project, there is an implicit assumption in the scoring of the above code module features: the defect dataset used contains an infinite number of code modules. However, in actual scenarios, the size of the defect dataset is limited, so there may be at least two situations. For ease of understanding, please refer to Figure 3 The embodiment shown or Figures 4 to 6 The embodiment shown.
[0024] 203. Calculate the difference between the actual defect rate and the expected defect rate to obtain a feature defect score of any code module feature in any code module.
[0025] After obtaining the actual defect rate and the expected defect rate of the code module feature, the difference between the actual defect rate and the expected defect rate can be calculated to obtain the feature defect score of any code module feature in any code module.
[0026] In one specific embodiment, the defect score of the code module feature is defined as the difference between the actual defect rate and the expected defect rate. Further, the feature defect score can be obtained by subtracting the expected defect rate from the actual defect rate.
[0027] 204. Calculate feature defect scores of all code module features in any code module to be analyzed to obtain a module defect score of any code module to be analyzed.
[0028] Thus, based on step 202-step 203, the feature defect scores of all code module features in any code module to be analyzed can be calculated, thereby obtaining the module defect score of any code module to be analyzed. It should be noted that the module defect score is used to characterize the defect tendency of the code module to be analyzed.
[0029] In one specific embodiment, when analyzing all code module features in a code module to be analyzed, the feature defect scores of all code module features in the code module to be analyzed may be accumulated to obtain a module defect score of the code module to be analyzed.
[0030] 205. After obtaining the module defect scores of all the code modules to be analyzed, sorting all the module defect scores, so as to process all the code modules to be analyzed in the software project to be analyzed in descending order of the module defect scores.
[0031] Therefore, after obtaining the module defect scores of all code modules to be analyzed in the software project to be analyzed, all module defect scores can be sorted, so that all code modules to be analyzed in the software project to be analyzed can be processed in order of priority according to the order of all module defect scores from large to small, and then more effective actions can be taken to reduce defects according to the defect scores of the code module features, such as modifying the code to give priority to changing features with higher defect scores.
[0032] In one of the specific embodiments, the defect scores of all code module features are aggregated by summing them up. This simple aggregation method can enhance the interpretability of ScoringDP.
[0033] Through an explainable defect prediction method disclosed in this embodiment, the defect tendency and defect score of each code module in the software project are evaluated by calculating the deviation between the actual defect rate and the expected defect rate, and the defect scores are sorted, thereby indicating the importance of module features to the defect score of the code module, and the evaluation process can be explained, thereby improving the accuracy and stability of the explanation. At the same time, developers can adjust the code modules in sequence according to the sorting order, thereby improving the efficiency of software defect repair.
[0034] Figure 3 for Figure 2 One implementation of step 201-step 202 in the embodiment is to obtain the actual defect rate and expected defect rate of the code module feature. For easy understanding, please refer to Figure 3 , Figure 3 This is a flow chart of another explainable defect prediction method disclosed in an embodiment of the present application, including steps 301 to 304.
[0035] 301. Analyze the software project to be analyzed line by line, set each line of the software project to be analyzed as any code module to be analyzed, and determine code module features included in any code module to be analyzed.
[0036] This embodiment mainly provides one possible implementation of step 201-step 202. Specifically, by analyzing the software project to be analyzed line by line, each line in the software project to be analyzed can be set as a corresponding code module to be analyzed (expressed as any code module to be analyzed). Thus, the code module features contained in any module to be analyzed can be determined.
[0037] In one specific embodiment, the software project to be analyzed is analyzed line by line, so as to obtain the code module to be analyzed represented by each line in the software project to be analyzed and the corresponding code module features.
[0038] 302. Based on the defect data set, obtain the total number of code module lines, the total number of total code module lines, the total number of code module defects, and the total number of total code module defects.
[0039] It should be noted that step 302 to step 304 in this embodiment is a calculation of the module feature defect score under an ideal state. In step 302, the calculation of the expected defect rate is based on an intuitive assumption that the defects in the defect data set are evenly distributed among the code lines of all code modules. Therefore, when the defect data in the defect data set is evenly distributed among all defective code modules, the total number of code module lines, the total number of code module defects, and the total number of code module defects after parsing the defect data set are obtained.
[0040] Furthermore, in the process of analyzing the defect data set, since the code module features and related defects are marked on the defective code module, one or more code module features and a corresponding module label of the defective code module can be obtained, and the label is annotated with the number of defects of the code module. Then, the total number of lines of the code module, the total number of lines of the total code module, the total number of defects of the code module and the total number of defects of the total code module can be obtained.
[0041] 303. Input the total number of lines of code modules and the total number of lines of total code modules into the expected defect rate calculation formula to obtain the expected defect rate.
[0042] Then, the total number of lines of the code module and the total number of lines of the total code module are input into the expected defect rate calculation formula to obtain the expected defect rate. It should be noted that the expected defect rate calculation formula is: , formula (1); where expected_defect_ratio is the expected defect rate, cm is the defect code module in the defect data set, D is the defect data set, f is the feature of any code module, fv is the target feature value, LOC is the number of lines of code of the defect code module in the defect data set, Used to represent the total number of lines in the code module. The total number of code module rows accumulated when the module feature value of the defective code module in the defect data set is the target feature value.
[0043] 304. Input the total number of code module defects and the total number of total code module defects into the actual defect rate calculation formula to obtain the actual defect rate. Corresponding to step 303, the total number of code module defects and the total number of total code module defects can be input into the actual defect rate calculation formula to obtain the actual defect rate. It should be noted that the actual defect rate calculation formula is: , formula (2); where actual_defect_ratio is the actual defect rate, defect is the number of defects in the defect code module in the defect data set, It is used to represent the total number of code module defects accumulated when the module feature value of the defective code module in the defect data set is the target feature value. Used to represent the total number of defects in the total code module.
[0044] In this embodiment, one of the inputs of the scoring algorithm is a defect dataset. Each row of the dataset represents a code module, including the various features and defect counts of the code module. This dataset is usually constructed based on the historical data of the project. For example, the features of the code module cm were counted one year ago, and then the number of defects found in it within this year was observed. However, it should be noted that Figure 3 The embodiment shown mainly assumes that the defect data set is large enough, and for any given feature value, there are enough code modules with the feature value. In this case, the expected defect rate and the actual defect rate will not be wrongly calculated as zero, but will change smoothly with the change of the feature value, thereby facilitating a reasonable estimation of the two defect rates.
[0045] An explainable defect prediction method disclosed in this embodiment calculates the module feature defect score, thereby effectively generating a reasonable expected defect rate and an actual defect rate, and can quantify and intuitively see the defect situation of the code module features of the code module to be analyzed.
[0046] It should be noted in advance that Figure 4 , Figure 5 and Figure 6 Compared to Figure 3 Another embodiment of obtaining the actual defect rate and expected defect rate of the code module feature. Figure 4 To describe an embodiment of obtaining an initial interval window, please refer to Figure 4 , Figure 4 This is a flow chart of another explainable defect prediction method disclosed in an embodiment of the present application, including steps 401 to 406.
[0047] 401. Obtain module feature values of all code module features in any defective code module in the defect data set, sort all module feature values in ascending order, and obtain a feature value sorting list corresponding to all module feature values.
[0048] As described above, this embodiment mainly describes determining the interval size of the initial interval window based on the defect data set. Figure 3 In the illustrated embodiment, the module feature values of all code module features have been acquired through the defect data set, and therefore, all module feature values may be sorted in ascending order to obtain a feature value sorting list corresponding to all module feature values.
[0049] In one specific embodiment, after obtaining the module feature values of all code module features, all module feature values are sorted in ascending order, thereby obtaining a sorted list corresponding to all module feature values, namely, a feature value sorted list.
[0050] 402. In the eigenvalue sorting list, check whether there is an interval window eigenvalue in all module eigenvalues.
[0051] Then, in the feature value sorting list, all module feature values are analyzed and whether there is an interval window feature value is screened. It should be noted that the interval window feature value is that the ratio of the number of code modules in a certain interval window to the total number of code modules in the data set must meet the preset interval ratio. For example, 20% or 30%, etc., are not limited here.
[0052] Furthermore, any one of step 403, step 404, step 405 or step 406 is executed respectively according to different inspection results.
[0053] 403. If there is an interval window eigenvalue in the eigenvalue sorting list, use the interval window eigenvalue as an insertion point in the eigenvalue sorting list to determine the index of the initial interval window.
[0054] Based on step 402, when there is an interval window eigenvalue in the eigenvalue sorting list, the interval window eigenvalue is used as the insertion point of the eigenvalue sorting list, and the index of the initial interval window is determined. It should be noted that the index includes a left index and a right index. The left index and the right index of the initial interval window are the interval positions where the module eigenvalues in the eigenvalue sorting list are located, and the insertion point is the center of the initial interval window.
[0055] In one specific embodiment, if the interval window eigenvalue fv exists in the eigenvalue sorting list, then the left index and the right index of the initial interval window at this time can be set to the index of the interval window eigenvalue fv in the eigenvalue sorting list, wherein it is necessary to satisfy as much as possible that the center of the left index and the right index of the initial interval window is the interval window eigenvalue fv.
[0056] 404. If the insertion point is located after the interval position of the interval window eigenvalue and the last module eigenvalue in the eigenvalue sorting list, the left index and the right index in the index of the initial interval window are set to the last module eigenvalue in the eigenvalue sorting list.
[0057] Based on step 402, when the insertion point is located after the interval position of the interval window feature value and the last module feature value in the feature value sorting list, the left index and the right index in the index of the initial interval window are set to the last module feature value in the feature value sorting list.
[0058] In one specific embodiment, if the interval window eigenvalue fv, that is, the insertion point is after the last element (module eigenvalue) in the eigenvalue sorted list, then the left index and the right index of the initial interval window at this time can be set to the last index in the eigenvalue sorted list, that is, the left index and the right index of the initial interval window at this time are set to the last module eigenvalue in the eigenvalue sorted list.
[0059] 405. If the insertion point is located at the interval position between the interval window eigenvalue and the first module eigenvalue in the eigenvalue sorting list, the left index and the right index in the index of the initial interval window are set to the first module eigenvalue in the eigenvalue sorting list.
[0060] Based on step 402, when the insertion point is located at the interval position between the interval window feature value and the first module feature value in the feature value sorting list, the left index and the right index in the index of the initial interval window are set to the first module feature value in the feature value sorting list.
[0061] In one specific embodiment, if the insertion point is at the first position in the eigenvalue sorting list (i.e., the module eigenvalue corresponding to the first position in the sorting), then the left index and the right index of the initial interval window at this time can be set to the index of the first element in the eigenvalue sorting list, that is, the left index and the right index of the initial interval window at this time are set to the first module eigenvalue in the eigenvalue sorting list.
[0062] 406. If the insertion point is located before the interval position of the first module eigenvalue in the eigenvalue sorting list in the interval window eigenvalue, the left index in the index of the initial interval window is set to the index of the previous sorting position of the insertion point, and the right index is the index of the insertion point.
[0063] Based on step 402, when the insertion point is located before the interval position of the first module feature value in the feature value sorting list in the interval window feature value, the left index in the index of the initial interval window is set to the index of the previous sorting position of the insertion point, and the right index is the index of the insertion point.
[0064] In one specific embodiment, if the interval window eigenvalue fv, that is, the insertion point, is before the first element (module eigenvalue) of the eigenvalue sorted list, then the left index of the initial interval window at this time can be set to the index of the previous interval position of the insertion point, and the corresponding right index is set to the index of the insertion point.
[0065] An explainable defect prediction method disclosed in this embodiment can effectively guide the initial interval window and the corresponding left index and right index, provide conditions for subsequently finding the final interval window, and reduce the workload.
[0066] for Figure 5 , Figure 5 For Figure 4 For easier understanding, please refer to Figure 5 , Figure 5 This is a flow chart of another explainable defect prediction method disclosed in an embodiment of the present application, including steps 501 to 507.
[0067] 501. Set a preset interval window value.
[0068] In order to obtain the target interval window through the initial interval window, it is necessary to ensure that there are enough code modules in the initial interval window for estimation. Therefore, it is necessary to set a reference interval window value, that is, a preset interval window value. Furthermore, the preset interval window value can be understood as the interval size θ, which will be described in detail later for ease of understanding. It should be noted that the preset interval window value is used to characterize the ratio of the total number of lines of the preset code module to the total number of lines of the total code module.
[0069] It should also be noted that the execution order of step 501 is not limited in this embodiment. Figure 2 When performing step 201 in the illustrated embodiment, step 501 may also be performed simultaneously.
[0070] 502. Calculate the ratio of the total number of lines of the code modules to be analyzed in the initial interval window to the total number of lines of the total code modules to obtain a ratio of the number of lines to be analyzed.
[0071] Since the total number of code module lines, the total number of code module lines, the total number of code module defects and the total number of code module defects have been obtained in the above steps, they will not be repeated here. Specifically, in this embodiment, the ratio of the total number of code module lines of the defective code modules located in the initial interval window to the total number of code module lines can be calculated to obtain the ratio of the number of lines to be analyzed.
[0072] In one specific embodiment, the ratio of the total number of lines of the defective code module to the total number of lines of the total code module in the interval window at this time may be calculated to obtain the ratio of the number of lines to be analyzed.
[0073] Then, according to the calculation results of different ratios of the number of rows to be analyzed, steps 502 to 504 or steps 505 to 507 are respectively executed.
[0074] 503. When the ratio of the number of rows to be analyzed is less than half of the preset interval window value, and any index of the initial interval window is not located at the list boundary of the eigenvalue sorting list, the initial interval window is iterated to move the left index of the initial interval window to the left by one unit of interval position, or to move the right index of the initial interval window to the right by one unit of interval position, so as to ensure that the interval window eigenvalue is located at the center of the initial interval window after iteration.
[0075] Furthermore, when the ratio of the number of rows to be analyzed is less than half of the preset interval window value, and any index of the initial interval window is not located at the list boundary of the eigenvalue sorting list, the initial interval window can be iterated, so as to move the left index of the initial interval window to the left by one unit of interval position. Alternatively, the right index of the initial interval window is moved to the right by one unit of interval position, and finally the interval window eigenvalue is located at the center of the iterated initial interval window.
[0076] In one of the specific embodiments, when the ratio of the number of rows to be analyzed is less than half of the preset interval window value, and an index (left index or right index) of the interval window at this time is not located at a certain list boundary (left boundary or right boundary) of the eigenvalue sorting list, the index can be adjusted. Specifically, the interval window at this time is expanded. For example, if the interval window at this time is the initial interval window mentioned above (the interval window that has not been iterated), the right index of the initial interval window can be moved one unit to the right in the eigenvalue sorting list. Alternatively, the left index of the initial interval window can be moved one unit to the left in the eigenvalue sorting list. It should be noted that moving to the right or to the left is acceptable, but it is necessary to satisfy that the interval window eigenvalue is located at the center of the initial interval window after iteration.
[0077] Furthermore, if the interval window at this time is the initial interval window after iteration, it can also be further expanded and step 504 is executed.
[0078] 504. Calculate the ratio of the number of rows to be analyzed of the initial interval window after iteration until the ratio of the number of rows to be analyzed is not less than half of the preset interval window value, and any index of the initial interval window is located at the list boundary of the eigenvalue sorting list, terminate the iteration, and determine the initial interval window after iteration as the target interval window.
[0079] Based on step 503, after completing one iteration, the ratio of the number of rows to be analyzed of the initial interval window after the iteration can be calculated until the ratio of the number of rows to be analyzed is not less than half of the preset interval window value, and any index of the initial interval window is located at the list boundary of the feature value sorting list, the iteration is terminated, and the initial interval window after the iteration is determined as the target interval window.
[0080] In one specific embodiment, after completing one iteration, it is necessary to recalculate the ratio of the number of rows to be analyzed of the initial interval window after the iteration. The specific calculation method can refer to the above steps. If the ratio of the number of rows to be analyzed of the initial interval window after the iteration is still less than half of the preset interval window value, and any index of the initial interval window is not located at the list boundary of the feature value sorting list, then continue to execute step 503. However, when the ratio of the number of rows to be analyzed of the initial interval window after the iteration is not less than half of the preset interval window value (i.e., not less than ), and when an index of the initial interval window after iteration reaches the corresponding boundary of the list, the iteration stops. The initial interval window after iteration at this time can be determined as the target interval window.
[0081] Furthermore, in other feasible technical solutions, there are the following situations. If the right index of the initial interval window after iteration reaches the right list boundary of the eigenvalue sorting list, the left index of the initial interval window after iteration is moved right by one unit of interval position. Or, if the left index of the initial interval window after iteration reaches the left list boundary of the eigenvalue sorting list, the right index of the initial interval window after iteration is moved left by one unit of interval position.
[0082] 505. When the ratio of the number of rows to be analyzed is not less than the preset interval window value, the interval window characteristic value is used as the window center point, and the interval distance between the left index or the right index of the initial interval window and the window center point is calculated.
[0083] Based on step 502, when the ratio of the number of rows to be analyzed is not less than the preset interval window value, the interval window characteristic value can be used as the window center point, and the interval distance between the left index or right index of the initial interval window and the window center point can be calculated.
[0084] In one specific embodiment, when the ratio of the number of lines to be analyzed (the specific calculation process has been described in the previous steps and will not be repeated here) is not less than the preset interval window value, that is, when the code volume ratio of the initial interval window is not less than θ, the module characteristic value corresponding to the initial interval window at this time (that is, the interval window characteristic value described above) can be calculated. Then, the interval window characteristic value is used as the window center point to calculate the interval distance from the left index of the initial interval window to the window center point, and the interval distance from the right index of the initial interval window to the window center point.
[0085] Then, according to the judgment result at this time, step 506 or step 507 is executed respectively.
[0086] 506. When the left interval distance of the left index of the initial interval window is less than the right interval distance of the right index of the initial interval window, and the left index of the initial interval window is not located at the list boundary of the feature value sorting list, the left index of the initial interval window is moved to the left by one unit of interval position to determine the moved initial interval window as the target interval window.
[0087] Based on step 505, when the left interval distance of the left index of the initial interval window is less than the right interval distance of the right index of the initial interval window, and the left index of the initial interval window is not located at the list boundary of the feature value sorted list, the left index of the initial interval window can be moved to the left by one unit of interval position, so that the moved initial interval window is determined as the target interval window.
[0088] In one specific embodiment, when the left endpoint corresponding to the left index is closer to the interval window characteristic value fv and the left index has not reached the corresponding boundary, the left index of the initial interval window is moved to the left by one unit of interval position, and the initial interval window after being moved to the left by one unit is used as the target interval window.
[0089] 507. When the right interval distance of the right index of the initial interval window is less than the left interval distance of the left index of the initial interval window, and the right index of the initial interval window is not located at the list boundary of the feature value sorting list, the right index of the initial interval window is moved to the right by one unit of interval position to determine the moved initial interval window as the target interval window.
[0090] Based on step 505, when the right interval distance of the right index of the initial interval window is less than the left interval distance of the left index of the initial interval window, and the right index of the initial interval window is not located at the list boundary of the feature value sorted list, the right index of the initial interval window can be moved to the right by one unit of interval position, so that the moved initial interval window is determined as the target interval window.
[0091] In one specific embodiment, the right endpoint distance interval window feature value corresponding to the right index If the right index of the initial interval window is closer and the right index does not reach the corresponding boundary, the right index of the initial interval window is moved one unit to the right, and the initial interval window after being moved one unit to the right is used as the target interval window.
[0092] based on Figure 4 and Figure 5 The embodiment shown can be understood as a scoring algorithm for module features. Figure 8 , Figure 8 This is a logic diagram of an algorithm for module feature scoring disclosed in an embodiment of the present application. Among them, Algorithm 2 describes in detail an algorithm for calculating the defect score of a code module feature f (module feature name is fn, module feature value is fv) based on a defect data set D. The last input of the algorithm is θ, which is used to determine the interval size in our proposed window-based estimation method. The algorithm is divided into three parts: the first part calculates some basic data (lines 1 to 17), the second part determines the interval of the window-based estimation (lines 18 to 29), and the third part calculates the final defect score (lines 30 to 36). It should be added that Figure 8 There are feature value list (fvlist, feature value list), sorted feature value list (sFvList, sorted feature value list), total number of defects (totalDefects, total number ofdefects), whether it exists (isExist, is Exist), and the index of the insertion position (insIdx, insert index). Among them, Figure 8 It is mainly divided into two parts.
[0093] The first part first retrieves the unique values of the input features from the input defect dataset D (line 1) and sorts them in ascending order (line 2). The resulting sorted list is denoted as sFvList. Subsequently, the algorithm determines the total number of defects and the total number of lines of code for all code modules in the dataset D (lines 3 and 4). The code from lines 5 to 17 is used to calculate the initial interval, which is an almost The smallest interval centered on the list sFvList, or if If it exceeds the bounds of the list, the closest The left index and right index of the interval are expressed as and . Note that the endpoints of the interval are inclusive. Specifically, we first check the input eigenvalues exists in sFvList (line 5), and calculates if Insertion point when inserting into sFvList (line 6). Then, determine the index of the initial interval: if exists in sFvList, then and All set to Index in sFvList (line 8); if the insertion point is after the last element of sFvList, then and are set to the last index of sFvList (line 11); if the insertion point is the first position of sFvList, then and are all set to the index of the first element (line 13); otherwise, Set to the index of the position before the insertion point, Set to the index of the insertion point (line 15).
[0094] The second part expands the initial interval to ensure that it contains enough code modules for effective window-based estimation. The algorithm iteratively expands the interval by moving the left index of the initial interval to the left or the right index to the right. When either condition (1) or condition (2) is met (where condition 1 is that the proportion of code in the current interval is not less than , condition 2 is that the proportion of code in the current interval window is not less than , and when an index of the current interval window reaches the corresponding boundary of the list), the iteration stops (line 21). It should be noted that condition (2) is used to stop the iteration in advance to avoid the situation where the interval cannot represent the input feature value. Furthermore, in each iteration, Algorithm 2 first calculates the proportion of the amount of code in the current interval (lines 19 to 20), and then decides whether to stop the iteration (lines 21 to 23). If it does not stop, continue to adjust the index. When in condition (1), the left endpoint is closer to fv than the right endpoint and the left index has not reached the corresponding boundary, or, in condition (2), the right index has reached the corresponding boundary, the left index is moved to the right. Otherwise, Algorithm 2 moves the right index to the left. The purpose of this index movement is to ensure that the interval is centered on fv as much as possible. Therefore, the interval window must be expanded after each iteration, and the iteration stop condition must be met after a certain number of iterations.
[0095] The last part goes first through Figure 6 Formula (4) and Formula (5) in the illustrated embodiment calculate the expected defect rate and the actual defect rate (lines 30 to 34). Subsequently, the defect score is calculated by Formula (3), which represents the output of Algorithm 2 (line 35), where Formula (3), Formula (4) and Formula (5) are Figure 6 The embodiments shown are described in detail.
[0096] It should be noted that the interval is iteratively enlarged, the current interval is the interval in the iterative process, and finally the target interval window is obtained.
[0097] Through an explainable defect prediction method disclosed in this embodiment and a window-based defect rate estimation method, the defect score of the code feature module can be effectively obtained, making the estimated defect rate more reasonable and accurate.
[0098] for Figure 6 , Figure 6 For Figure 5 For easier understanding, please refer to Figure 6 , Figure 6 This is a flow chart of another explainable defect prediction method disclosed in an embodiment of the present application, including steps 601 to 605.
[0099] 601. Analyze the defect data set and filter out defective code modules whose module feature values of code module features are interval window feature values.
[0100] In this embodiment, by analyzing the defect data set, it is possible to screen out defect code modules under the condition that the module characteristic value of each code module characteristic is the interval window characteristic value. It should be noted that the interval window characteristic value is used to characterize that in the defect data set, in the target interval window centered on the interval window characteristic value, the ratio of the number of defect code modules located in the target interval window to the total number of all defect code modules in the defect data set meets the preset quantity ratio.
[0101] In one specific embodiment, for ease of understanding, please refer to Fig. 9 , Fig. 9 This is a schematic diagram of an actual defect rate estimation based on a window disclosed in an embodiment of the present application. It should be noted that this embodiment mainly demonstrates the principle of the actual defect rate estimation method based on a window (the principle of the expected defect rate is similar to this). Fig. 9 A point (x, y) on the midline, x represents the value of the code module feature f, and y represents the total number of defects in all code modules in the defect dataset whose code module feature f has the value x. It is worth noting that for some values of the code module feature f, there may be no corresponding points in the graph due to the limited size of the defect dataset used. When using the window-based estimation method, calculating the defect score for the code module feature f with the value fv involves the following steps: First, ScoringDP determines an interval centered on fv (an interval is a special case of a window, i.e., a target interval window), denoted as intvl, to represent the module feature value fv. In this step, it is necessary to ensure that the dataset used contains a sufficient number of code modules whose feature f values fall within this interval.
[0102] It should be added that the target interval window is derived from the analysis of the data set. For example, for a defective code module, the value of its code module feature f is fv, and then an interval centered on fv is determined so that the number of code modules in the data set whose code module feature f value is within this interval accounts for 20% of the total number of code modules in the data set.
[0103] Then, step 602 to step 605 may be executed.
[0104] 602. Determine the total number of code module lines, the total number of total code module lines, the total number of code module defects, and the total number of total code module defects according to the number of defective code modules and the total number of all defective code modules.
[0105] In this embodiment, step 602 is similar to the above Figure 3 However, it should be noted that, in this embodiment, the total number of code module lines, the total number of total code module lines, the total number of code module defects and the total number of total code module defects can also be determined according to the number of defective code modules and the total number of all defective code modules.
[0106] 603. Input the total number of lines of code modules and the total number of lines of total code modules into the calculation formula for estimating the expected defect rate to obtain the expected defect rate. Based on step 602, ScoringDP can input the total number of lines of code modules and the total number of lines of total code modules into the calculation formula for estimating the expected defect rate to obtain the expected defect rate. It should be noted that the calculation formula for estimating the expected defect rate is: , formula (4); where expected_defect_ratio is the expected defect rate, cm is the defect code module in the defect data set, D is the defect data set, f is the code module feature, intvl is the interval window feature value, LOC is the number of code lines of the defect code module in the defect data set, The total number of code module rows accumulated when the module characteristic value of the defective code module in the defect data set is the interval window characteristic value, Used to represent the total number of lines of the total code module.
[0107] 604. Input the total number of code module defects and the total number of total code module defects into the calculation formula for estimating the actual defect rate to obtain the actual defect rate. Based on step 602, ScoringDP can input the total number of code module defects and the total number of total code module defects into the calculation formula for estimating the actual defect rate to obtain the actual defect rate. It should be noted that the calculation formula for estimating the actual defect rate is: , formula (5); where actual_defect_ratio is the actual defect rate, defect is the number of defects in the defect code module in the defect data set, It is used to characterize the total number of code module defects accumulated when the module characteristic value of the defective code module in the defect data set is the interval window characteristic value. Used to represent the total number of defects in the total code module.
[0108] 605. Subtract the actual defect rate from the expected defect rate to obtain a characteristic defect score.
[0109] Then, the actual defect rate can be subtracted from the expected defect rate to obtain the feature defect score. Specifically, defect_score = actual_defect_ratio - expected_defect_ratio, formula (3); where defect_score is the feature defect score. Finally, ScoringDP uses these two defect rates to calculate the defect score of the code module feature f through formula (3). Therefore, based on the above window-based estimation method, the defect score can be reasonably calculated for features with any value (including those feature values that do not appear in the defect dataset used).
[0110] Combination Figure 6 The illustrated embodiment and Algorithm 1 can be found in Figure 7 , Figure 7 This is a logic diagram of a code module scoring algorithm disclosed in an embodiment of the present application. Figure 7 As can be seen, the working process of Algorithm 1 is as follows. It first calculates the defect score of each feature of the input code module cm in turn (lines 1 to 7). In the process of calculating the defect score of each feature of the code module to be analyzed, the required parameters and the algorithm for obtaining the parameters are detailed in Algorithm 2. Subsequently, it derives the defect score of cm by summing up the feature defect scores of the code module features of these code modules to be analyzed (line 8). Finally, the defect scores of the features are summarized by summing. This summary method can enhance the interpretability of ScoringDP.
[0111] At Figure 7It should be noted that fn is the feature name, fv is the feature value, and fns is multiple feature names. The details are not repeated here.
[0112] Furthermore, for code modules, higher defect scores indicate higher defect density. Therefore, quality assurance resources should be allocated to code modules with higher defect scores to improve resource utilization. To interpret the prediction results for a specific code module, ScoringDP uses the model feature defect scores calculated during the prediction process as feature importance. Fig.10 , Fig.10 This is an example diagram for explaining the feature importance of ScoringDP disclosed in the embodiment of the present application. Fig.10 An example of ScoringDP explanation is shown, where the horizontal axis represents the defect score of the feature (i.e. the calculated defect score) and the vertical axis represents the code module features (and their values, i.e. the true value) sorted in descending order according to the defect score. For each feature described above, see Fig.11 . Fig.11 A Chinese-English comparison chart of the feature name of a module feature.
[0113] Specifically, the defect score of a single code module feature can be interpreted from two aspects: sign and magnitude. A positive (or negative) defect score indicates that the actual defect rate is higher than the expected defect rate, which means that the code module has more (or fewer) defects than expected when the value of code module feature X is x. A larger absolute value of the defect score indicates the extent to which the total number of defects in the code module is more (or less) than the expected number of defects. Based on the ranked features, developers can make evidence-based decisions: in order to reduce the defect proneness of a code module, developers should modify the code module to prioritize changing features with larger defect scores, i.e. Fig.10 The specific module feature names can be found in Fig.11 .
[0114] The explainable defect prediction method disclosed in this embodiment has the following three advantages: (1) The explanation is relatively intuitive: The explanation of ScoringDP comes directly from its internal decision-making process, without relying on external explanation methods (such as LIME and SHAP), which improves the accuracy and stability of the explanation. (2) Strong operability: Developers can take more effective actions to reduce defects based on the defect scores of module features, such as modifying the code to prioritize changing features with higher defect scores. (3) Excellent prediction performance: According to experiments, ScoringDP is better than or equal to the existing state-of-the-art methods in most performance indicators.
[0115] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0116] See also Fig.12 , Fig.12 A schematic diagram of the structure of an explainable defect prediction system disclosed in an embodiment of the present application.
[0117] The acquisition unit 1201 is used to acquire each code module to be analyzed in the software project to be analyzed, and determine a defect data set and a code module feature corresponding to the code module to be analyzed; wherein the defect data set is constructed by historical data of the code module to be analyzed in the software project to be analyzed, and the code module feature is used to characterize the numerical feature of the code module to be analyzed; The determining unit 1202 is used to determine the actual defect rate and expected defect rate of any code module feature in any code module to be analyzed according to the defect data set when the module feature value of any code module feature in any code module to be analyzed is the target feature value; wherein the expected defect rate is the ratio of the total number of code module lines of all defective code modules whose module feature values in the defect data set are the target feature value to the total number of code module lines of all defective code modules in the defect data set, and the actual defect rate is the ratio of the total number of code module defects of all defective code modules whose module feature values in the defect data set are the target feature value to the total number of code module defects of all defective code modules in the defect data set; the defect data set includes the total number of code module lines and the total number of code module defects corresponding to different module feature values, and the total number of code module lines and the total number of code module defects corresponding to all defective code modules; the defective code module is the code module in the defect data set; The calculation unit 1203 is used to calculate the difference between the actual defect rate and the expected defect rate, and obtain a feature defect score corresponding to any code module feature in any code module; The calculation unit 1203 is further used to calculate the feature defect scores of all code module features in any code module to be analyzed, and obtain the module defect score of any code module to be analyzed; wherein the module defect score is used to characterize the defect tendency of the code module to be analyzed; The sorting unit 1204 is used to sort all the module defect scores after obtaining the module defect scores of all the code modules to be analyzed, so as to process all the code modules to be analyzed in order from large to small.
[0118] See below Fig.13 , a schematic diagram of a structure of an explainable defect prediction device disclosed in an embodiment of the present application includes: CPU 1301, memory 1305, input / output interface 1304, wired or wireless network interface 1303 and power supply 1302; The memory 1305 is a temporary storage memory or a permanent storage memory; The CPU 1301 is configured to communicate with the memory 1305 and execute the instructions in the memory 1305 to perform the aforementioned Figures 2 to 6 An explainable defect prediction method in any of the illustrated embodiments.
[0119] The embodiment of the present application also provides a chip system, the chip system includes at least one processor and a communication interface, the communication interface and the at least one processor are interconnected through a line, and the at least one processor is used to run a computer program or instruction to execute the aforementioned Figures 2 to 6 An explainable defect prediction method in any of the illustrated embodiments.
[0120] The embodiment of the present application also provides a computer-readable storage medium, the computer-readable storage medium includes instructions, when the instructions are executed on a computer, the computer executes the aforementioned Figures 2 to 6 An explainable defect prediction method in any of the illustrated embodiments.
[0121] The present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the aforementioned Figures 2 to 6 An explainable defect prediction method in any of the illustrated embodiments.
[0122] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0123] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0124] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0125] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0126] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. An explainable defect prediction method, characterized in that: The method comprises: Constructing a defect data set based on historical data of the software project to be analyzed, and obtaining each code module to be analyzed in the software project to be analyzed and a code module feature corresponding to each code module to be analyzed from current data of the software project to be analyzed; wherein the code module feature is used to characterize a numerical feature of the code module to be analyzed; If the module characteristic value of any code module characteristic in any code module to be analyzed is the target characteristic value, determine the actual defect rate and expected defect rate of any code module characteristic in any code module to be analyzed according to the defect data set; wherein the expected defect rate is the ratio of the total number of code module lines of all defective code modules whose module characteristic values in the defect data set are the target characteristic value to the total number of code module lines of all defective code modules in the defect data set, and the actual defect rate is the ratio of the total number of code module defects of all defective code modules whose module characteristic values in the defect data set are the target characteristic value to the total number of code module defects of all defective code modules in the defect data set; the defect data set includes the total number of code module lines and the total number of code module defects corresponding to different module characteristic values, and the total number of code module lines and the total number of code module defects corresponding to all defective code modules; the defective code module is the code module in the defect data set; Calculating a difference between the actual defect rate and the expected defect rate to obtain a feature defect score of any code module feature in any code module; Calculating feature defect scores of all code module features in any code module to be analyzed to obtain a module defect score of any code module to be analyzed; wherein the module defect score is used to characterize the defect tendency of the code module to be analyzed; After obtaining the module defect scores of all the code modules to be analyzed, all the module defect scores are sorted, so as to process all the code modules to be analyzed in the software project to be analyzed in order from large to small.
2. The explainable defect prediction method according to claim 1, characterized in that: The step of obtaining each code module to be analyzed in the software project to be analyzed and a code module feature corresponding to each code module to be analyzed from the current data of the software project to be analyzed includes: The software project to be analyzed is analyzed line by line, each line of the software project to be analyzed is set as any code module to be analyzed, and the code module features contained in any code module to be analyzed are determined.
3. The explainable defect prediction method according to claim 1, characterized in that: Determining the actual defect rate and the expected defect rate of any code module feature according to the defect data set includes: Based on the defect data set, obtaining the total number of lines of the code module, the total number of lines of the total code module, the total number of defects of the code module and the total number of defects of the total code module; The total number of lines of the code module and the total number of lines of the total code module are input into the expected defect rate calculation formula to obtain the expected defect rate; wherein the expected defect rate calculation formula is: , the expected_defect_ratio is the expected defect rate, the cm is the defect code module in the defect data set, the D is the defect data set, the f is the feature of any code module, the fv is the target feature value, the LOC is the number of lines of code of the defect code module in the defect data set, The total number of code module rows accumulated when the module characteristic value of the defective code module in the defective data set is the target characteristic value, Used to represent the total number of lines of the total code module; The total number of code module defects and the total number of total code module defects are input into the actual defect rate calculation formula to obtain the actual defect rate; wherein the actual defect rate calculation formula is: , the actual_defect_ratio is the actual defect rate, the defect is the number of defects in the defect code module in the defect data set, and the The total number of code module defects accumulated when the module characteristic value of the defective code module in the defect data set is the target characteristic value, Used to represent the total number of defects in the total code module.
4. The explainable defect prediction method according to claim 1, characterized in that: Determining the actual defect rate and the expected defect rate of any code module feature in any code module to be analyzed according to the defect data set includes: Analyze the defect data set, and filter out defect code modules whose module characteristic value of code module characteristics is an interval window characteristic value; wherein the interval window characteristic value is used to indicate that, in the defect data set, in a target interval window centered on the interval window characteristic value, a ratio of the number of defect code modules located in the target interval window to the total number of all defect code modules in the defect data set satisfies a preset quantity ratio; Determine, according to the number of defective code modules and the total number of all defective code modules, the total number of lines of the code modules, the total number of defects of the code modules, and the total number of defects of the total code modules; The total number of lines of the code module and the total number of lines of the total code module are input into the calculation formula for estimating the expected defect rate to obtain the expected defect rate; wherein the calculation formula for estimating the expected defect rate is: , the expected_defect_ratio is the expected defect rate, the cm is the defect code module in the defect data set, the D is the defect data set, the f is the code module feature, the intvl is the interval window feature value, the LOC is the number of code lines of the defect code module in the defect data set, The total number of code module rows accumulated when the module characteristic value of the defective code module in the defective data set is the interval window characteristic value, Used to represent the total number of lines of the total code module; The total number of code module defects and the total number of total code module defects are input into a calculation formula for estimating the actual defect rate to obtain the actual defect rate; wherein the calculation formula for estimating the actual defect rate is: , the actual_defect_ratio is the actual defect rate, the defect is the number of defects in the defect code module in the defect data set, and the The total number of code module defects accumulated when the module characteristic value of the defective code module in the defect data set is the interval window characteristic value, Used to represent the total number of defects in the total code module.
5. The explainable defect prediction method according to claim 4, characterized in that: Before filtering out defective code modules whose module characteristic values of code module characteristics are interval window characteristic values, the method further includes: Obtaining module feature values of all code module features in any defective code module in the defect data set, sorting all module feature values in ascending order, and obtaining a feature value sorting list corresponding to all module feature values; In the eigenvalue sorting list, checking whether the interval window eigenvalue exists in the eigenvalues of all modules; If the interval window eigenvalue exists in the eigenvalue sorting list, the interval window eigenvalue is used as the insertion point of the eigenvalue sorting list to determine the index of the initial interval window; wherein the left index and the right index of the initial interval window are the interval positions where the module eigenvalues in the eigenvalue sorting list are located, and the insertion point is the center of the initial interval window; or, If the insertion point is located after the interval position of the interval window feature value and the last module feature value in the feature value sorting list, the left index and the right index in the index of the initial interval window are set to the last module feature value in the feature value sorting list; or, If the insertion point is located at the interval position between the interval window feature value and the first module feature value in the feature value sorting list, the left index and the right index in the index of the initial interval window are set to the first module feature value in the feature value sorting list; or, If the insertion point is located before the interval position of the first module feature value in the feature value sorting list where the interval window feature value is located, the left index in the index of the initial interval window is set to the index of the previous sorting position of the insertion point, and the right index is the index of the insertion point.
6. The explainable defect prediction method according to claim 5, characterized in that: The method for obtaining the target interval window includes: Setting a preset interval window value; wherein the preset interval window value is used to represent the ratio of the total number of lines of a preset code module to the total number of lines of a preset total code module; Calculating the ratio of the total number of lines of the code module of any defective code module located in the initial interval window to the total number of lines of the total code modules to obtain a ratio of the number of lines to be analyzed; When the ratio of the number of rows to be analyzed is less than half of the preset interval window value, and any index of the initial interval window is not located at the list boundary of the feature value sorting list, the initial interval window is iterated to move the left index of the initial interval window to the left by one unit of interval position, or to move the right index of the initial interval window to the right by one unit of interval position, so as to satisfy that the interval window feature value is located at the center of the iterated initial interval window; Calculate the ratio of the number of rows to be analyzed of the initial interval window after iteration, until the ratio of the number of rows to be analyzed is not less than half of the preset interval window value, and any index of the initial interval window is located at the list boundary of the feature value sorted list, terminate the iteration, and determine the initial interval window after iteration as the target interval window.
7. The explainable defect prediction method according to claim 6, characterized in that: Before the iteration is terminated and the initial interval window after the iteration is determined as the target interval window, the method further includes: If the right index of the iterated initial interval window reaches the right list boundary of the eigenvalue sorting list, the left index of the iterated initial interval window is moved rightward by one unit interval position; or, If the left index of the initial interval window after the iteration reaches the left list boundary of the eigenvalue sorting list, the right index of the initial interval window after the iteration is moved to the left by a unit interval position.
8. The explainable defect prediction method according to claim 6, characterized in that: The method further comprises: When the ratio of the number of rows to be analyzed is not less than the preset interval window value, taking the interval window characteristic value as the window center point, calculating the interval distance between the left index or the right index of the initial interval window and the window center point; When the left interval distance of the left index of the initial interval window is less than the right interval distance of the right index of the initial interval window, and the left index of the initial interval window is not located at the list boundary of the feature value sorted list, the left index of the initial interval window is moved to the left by a unit interval position, so as to determine the moved initial interval window as the target interval window; or, When the right interval distance of the right index of the initial interval window is less than the left interval distance of the left index of the initial interval window, and the right index of the initial interval window is not located at the list boundary of the feature value sorted list, the right index of the initial interval window is moved to the right by one unit of interval position to determine the moved initial interval window as the target interval window.
9. An explainable defect prediction device, characterized in that: The device comprises: CPU, memory, input and output interfaces, wired or wireless network interfaces, and power supply; The memory is a short-term storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the explainable defect prediction method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium comprises instructions, and when the instructions are executed on a computer, the computer is caused to perform the explainable defect prediction method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Software defect prediction method and device, electronic equipment and computer storage medium
CN113656325A
Code detection method and device, equipment and storage medium
CN115344491A
Code defect detection and repair method and device based on large model
CN118860480A