Git Product home page Git Product logo

fraud-detection's Introduction

Credit Card Fraud Detection using Machine Learning

Credit card fraud is a growing issue with many challenges including temporal drift and heavy class imbalance. This project attempts to tackle class imbalance using state-of-the-art techniques including Adaptive Synethtic Sampling Approach (ADASYN) and Synethetic Minority Oversampling Technique (SMOTE). Over 280k real transactions made in Europe in September 2013 [1] are used as the training dataset. Three types of machine learning models are compared: Random Forest, Support Vector Machine, and Multi-Layer Perceptron. Results show that the optimal sampling method for an imbalanced dataset is dependent on the dataset and the model being used.

This project has the following components:

a) IEEE style Paper in PDF format

b) Jupyter Notebook walking through machine learning tests conducted. You can run view and run them yourself. Included are also comments, reasoning, and figures. For your convenience I have included a copy of the original dataset [1] in this git repo, however please refer to the original source for the most up-to-date version.

This project was done as part of SYDE 522: Machine Learning at the University of Waterloo in Winter 2017.

Installation

  1. Clone the project:

    $ git clone https://github.com/yazanobeidi/fraud-detection.git && cd fraud-detection

  2. Pip-install dependencies. For example using a virtualenv:

    $ virtualenv env && source env/bin/activate && pip install -r requirements.txt

Usage

a) Read the Paper (PDF):

credit_card_fraud_detection_yazan_obeidi.pdf

b) Run the Jupyter Notebook:

  1. First unzip the dataset:

$ unzip data/creditcardfraud.zip

  1. Generate a balanced dataset using ADASYN resampling (this will take several minutes):

$ python adasyn.py

  1. Run the notebook:

$ jupyter notebook

Authors

Yazan Obeidi

Copyright

2017, Yazan Obeidi

References

[1] Kaggle. (2017, Jan. 12). Credit Card Fraud Detection [Online]. Available: https://www.kaggle.com/dalpozz/creditcardfraud

fraud-detection's People

Contributors

yazanobeidi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fraud-detection's Issues

FileNotFoundError: [Errno 2] No such file or directory: 'pickle/train_data_resampled.pkl'

System: Ubuntu 16.4
User: root
Python: 2
console:
`python adasyn.py
Loading creditcard.csv
test
starting...
adasyn.py:24: DeprecationWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
np.array(X_train.ix[:, X_train.columns != 'Class']),
pickling...
Traceback (most recent call last):
File "adasyn.py", line 28, in
with open('pickle/train_data_resampled.pkl', 'wb+') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'pickle/train_data_resampled.pkl'
`

Jupyter notebook project.ipynb:
In[13]:

Resample the Training Data using ADASYN

The test data remains imbalanced

#from imblearn.over_sampling import ADASYN
#ada = ADASYN()
#data_resampled, data_labels_resampled = ada.fit_sample(

np.array(X_train.ix[:, X_train.columns != 'Class']),

np.array(X_train.Class))

SLOW so will just unpickle something that was run previously

with open('pickle/train_data_resampled.pkl', 'rb') as f:
X_train_resampled = pickle.load(f)
with open('pickle/train_data_labels_resampled.pkl', 'rb') as f:
X_train_labels_resampled = pickle.load(f)

print(Counter(X_train_labels_resampled))

X_train_resampled = pd.DataFrame(X_train_resampled)
X_train_labels_resampled = pd.DataFrame(X_train_labels_resampled)
X_train_resampled = pd.concat([X_train_resampled, X_train_labels_resampled], axis=1)
X_train_resampled.columns = X_train.columns
X_train_resampled.head()

`FileNotFoundError Traceback (most recent call last)
in
8 # np.array(X_train.Class))
9 # SLOW so will just unpickle something that was run previously
---> 10 with open('pickle/train_data_resampled.pkl', 'rb') as f:
11 X_train_resampled = pickle.load(f)
12 with open('pickle/train_data_labels_resampled.pkl', 'rb') as f:

FileNotFoundError: [Errno 2] No such file or directory: 'pickle/train_data_resampled.pkl'`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.