# Transfer Convolutional Neural Network for Cross-Project Defect Prediction
## 1 Introduction  
As software scale and complexity increase, software testing has become one of the most critical phases in the software lifecycle. Software defect prediction (SDP) based on static code inspection could help the software quality assurance team find defect-prone modules or files, so that they could allocate resources more efficiently. Many existing studies [1; 2; 3] proposed various approaches to perform SDP, but they were usually limited to within-project defect prediction (WPDP), which attempts to train prediction models by using historical data to detect undiscovered and future defects in the same project. In the early stages of the software lifecycle, however, with this approach, reliable predictors cannot be built due to the lack of software defect knowledge (e.g., data with a defective or clean label). To allow SDP to be used in new projects earlier, cross-project defect prediction (CPDP) is proposed as a more practical solution. The CPDP approach aims to transfer defect prediction knowledge from a mature project (source project with sufficient labeled data) to a new project (target project with noor very limited labeled data) so that the defect predictor trained by the source project can be used to predict whether the files of the target project are defective. The CPDP technique is a promising application of transfer learning [4]. In traditional CPDP methods, handcrafted features are commonly adopted to perform CPDP (e.g., Halstead features based on operators and operands [5], McCabe features based on dependencies [6], and CKfeatures based on the object-oriented concept [7]). In recent years, some researchers [8; 9] suggested that the generic convolutional neural network (CNN) and deep belief network (DBN) models could extract semantic and structural features from project programs and applied them to perform SDP for better prediction performance. We call these features deep-learning-generated (DL-generated) features. Inspired by this, we believe that DL-generated features could also be used to improve CPDP performance. However, whether the features extracted from the program can be directly adopted to train the CPDP model requires further exploration. In a previous study [9], it was assumed that the semantic features extracted by DBN can capture the common characteristics related to defects in the source code, so the features extracted from the source project can be directly applied to the target project. However, due to different scales, functions, and coding rules of software, the data in different projects would show distribution divergence [10; 11]. As shown in Figure 1 (left), the classifiers learned in source projects do not necessarily transfer well to the target project when distribution divergence exists. If the distributions of the source and target project could be matched by a transfer learning approach, the new learning data representations would be project invariant [12], which would improve the transferability of the classifier across projects (Figure 1 (right)). To handle the impact of semantic features' distribution divergence between projects, we put forward a transfer convolutional neural network (TCNN) model to mine the transferable semantic (DL-generated) features for CPDP tasks. First, our approach parses the source file into integer vectors as the network inputs. Second, to obtain the TCNN model, a matching layer is added into CNN where the hidden representations of the source and target project-specific data are embedded into a reproducing kernel Hilbert space (RKHS) for different distribution matching. By simultaneously minimizing classification error and distribution divergence between projects, the constructed TCNN could extract the transferable DL-generated features. Third, without losing the information contained in handcrafted features, we combine the TCNN-generated features with the handcrafted features processed by transfer component analysis (TCA) to form the transferable joint features. Finally, we feed the joint features into a classifier to conduct CPDP.