Skip to main content

تحلیل و شناسایی تقلب در معاملات مالی با یادگیری ماشین و یادگیری عمیق

پروژهٔ شناسایی تقلب در تراکنش‌های کارت اعتباری با ترکیب مدل‌های یادگیری ماشین کلاسیک، یادگیری عمیق جدولی (TabNet) و مدل‌های ترکیبی XGBoost + TabNet و LightGBM + TabNet.

  • مجموعه‌داده: Credit Card Fraud (ULB) — ۲۸۴٬۸۰۷ تراکنش، ۴۹۲ تقلب (۰٫۱۷۲٪)
  • تقسیم داده: ۸۰٪ آموزش / ۱۵٪ اعتبارسنجی / ۵٪ آزمون
  • تفسیرپذیری: SHAP، LIME، ELI5

روش کلی

  1. بارگذاری و تحلیل اکتشافی داده (EDA)
  2. پیش‌پردازش (RobustScaler) و SMOTE روی دادهٔ آموزش
  3. آموزش مدل‌های پایه: Logistic Regression، Random Forest، XGBoost، LightGBM، SVM
  4. آموزش TabNet (شبکهٔ عمیق جدولی)
  5. ترکیب XGBoost+TabNet و LightGBM+TabNet با میانگین وزن‌دار و Stacking
  6. ارزیابی، مقایسه و تفسیرپذیری
  7. ذخیرهٔ نتایج در results/<timestamp>/

جزئیات مدل‌ها: docs/methodology.md

ساختار پروژه

creditcard-fraud-xgb-tabnet/
├── main.py                    # نقطه ورود
├── src/                       # کد پکیج fraud_detection
│   ├── config.py
│   ├── pipeline.py
│   ├── output.py
│   ├── data/                  # بارگذاری و پیش‌پردازش
│   ├── eda/
│   ├── models/
│   ├── evaluation/
│   ├── visualization/
│   └── interpretability/
├── dataset/                   # creditcard.csv (دانلود خودکار)
├── docs/
│   └── methodology.md
├── results/                   # خروجی هر اجرا
│   └── YYYYMMDD_HHMMSS/
│       ├── run_info.json
│       ├── figures/
│       └── metrics/
├── requirements.txt
└── pyproject.toml

نصب

conda activate myenv
pip install -r requirements.txt
pip install -e .

پس از pip install -e . پوشهٔ fraud_detection.egg-info/ ساخته می‌شود (artifact نصب؛ در .gitignore است و نیازی به commit ندارد).

اجرا

conda activate myenv
python main.py

یا:

fraud-detection

هر اجرا یک پوشهٔ جدید با نام timestamp (مثلاً results/20250726_183045/) می‌سازد.

گزارش PDF از نتایج یک ران

برای دیدن همهٔ جداول و شکل‌ها در یک فایل (به‌ترتیب پایپلاین):

conda activate myenv
python -m fraud_detection.reporting.generate_report --run 20260726_194158

خروجی‌ها:

  • results/<run>/report/report.tex
  • results/<run>/report/report.pdf
  • کپی آسان‌دسترس: reports/report_<run>.pdf

GPU

TabNet در صورت وجود CUDA روی GPU آموزش می‌بیند؛ در غیر این صورت روی CPU اجرا می‌شود.

داده

ترتیب بارگذاری در load_creditcard_dataset():

  1. CREDITCARD_CSV یا dataset/creditcard.csv
  2. kagglehub (نیاز به احراز هویت Kaggle)
  3. آینهٔ Zenodo

خروجی‌ها

هر run در results/<timestamp>/ ذخیره می‌شود:

مسیر توضیح
run_info.json اطلاعات اجرا (timestamp و مسیرها)
figures/*.png نمودارها
metrics/*.csv, metrics.json نتایج عددی و LaTeX

مستندات

  • docs/methodology.md — روش‌شناسی، توضیح مدل‌ها و جریان pipeline

Metadata

Release files for fraud-detection-xy 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fraud-detection-xy 1.0.2
File Size Uploaded Provenance Actions
fraud_detection_xy-1.0.2.tar.gz 22.3 kB Without provenance Details for fraud_detection_xy-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fraud-detection-xy 1.0.2
File Interpreter ABI Platform Actions
fraud_detection_xy-1.0.2-py3-none-any.whl Python 3 none any Details for fraud_detection_xy-1.0.2-py3-none-any.whl

Total release size: 49.1 kB

Release files / fraud_detection_xy-1.0.2.tar.gz

Download URL fraud_detection_xy-1.0.2.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0ea90c09252010f820d83f36ed3e6276e162ac42a8a9c1861d9dafff88e6f157
BLAKE2b-256 checksum
How to use checksums
e525fdf28b49f3df370811e830fae4601319b6caff3ef41265e601e3dd09bc74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / fraud_detection_xy-1.0.2-py3-none-any.whl

Download URL fraud_detection_xy-1.0.2-py3-none-any.whl
Size 26.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a6e1ae07be8cdb05e429107580ff797fdc0a147938fa9e7ecbad10a9ac3c763
BLAKE2b-256 checksum
How to use checksums
3417c44d3dc36923e0873ecdcde1dbd88b45a64880cb2653ebc5d4d17cfcea60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Security for fraud-detection-xy 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page