# Bank Note Authentication using Random Forest – with source code – easy project – 2022 In today’s blog, we will see that how we can perform Bank Note Authentication or how we can classify Bank Notes into fake or authentic classes based on numeric features like variance, skewness, kurtosis, entropy. This is going to be a very short blog, so without any further due.

### Let’s do it…

#### Code for Bank Note Authentication…

```import pandas as pd
import pickle
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

X = df.iloc[:,:-1]
y = df.iloc[:,-1]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

rf = RandomForestClassifier()
rf.fit(X_train,y_train)

pred = rf.predict(X_test)

score = accuracy_score(y_test,pred)

print(score)

with open('classifier.pkl','wb') as file:
pickle.dump(rf,file)

print('Model saved!!!')

#Let's test a random set of values
print(rf.predict([[-2,-3,1,1]]))```
• Line 1-5 – Importing required libraries.
• Line 7 – Reading the whole data which is in csv form.
• Line 9 – Let’s see the head of our data.
• Line 11 – Select all the rows and all columns except the last column as X_train.
• Line 12 – Select all rows and last column as y_train.
• Line 14 – Let’s see the X data.
• Line 15 – Let’s see the y data.
• Line 17 – Splitting the data in 70-30 proportions. 70% data is kept for training and 30% for testing.
• Line 19 – Create a Random Forest Classifier model.
• Line 20 – Fit the training data into our Bank Note Authentication classifier.
• Line 22 – Let’s make predictions on test data to see how our model is performing.
• Line 24 – Let’s calculate the score by comparing our predictions on test data with true labels.
• Line 26 – Printing the score/accuracy on test data.