-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclassification.py
74 lines (69 loc) · 2.48 KB
/
classification.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
74
import os
import os.path
import glob
from keras.models import model_from_json
from keras.layers import Dense
from keras.optimizers import SGD
import cv2
import numpy as np
import pickle as pkl
import sys
from sklearn.preprocessing import MinMaxScaler
from sklearn.naive_bayes import GaussianNB
def get_data_parts(dataline):
parts = dataline.split(" ")
Y = np.array([int(parts[0]),int(parts[1]),int(parts[2]),int(parts[3]),int(parts[4]),int(parts[5]),int(parts[6]),int(parts[7]),int(parts[8])])
Y = Y.reshape(9,1)
y_train = np.zeros([1])
#print(y_train)
if int(parts[9]) == 1:
y_train[0] = float(0.1 * 10)
else :
y_train[0] = float(0)
#y_train[0][int(parts[10])] = 0.95/4.5
#y_train[0][int(parts[11])] = 0.9/4.5
#y_train[0][int(parts[12])] = 0.8/4.5
#y_train[0][int(parts[13])] = 0.85/4.5
#print(y_train[0][int(parts[9])])
return Y , y_train
if __name__ == '__main__':
num_classes = 21
f1 = open('datasettest.txt','r')
n = f1.readline().strip()
k = 0
while k != 20000:
Y , y_train = get_data_parts(n)
for i in range(19999) :
n = f1.readline().strip()
z , z_train = get_data_parts(n)
#print(np.shape(Y))
Y = np.append(Y,z,axis = 1)
y_train = np.append(y_train,z_train,axis = 0)
k+=1
n = f1.readline().strip()
k+=1
Y = Y.T
scalar = MinMaxScaler()
Y = scalar.fit_transform(Y)
gnb = GaussianNB()
gnb.fit(Y,y_train)
print(gnb.score(Y,y_train))
#print(Y.shape)
#print(y_train.shape)
f2 = open('datasetclass.txt','r')
n = f2.readline().strip()
k = 0
while k != 100000:
Y_test , y_test = get_data_parts(n)
for i in range(99999) :
n = f2.readline().strip()
z , z_train = get_data_parts(n)
#print(np.shape(Y))
Y_test = np.append(Y_test,z,axis = 1)
y_test = np.append(y_test,z_train,axis = 0)
k+=1
n = f2.readline().strip()
k+=1
Y_test = Y_test.T
Y_test = scalar.fit_transform(Y_test)
print(gnb.score(Y_test,y_test))