Credit Card Fraud Detection Programming Task-San Jose State University .
As discussed in Lesson 27, can use a supervised or unsupervised algorithm to detect credit card fraud. This assignment is for you to try it yourself if you are interested. Also, It can replace your lowest quiz score if the % score of this assignment is higher than that.
Step 0: Clean Data
OBTAIN DATA FROM KAGGLE (LINKS TO AN EXTERNAL SITE.). REMOVE ALL DUPLICATES. FOR THE ATTRIBUTE “CLASS”, CHANGE 0 TO -1 SO THAT -1 REPRESENTS NORMAL AND +1 REPRESENTS FRAUD. AFTER THIS, THE RESULTING DATASET SHOULD CONTAIN 473 FRAUD AND 283253 NORMAL TRANSACTIONS.
Step 1: Scale Time & Amount
All other features were PCA transformed, except for Time & Amount. However, the ranges of these 2 features differ a lot. Therefore, the data under ‘Time’ and ‘Amount’ need to be scaled so that none of the features will weigh in a lot more. Choose an appropriate scaler (can refer to Compare the effect of different scalers on data with outliers (Links to an external site.)) to scale.
Step 2: Re-sample Data
THE DATA SET IS EXTREMELY UNBALANCED: ONLY 0.17% OF DATA ENTRIES ARE FRAUD TRANSACTIONS, WHICH IS EXPECTED SINCE FRAUD SHOULD BE ABNORMAL. PARTITION DATA SO THAT 20% OF DATA IS THE TESTING DATA AND 80% OF DATA IS THE TRAINING DATA (MAKE SURE BOTH PARTS HAVE FRAUD TRANSACTIONS!). OPTIONALLY, YOU CAN APPLY 5-FOLD CROSS-VALIDATION (CAN REFER TO SKLEARN.MODEL_SELECTION.KFOLD (LINKS TO AN EXTERNAL SITE.)). FOR THE TRAINING DATA ONLY, CHOOSE APPROPRIATE RESAMPLING TECHNIQUE(S) (CAN REFER TO UNDER-SAMPLING METHODS (LINKS TO AN EXTERNAL SITE.) AND OVER-SAMPLING METHODS (LINKS TO AN EXTERNAL SITE.)) TO RESAMPLE THE TRAINING DATA. DO NOT RESAMPLE TESTING DATA.
Step 3: Train Model
Pick a model that can be used on this problem (can refer to Credit Card + EDA + (25+) Models For Beginners (Links to an external site.)). Train the model using the resampled training data.
Step 4: Analyze Result
USE YOUR TESTING DATA TO SCORE YOUR MODEL. AT LEAST COMPUTE THE ACCURACY, PRECISION & RECALL. FEEL FREE TO EXPLORE MORE SCORING OPTIONS (LINKS TO AN EXTERNAL SITE.).
Finally, choose 1 thing to adjust, and compare the results. That is, keep everything except…
Scaler in step 1, to check the effect of different scalers (or the same scaler with different parameters);
Or resampling method in step 2, to check the effect of different resampling methods (or the same method with different parameters);
Or the model in step 3, to check the effect of different models (or the same model with different parameters).
Adjusting & testing one of them is enough. If you do more, you may get some extra credits. Also, try to explain the reason for the different results you see.
Resources to Use
You probably want to write code in Python since those pre-written machine learning packages (scikit-learn (Links to an external site.), imbalanced-learn, etc (Links to an external site.).) are written in Python. A Jupyter notebook should be enough for you to write and run your code.