Problem statement:
To predict whether a bank currency note is authentic or not based upon four attributes of the note ??
It is a binary classification problem, here we use SVM to classify currency.
import numpy as np
import pandas as pd
Import data set :
df=pd.read_csv("D:\\Raj_DataScience\\Documents\\bill_authentication.csv")
print(df.head())
Variance Skewness Curtosis Entropy Class
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
df.shape
( 1372, 5 )
Attributes & Labels :
x= df.drop('Class',axis=1)
y= df['Class']
Split the data into Train and Test :
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=51)
Implementing SVM Classifier :
Since, we are going to perform classification task, we will use support vector classifier class, which is written as SVC, and here we are using linear kernel.
from sklearn.svm import SVC
svcclassifier=SVC(kernel='linear')
svcclassifier.fit(x_train,y_train)
y_pred=svcclassifier.predict(x_test)
Model Evaluation :
from sklearn.metrics import classification_report,confusion_matrix,accuracy_score
print(confusion_matrix(y_pred,y_test))
print(classification_report(y_pred,y_test))
print(accuracy_score(y_pred,y_test))
[[159 2] [ 1 113]] precision recall f1-score support 0 0.99 0.99 0.99 161 1 0.98 0.99 0.99 114 avg / total 0.99 0.99 0.99 275 0.9890909090909091
Comments
Post a Comment