Detecting Credit Card Fraud using Tensorflow

Detecting Credit Card Fraud using Tensorflow

In this article, we’ll be leveraging the power of deep learning to solve a key issue that credit card companies often have to address, namely detecting fraudulent transactions.

In this article, we’ll be leveraging the power of deep learning to solve a key issue that credit card companies often have to address, namely detecting fraudulent transactions. For this task, a Deep Neural Network (DNN) will be trained in order to do exactly that. We’ll walk through the following steps:

  1. Data Overview
  2. Data Preprocessing
  3. DNN model building
  4. DNN model evaluation
  5. Conclusion

Without further ado, let’s get started!

1. Data Overview

We got the dataset we’re using today from Kaggle and it contains two days’ worth of transactions by European cardholders. It’s important to note that due to the confidential nature of the data, a PCA transformation was done on 28 features and we have no information on what those feature names are. The only features that haven’t undergone this transformation and we can identify are ‘Time’, ‘Amount’, and ‘Class’. ‘Time_’_ represents the seconds elapsed between each transaction and the first transaction in the dataset. ‘Amount_’ _denotes the amount of each transaction and ‘Class’ refers to our target variable with 0 referring to a normal transaction and 1 referring to a fraudulent one. Our dataset also contains a total of 284,807 rows.

One thing we’d expect (and hope) from this dataset is that the target variable’s instances are imbalanced. This makes sense, right? It should as fraudulent transactions typically represent a minority of the cases. We can confirm this using the code below. We’ll also be changing the target variable’s column name so that it’s more intuitive.

#Rename Class
data.rename(columns={"Class": "isFraud"}, inplace=True)

#Percentage of fraud
fraud_per = data[data.isFraud == 1].isFraud.count() / data.isFraud.count()

This indeed turned out to be the case as only 0.17% of our transactions are fraudulent (whew)! While a low percentage of credit card fraud is certainly good news for a credit card company, it actually threatens the predictive performance of our network, especially for the fraudulent cases, so we’ll remedy this later using SMOTE. We’ll now investigate whether our dataset contains missing data.

## Looking for missing data

The output shows that our dataset contains no missing values. Next, a correlation matrix can help give us an all-rounded understanding of how the variables in our dataset relate to each other.

#Correlation Plot
plt.figure(figsize = (14,10))
plt.title('Correlation Plot', size = 20)
corr = data.corr()

neural-networks deep-learning tensorflow

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Learn TensorFlow.js - Deep Learning and Neural Networks with JavaScript

This full course introduces the concept of client-side artificial neural networks. We will learn how to deploy and run models along with full deep learning applications in the browser! To implement this cool capability, we’ll be using TensorFlow.js (TFJS), TensorFlow’s JavaScript library.

Training Neural Networks for price prediction with TensorFlow

Training Neural Networks for price prediction with TensorFlow: Learn how to make your DNN more efficient in solving regression problems: a practical guide with TensorFlow and Keras.

Bayesian Neural Networks: 2 Fully Connected in TensorFlow and Pytorch

This chapter continues the series on Bayesian deep learning. In the chapter we’ll explore alternative solutions to conventional dense neural networks.

Transfer learning for Deep Neural Networks using TensorFlow

A practical and hands-on example to know how to use transfer learning using TensorFlow. We will learn how to use transfer learning for a classification task.

Deep Learning 101 —  Neural Networks Explained

The past few decades have witnessed a massive boom in the penetration as well as the power of computation, and amidst this information.