# Improving Software Defect Prediction in Noisy Imbalanced Datasets
## 3 Materials and Methods
### Undersampling  
In datasets, the number of non-defective samples often far exceeds the number of defective samples. These datasets typically include duplicate non-defective samples brought by non-defective code files that have not been modified in each version. In such cases, the dataset needs to be undersampled in order to reduce the degree of class imbalance and reduce the over-fitting of the model caused by repeated samples. The initial dataset can be expressed by the following formula:  
\[\mathrm{X}_{\mathrm{origin}}=\left\{(\mathrm{x}_{\mathrm{i}},\mathrm{y}_{ \mathrm{i}})\middle|\mathrm{i}\in(1,\mathrm{n}),\mathrm{y}_{\mathrm{i}}\in\{0, 1\},\mathrm{x}_{\mathrm{i}}=[\mathrm{x}_{\mathrm{i},1},\mathrm{x}_{\mathrm{i},2},\ldots,\mathrm{x}_{\mathrm{i},\mathrm{m}}]^{\mathrm{T}}\right\} \tag{1}\] \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Name** & **Description** & **Name** & **Description** \\ \hline Outdegree & The total number of connections other nodes point to it. & PageRank & A ranking of the nodes in the graph G based on the structure of the incoming links. \\ \multirow{3}{*}{\begin{tabular}{c} Insidelinks \\ \end{tabular} } & The total number of connections within the internal functions of the node. & Average\_neighbor\_degree & The average of the neighborhood of each node. \\ \multirow{3}{*}{\begin{tabular}{c} Out\_degree\_centrality \\ \end{tabular} } & The fraction of nodes its outgoing edges are connected to. & Number\_of\_cliques & The number of maximal cliques for each node. \\ \multirow{3}{*}{\begin{tabular}{c} In\_degree\_centrality \\ \end{tabular} } & The fraction of nodes its incoming edges are connected to. & Core\_number & The largest value k of a k-core containing that node. \\ \multirow{3}{*}{\begin{tabular}{c} Degree\_centrality \\ \end{tabular} } & The fraction of nodes it is connected to. & Brokerage & The number of pairs not directly connected. \\ \multirow{3}{*}{\begin{tabular}{c} Closeness\_centrality \\ \end{tabular} } & The reciprocal of the sum of the shortest path distances from v to all other nodes. & EffSize & Effective size of network. \\ \multirow{3}{*}{\begin{tabular}{c} Betweenness\_centrality \\ \end{tabular} } & The sum of the fraction of all-pair shortest paths that pass through node v. & Constraint & Measures how strongly a module is constrained by its neighbors. \\ \multirow{3}{*}{\
\begin{tabular}{c} Eccentricity \\ \end{tabular} } & The maximum distance from v to all other nodes in G. & Hierarchy & Measures how the constraint measure is distributed across neighbors. \\ \multirow{3}{*}{
\begin{tabular}{c} Communicability\_centrality \\ \end{tabular} } & A broader measure of connectivity, which assumes that information could flow along all possible paths between two nodes. & TwoStepReach & The percentage of nodes that are two steps away. \\ \hline \hline \end{tabular}
\end{table} 
Table 3: _Cont._where \(x_{i}\) is the feature vector of the i-th sample, \(y_{i}\) is the defect label of the i-th sample, \(n\) is the number of samples, and \(m\) is the feature dimension. In the method we are proposing, undersampling is introduced to alleviate the imbalance in a dataset caused by duplicate codes in multiple versions. The process of undersampling is represented by Algorithm 1:  
```
input original dataset \(X_{\text{origin}}\), imbalance degree \(r_{\text{max}}=y_{\text{negative}}/y_{\text{positive}}\), step \(s_{\text{us}}\) output undersample dataset \(X_{\text{us\_all}}[\,][\,]\) contains \(X_{\text{us}}\) with diff \(r_{\text{us}}\)
1. \(r_{\text{us}}\): undersample ratio, initialize to 1
2. \(X_{\text{max}},X_{\text{d}},X_{\text{min}}\) initialize to null
3. for\(x_{i}\) in \(X_{\text{origin}}\)
4. if\(y_{i}=0\)
5. then if\(x_{i}\) in \(X_{\text{max}}\)
6. then\(X_{\text{d}}\gets x_{i}\)
7. \(X_{\text{max}}\gets x_{i}\)
8. end if
9. else
10. \(X_{\text{min}}\leftarrow x_{i}\)
11. end if
12. end for
13. do {
14. r = the number of samples in \(X_{\text{max}}\)/the number of samples in \(X_{\text{min}}\)
15. while r \(\leq r_{\text{us}}\)
16.