This Jupyter notebook predicts credit card fraud using machine learning, exploring data, preprocessing imbalances, training models, and optimizing performance. It uses anonymized features (V1–V28), Time, Amount, and a binary Class label (0 for non-fraud, 1 for fraud).
- Importing Required Libraries: Loads
pandas,numpy,seaborn,matplotlib,sklearn,imbalanced-learn,xgboost, and metrics for analysis and modeling. - Load Data: Imports the
creditcard.csvdataset containing transaction details. - Exploratory Data Analysis (EDA): Analyzes dataset shape, info, first rows, summary statistics, and class distribution to identify patterns.
- Data Preprocessing: Engineers features (
Hour,Amount_to_Mean,Hourly_Fraud_Rate,Log_Amount), scales features, and splits data into train, validation, and test sets with SMOTE. - Handle Imbalanced Data: Applies SMOTE to oversample the minority (fraud) class.
- Model Training: Trains Logistic Regression, Random Forest, and XGBoost with cross-validation, ROC curves, and confusion matrices.
- Hyperparameter Tuning: Optimizes Random Forest using RandomizedSearchCV for recall, with threshold tuning.
- Model Evaluation: Evaluates the tuned Random Forest model on the test set with classification report, ROC-AUC, and confusion matrix.
- Conclusion: Summarizes key features (
V4,V11,Hourly_Fraud_Rate), performance, trade-offs, and next steps.
- Clone the repository and navigate to the project folder:
git clone https://github.com/rk0802p/cc-fraud-detection.git cd cc-fraud-detection