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.
1 attachmentsSlide 1 of 1attachment_1attachment_1
Unformatted Attachment Preview
Extra Assignment 2
Step O Finished
Step 1 Finished
Step 2 Finished
2 pts 1 pts
Full Marks Testing data also resampled
Only partitioned, no resampling
No Marks 2 pts
Step 3 Finished
Step 4 Finished
All Required Files Submitted 2 pts
Total Points: 10
Purchase answer to see full
User generated content is uploaded by users for the purposes of learning and should be used following Studypool’s honor code & terms of service.