Machine learning, relying on data modeling and feature recognition techniques, constructs social risk prediction models, enabling intelligent decision-making in risk prevention and control systems. However, fraud detection tasks are constrained by the severe imbalance between positive and negative samples. In cases of extreme imbalance, even if the model predicts all transactions as normal, the accuracy can still exceed 99%, while the detection rate of fraudulent transactions is close to zero. Moreover, a single model can only capture fraud features with specific dimensions and struggles to comprehensively predict multiple fraud patterns. To address this, a ContraStacker ensemble method was proposed to overcome data imbalance limitations, compensate for the shortcomings of a single model, and accurately identify various fraud patterns to improve fraud detection rate. ContraStacker balanced the data distribution through oversampling, undersampling, and their combined strategies, constructed multiple risk predictors, and integrated contrastive loss functions into the Stacking framework to deeply fuse model predictions and original features, enhancing the model's generalization ability, successfully tackling the challenge of extreme imbalance in fraud detection. Experimental results show that ContraStacker effectively reduces False Positive Rate (FPR) (the proportion of normal transactions predicted as fraudulent ones) while maintaining a low False Negative Rate (FNR) (the proportion of fraudulent transactions predicted as normal ones), demonstrating its potential for application in financial transaction security.