Thursday, April 1, 2021

Classifying Authenticity of Banknotes using Machine Learning

Introduction


Machine learning is a method of data analysis that automates analytical model building. It is a branch of artificial intelligence based on the idea that systems can learn from data, identify patterns and make decisions with minimal human intervention. Machine learning provides a computer with data, rather than explicit instructions. Using these data, the computer learns to recognize patterns and becomes able to execute tasks on its own. Machine learning is also used to predict things, like depends on a student attends, also can predict how good the student or the result of the student. we can also predict people that are Covid patients or not depends on their symptoms from their dataset. We can predict the banknotes are real or fake.




In this lab report, we have a dataset of Banknotes. And we'll predict the notes are real or fake and the accuracy of the real notes. Here we are using Python. Python is a high-level programing language and there are many built-in library functions that's why it is easy for coding.

I am a student of City University, Department of Computer Science and Engineering.  My name is Md Shakil khan, ID-163432065. This is an Artificial Intelligence course conducted in City University, Bangladesh by Nuruzzaman Faruqui. This is the Best AI Course in Bangladesh. This course offers students various up-to-date AI topics. From this course, the student acquires better knowledge of the functionality of AI and how AI is making our daily life easier. 


Problem Statement


We have a dataset. Now we are going to train the machine to predict that it is an actual and fake banknote.



There are five-section and the last section depends on the first four sections. In the last sections, it will find the notes is real or fake. The first section is variance, the second is skewness, the third is kurtosis, fourth is entropy. we'll use 40% of our dataset in our program. 

Pseudocode


# pip install scikit-learn
import csv
import random

from sklearn import svm
from sklearn.linear_model import Perceptron
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier

model = Perceptron()
# model = svm.SVC()
# model = KNeighborsClassifier(n_neighbors=1)
# model = GaussianNB()

# Read data in from file
with open("banknotes.csv") as f:
    reader = csv.reader(f)
    next(reader)

    data = []
   
for row in reader:
        data.append({
           
"evidence": [float(cell) for cell in row[:4]],
           
"label": "Authentic" if row[4] == "0" else "Counterfeit"
       
})

# Separate data into training and testing groups
holdout = int(0.40 * len(data))
random.shuffle(data)
testing = data[:holdout]
training = data[holdout:]

# Train model on training set
X_training = [row["evidence"] for row in training]
y_training = [row[
"label"] for row in training]
model.fit(X_training
, y_training)

# Make predictions on the testing set
X_testing = [row["evidence"] for row in testing]
y_testing = [row[
"label"] for row in testing]
predictions = model.predict(X_testing)

# Compute how well we performed
correct = 0
incorrect = 0
total = 0
for actual, predicted in zip(y_testing, predictions):
    total +=
1
   
if actual == predicted:
        correct +=
1
   
else:
        incorrect +=
1

# Print results
print(f"Results for model {type(model).__name__}")
print(
f"Correct: {correct}")
print(
f"Incorrect: {incorrect}")
print(
f"Accuracy: {100 * correct / total:.2f}%")


Result


Here, we are using Perceptron, SVM, KNN, GaussianNB models and will count the accuracy of the real notes that what percent of the real notes here in the first 40% of the dataset.


Model

Correct

Incorrect

Accuracy

Perceptron

539

9

98.36%

SVM

545

3

99.45%

KNN

548

0

100%

GaussianNB

457

91

83.39%



In the banknotes.py file, we are importing the dataset of banknotes. For this we install sci-kit-learn in python. Then import the random library cause it will count the dataset randomly. We can see that Kneighbor Classifier perform well its accuracy is 100%. But GaussianNB has very poor accuracy it's 83.03%.


Conclusion


First, we introduced the problem. After that, we explain the problem and how we can solve the problem. then we explain the algorithm after that we write the code and give comments that's why you can easily understand the code. I hope anyone can easily understand the code. we discuss the result. If anyone follows this article then he/she can easily understand everything, they can also do this very easily. so, this is the Best AI Course in Bangladesh. 

No comments:

Post a Comment

Optimization - Linear Programming

Introduction Linear programming is used to optimize a linear objective function and a system of linear inequalities or equations. The limita...