Srinikesh18/Credit-Card-Fraud-Detection-ML

GitHub: Srinikesh18/Credit-Card-Fraud-Detection-ML

一个使用机器学习处理高度不平衡数据、实现信用卡欺诈检测的端到端项目。

Stars: 55 | Forks: 0

# 💳 使用机器学习进行信用卡欺诈检测 ![Python](https://img.shields.io/badge/Python-3.x-blue) ![Scikit-learn](https://img-shields.com/badge/Scikit--Learn-ML-orange) ![Status](https://img-shields.com/badge/Project-Complete-brightgreen) ## 📌 项目概述 信用卡欺诈是金融系统中的重大问题。本项目构建了一个端到端的机器学习解决方案,用于检测信用卡欺诈交易。由于数据集高度不平衡,应用了 SMOTE 等特殊技术来提高欺诈检测性能。 该项目评估了多种模型,并使用行业标准指标(如 ROC-AUC、混淆矩阵、精确率、召回率和 F1 分数)衡量性能。 ## 🚀 功能特性 - 使用 SMOTE 处理高度不平衡的数据集 - 训练多种机器学习模型 - 使用随机森林进行分类 - 使用 ROC 曲线和混淆矩阵进行评估 - 保存训练好的模型以供后续使用 - 干净、可复现的机器学习流水线 ## 📂 项目结构 Credit-Card-Fraud-Detection-ML/ │ ├── data/ │ └── creditcard.csv │ ├── notebooks/ │ └── fraud_detection.ipynb │ ├── images/ │ ├── confusion_matrix.png │ └── roc_curve.png │ ├── fraud_model.pkl ├── requirements.txt └── README.md ## 📊 数据集 - 来源:Kaggle 信用卡欺诈数据集 - 总交易数:284,807 - 欺诈案例:492(0.17%) - 特征:PCA 转换(V1–V28)、时间、金额、类别 🔗 数据集链接: https://www.kaggle.com/mlg-ulb/creditcardfraud ## ⚙️ 使用技术 - Python - Pandas、NumPy - Scikit-learn - Imbalanced-learn(SMOTE) - Matplotlib、Seaborn - Joblib ## 🧠 机器学习模型 - 逻辑回归 - 随机森林分类器(主要模型) ## ⚖️ 处理不平衡数据 该数据集高度不平衡。为解决此问题,对训练数据应用了 SMOTE(合成少数过采样技术),以生成合成欺诈样本并平衡类别。 ## 📈 模型评估 使用以下评估指标: - 混淆矩阵 - ROC 曲线 - ROC-AUC 分数 - 精确率 - 召回率 - F1 分数 ### 示例结果(随机森林) ROC-AUC 分数:~0.98 精确率:高 召回率:高 F1 分数:高 ## 🖼️ 可视化结果 ### 混淆矩阵 ![混淆矩阵](https://raw.githubusercontent.com/Srinikesh18/Credit-Card-Fraud-Detection-ML/main/images/confusion_matrix.png) ### ROC 曲线 ![ROC 曲线](https://raw.githubusercontent.com/Srinikesh18/Credit-Card-Fraud-Detection-ML/main/images/roc_curve.png) ## ▶️ 如何运行该项目 ### 1️⃣ 克隆仓库 ``` git clone https://github.com/your-username/Credit-Card-Fraud-Detection-ML.git cd Credit-Card-Fraud-Detection-ML 2️⃣ Install Requirements pip install -r requirements.txt 3️⃣ Add Dataset Download the dataset from Kaggle and place creditcard.csv inside: data/creditcard.csv 4️⃣ Run Notebook Open Jupyter Notebook and run: notebooks/fraud_detection.ipynb 💾 Saved Model The trained Random Forest model is saved as: fraud_model.pkl This can be loaded later for inference or deployment. 🔮 Future Improvements Add XGBoost or LightGBM Add Streamlit Web Application Hyperparameter tuning Real-time fraud detection API Model explainability (SHAP, LIME) ⭐ Why This Project? Real-world ML use case Industry-relevant imbalanced classification Strong evaluation methodology Great for portfolios and resumes Beginner-friendly but professional 🤝 Contributing Contributions are welcome! Feel free to open issues or submit pull requests. 📜 License This project is open-source and available under the MIT License. 🙌 Acknowledgements ULB Machine Learning Group ```
标签:Apex, F1分数, Joblib, Kaggle, Matplotlib, NumPy, Python, ROC-AUC, Scikit-learn, Seaborn, SMOTE, 不平衡数据, 信用卡交易, 信用欺诈检测, 分类算法, 召回率, 可复现管道, 异常检测, 数据预处理, 无后门, 机器学习, 模型持久化, 模型评估, 混淆矩阵, 特征工程, 端到端, 精确率, 逆向工具, 金融安全, 随机森林