Fake Currency Detection with Machine Learning

Fake Currency Detection is a real problem for both individuals and businesses. Counterfeiters are constantly finding new methods and techniques to produce counterfeit banknotes, which are essentially indistinguishable from real money. At least for the human eye. In this article, I will introduce you to Fake Currency Detection with Machine Learning.

Fake Currency Detection is a task of binary classification in machine learning. If we have enough data on real and fake banknotes, we can use that data to train a model that can classify the new banknotes as real or fake.

Also, Read – Machine Learning Full Course for free.

Fake Currency Detection

The dataset I will use in this task for fake currency detection can be downloaded from here. The dataset contains these four input characteristics:

  • The variance of the image transformed into wavelets
  • The asymmetry of the image transformed into wavelets
  • Kurtosis of the image transformed into wavelets
  • Image entropy

The target value is simply 0 for real banknotes and 1 for fake banknotes. Now let’s get started with this task of Fake Currency Detection with Machine Learning. I will start this task by importing the necessary packages:

Now, let’s have a look at the dataset, the data does not have headings so I will also assign headings in the process and then I will print the first 5 rows from the data:

       var    skew    curt     entr  auth
0  3.62160  8.6661 -2.8073 -0.44699     0
1  4.54590  8.1674 -2.4586 -1.46210     0
2  3.86600 -2.6383  1.9242  0.10645     0
3  3.45660  9.5228 -4.0112 -3.59440     0
4  0.32924 -4.4552  4.5718 -0.98880     0

Data Exploration

Now let’s start exploring the dataset. First, I’ll check the data types and if there are any missing values ​​in the data:

Code language: CSS (css)

We, therefore, have no missing values ​​in the data. We can now draw a pair diagram to get an overview of the relationship between all the entities. I will also colour the observations: blue for genuine banknotes and orange for counterfeit banknotes:

sns.pairplot(data, hue='auth') plt.show()
Code language: JavaScript (javascript)
banknotes classification

From this pair plot we can make several interesting observations:

  • The distribution of both variance and skewness appears to be quite different for the two target characteristics, while kurtosis and entropy appear to be more similar.
  • There are clear linear and nonlinear trends in the input features.
  • Some characteristics seem to be correlated.
  • Some features seem to separate genuine and fake banknotes quite well.

Now let’s check if our data is balanced against the target values:

fake currency detection

The dataset is fairly balanced, but for the binary classification task, we need to balance it perfectly. So let’s start preprocessing the data by doing just that.

Data Processing

Now we need to balance our data, the easiest way to do this is to randomly drop a number of instances of the overrepresented target function. This is called random undersampling.

Otherwise, we could also create new synthetic data for the under-represented target class. This is called oversampling. For now, let’s start by randomly deleting 152 observations of actual banknotes:

1  610
0  610
Name: auth, dtype: int64

Now we have a perfectly balanced dataset. Next, we need to divide the data into training and test sets:

Now I will standardize the data by using the StandardScalar method provided by Scikit-learn:

Logistic Regression for Fake Currency Detection

Now, I will train and test our model for fake currency detection by using the Logistic Regressing Algorithm. Let’s first fit the data on the Logistic Regression model to train the model:

clf = LogisticRegression(solver='lbfgs', random_state=42, multi_class='auto') clf.fit(x_train, y_train.values.ravel())
Code language: JavaScript (javascript)

Now let’s test the accuracy of our model:

              Pred.Negative   Pred.Positive
Act.Negative     187               6
Act.Positive      0                173
Accuracy =  98.36%

The logistic regression model achieved an accuracy of 98.36%. And not only that, when our fake currency detection model predicted that a banknote was real, it was correct 100% of the time.

Now let’s simulate the prediction of a single banknote. All we need to do is extract the features, scale them, and integrate them into our pre-trained model. We can also inspect the banknote probabilities of belonging to each target class:

Prediction: Class0
Probability [0/1]: [0.61112576 0.38887424]

Our model predicts that this banknote is real. I hope you liked this article on fake currency detection with machine learning. Feel free to ask your valuable questions in the comments section below.

Also, Read – Python Coding Interview Tips.

Follow Us:

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

Leave a Reply