Introduction Machine learning is what it exactly sounds like. You will train a machine to teach it how to learn. Once it learns through trai...
Introduction
Machine learning is what it exactly sounds like. You will train a machine to teach it how to learn. Once it learns through training i.e., gaining experiences on data it can make decisions in a new environment. But data should be expressed in a way that machines can understand. Mainly you can teach a machine in 3 ways. Those are Supervised Learning, Unsupervised Learning, and Re-enforcement learning.
In this lab report, we will use supervised learning to teach
an AI to recognize fake banknotes. So, what is supervised learning? In supervised learning, you will have to make a
dataset that contains input-output pairs. What you will do is tell the
machine, that, hey, if this is the input then you should get that output. That
way machines can train them and when they encounter a similar based problem,
machines can easily give an output. One of the major tasks in supervised
learning is classification. You can teach a machine to label on the dataset to
recognize something.
This report is a part of the Artificial Intelligence course Lab-work under supervision of Nuruzzaman Faruqui, Lecturer of City University, Bangladesh. This course offers students various up-to-date AI topics. Students get to explore the real applicable approaches through AI. From this course, the student acquires better knowledge of the functionality of AI and how AI is making our daily life easier. This is the best Artificial Intelligence course in Bangladesh.
Problem statement
Think about how your teacher teaches you
in a class. The teacher teaches you with a fixed curriculum. In machine learning, we
call it “training”. When a teacher takes your test to evaluate your performance,
he doesn’t necessarily give you the exact same study material that you practiced on
training. The teacher gives you similar types of questions on the same topic. We call it
“testing”.
So, we are going to train a machine on a dataset and then
put it on testing. As an example, we will use a nicely pre-clean dataset. We
will use perceptron learning, SVM, K-nearest neighbor, and GaussianNB to check
which classification model performs well on our data.
Let’s jump onto the code now:
# 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
|
Model |
Correct |
Incorrect |
Accuracy |
|
Perceptron |
539 |
9 |
98.36% |
|
SVM |
545 |
3 |
99.45% |
|
KNN |
548 |
0 |
100% |
|
GaussianNB |
457 |
91 |
83.39% |
Conclusion
Machine learning is a great way to get solutions to real-life problems more conveniently. It would take many times for humans what we
did in this report. But after training the machine banknote can be easily
recognized if it’s fake or authentic. There is many more model to try than we
have used here in this report. If you found this interesting then be sure to
explore. Computer Science is all about how broadly you can explore. The more
you surf, the more you learn something to apply.
As you can probably tell now how easily this concept is
described above. Anyone with basic discrete mathematics knowledge can
understand this. Our honorable instructor’s well-explained teaching method is
the main reason for successfully grasping every topic of this course quickly.
That’s why this is the best AI course in Bangladesh.

No comments