This is a deep learning model designed to monitor credit card transaction history and activity in order to flag fraudulent purchases
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.9830On 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...
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:
- Distance from home when transaction happened
- Distance from last transaction
- Ratio of transaction purchase amount to median purchase amount
- Is the transaction from the same retailer?
- Is the transaction through the chip?
- Did the transaction use a PIN number?
- 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)
