Abstract:The purpose of software defect prediction is to identify code modules that may have defects in advance, assisting the software quality assurance team to allocate resources and manpower appropriately. Currently, the Software Defect Prediction method based on Stable Learning lacks global information of code images during the process of feature extraction and disregards the impact of imbalanced data on model performance. To address these issues, a Software Defect Prediction method based on Attention and Cost sensitivity is proposed here. This method enhances the neural network of SDP-SL with a global attention module that focuses on the features related to defective code in the images. Moreover, it improves the classifier's loss function to a cost sensitive loss function, mitigating the impact of class imbalance on model performance. To evaluate the performance of SDP-SLAC, multiple comparative experiments were conducted on ten open-source Java projects from the PROMISE database. The results unveil that the SDP-SLAC method effectively enhances the performance of defect prediction models.