Skip to content

Showcasing the deep neural network built in tensorflow for classifying credit card transactions into fraudulent or legitimate categories

License

Notifications You must be signed in to change notification settings

64nilneb/CreditCardFraudDetection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Credit Card Fraud Detection Using A Deep Neural Network (DNN)

This is a deep learning model designed to monitor credit card transaction history and activity in order to flag fraudulent purchases

Performance

The model performs with an accuracy of 99.6% over a test set of 200,000 purchases.

F1 Score: 51%

Precision: 98%

Recall: 98%

loss: 0.0103 - f1_score: 0.5068 - accuracy: 0.9964 - precision: 0.9757 - recall: 0.9830

Model Predictions

On our test data set, the model outputs these results for the first 15 purchases as a sample:

On large datasets, it has the functionality to iterate through and return an array of numbers corresponding to fraudulent purchase numbers

[15, 27, 65, 73, 96, 115, 121, 126, 134, 169, 198, 203...]

Note: 15 means the 15th purchase from the top is fraudulent, 27 is the 27th from the top, etc...

Trying the Model

Download FraudDetectionModel and add to your local directory. Then load the model using tensorflow

import tensorflow as tf
import pandas as pd

# Load the model
loaded_model = tf.keras.models.load_model("FraudDetectionModel")

# Load your data into a dataframe
dataset = pd.read_csv(file_name.csv)

Note that the loaded data must only contain the following entries:

  1. Distance from home when transaction happened
  2. Distance from last transaction
  3. Ratio of transaction purchase amount to median purchase amount
  4. Is the transaction from the same retailer?
  5. Is the transaction through the chip?
  6. Did the transaction use a PIN number?
  7. Is the transaction an online order?
# Make your predictions
predictions = tf.squeeze(tf.round(loaded_model.predict(dataset)))

# Create a table to represent your results
table = pd.DataFrame(predictions)
table.replace({0.0: 'Legitimate', 1.0: 'Fraud'}, inplace=True)
table.columns = ['Status']

# View the results
print(table)

To isolate fraudulent purchases:

fraudulent_purchases = []

# Iterates through model predictions and isolates the indices where fraudulent purchases are made
for i in range(len(predictions)):
  if predictions[i] == 1.0:
    fraudulent_purchases.append(i+1)

# The numbers in these array correspond to the purchase number in your purchase history, where 1 is the first purchase from the top, 2 is the second, etc
print(fraudulent_purchases)

Confusion Matrix

Confusion Matrix

License

MIT

About

Showcasing the deep neural network built in tensorflow for classifying credit card transactions into fraudulent or legitimate categories

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published