-
Notifications
You must be signed in to change notification settings - Fork 167
/
classifier.py
73 lines (55 loc) · 1.86 KB
/
classifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# importing required libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# import GaussianNB
from sklearn.naive_bayes import GaussianNB
import cv2
# import warnings to remove any type of future warnings
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
# reading csv file and extracting class column to y.
dataf = pd.read_csv("Datasetinfectedhealthy.csv")
# extracting two features
X = dataf.drop(['imgid','fold num'], axis=1)
y = X['label']
X = X.drop('label', axis=1)
print("\nTraining dataset:-\n")
print(X)
log = pd.read_csv("datasetlog/Datasetunlabelledlog.csv")
log = log.tail(1)
X_ul = log.drop(['imgid','fold num'], axis=1)
print("\nTest dataset:-\n")
print(X_ul)
print("\n*To terminate press (q)*")
#X.plot(kind='scatter',x='feature1',y='feature2')
#plt.show()
Sum = 0
from sklearn.model_selection import train_test_split
'''
from sklearn.model_selection import train_test_split
for n in range(4):
x_train, Xi_test, y_train, yi_test = train_test_split(X, y, test_size=0.52, random_state=60)
if cv2.waitKey(1) == ord('q' or 'Q'): break
svclassifier = SVC(kernel='linear')
svclassifier.fit(x_train, y_train)
pred = svclassifier.predict(X_ul)
'''
for n in range(4):
x_train, Xi_test, y_train, yi_test = train_test_split(X, y, test_size=0.52, random_state=60)
if cv2.waitKey(1) == ord('q' or 'Q'): break
classifier = GaussianNB()
classifier.fit(x_train, y_train)
pred =classifier.predict(X_ul)
Sum = Sum + pred
print(pred)
print("\nprediction: %d" %int(Sum/4))
if(Sum < 2):
print("The leaf is sufficiently healthy!")
else:
print("The leaf is infected!")
print("\nKeypress on any image window to terminate")
#from sklearn.metrics import classification_report, confusion_matrix
#print(classification_report(yi_test,y_pred))
#print "\n Average precision percentage: %.2f" %avg_pred + "%"
cv2.waitKey(0)