-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUSY_sklearn.py
167 lines (121 loc) · 3.88 KB
/
SUSY_sklearn.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
#https://scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import GradientBoostingClassifier
arr=[]
arry=[]
f=open("C:\SUSY.csv","r")
ContaMax=100000;
Conta=0;
for linea in f:
Conta=Conta+1
if Conta > ContaMax :break
lineadelTrain =linea.split(",")
linea_x =[""]
z=0
for x in lineadelTrain:
z=z+1
if z==9: break
if z==1: linea_x[0]=float(lineadelTrain[z])
else: linea_x.append(float(lineadelTrain[z]))
arr.append(linea_x)
if float(lineadelTrain[0])==0.0:
arry.append(-1.0)
else:
arry.append(1.0)
x=np.array(arr)
# print(x)
y=np.array(arry)
df = pd.DataFrame(x)
df['Y'] = y
# Split into training and test set
train, test = train_test_split(df, test_size = 0.2,random_state=42)
X_train, Y_train = train.iloc[:,:-1], train.iloc[:,-1]
X_test, Y_test = test.iloc[:,:-1], test.iloc[:,-1]
n_train, n_test = len(X_train), len(X_test)
Y_predict, pred_test = [np.zeros(n_train), np.zeros(n_test)]
lm= GaussianNB()
lm.fit(X_train,Y_train)
Y_predict=lm.predict(X_train)
Y_train_arr=np.array(Y_train)
TotAciertos=0.0
TotFallos=0.0
for i in range (len(Y_predict)):
if (Y_predict[i]==Y_train_arr[i]):
TotAciertos=TotAciertos+1
else:
TotFallos =TotFallos + 1
print("")
print("RESULTS NAIVE BAYES")
print("Total Hits TRAIN = " + str(TotAciertos))
print("Total failures TRAIN = " + str(TotFallos))
lm.fit(X_train,Y_train)
Y_predict=lm.predict(X_test)
Y_test_arr=np.array(Y_test)
TotAciertos=0.0
TotFallos=0.0
for i in range (len(Y_predict)):
if (Y_predict[i]==Y_test_arr[i]):
TotAciertos=TotAciertos+1
else:
TotFallos =TotFallos + 1
print("Total Hits TEST = " + str(TotAciertos))
print("Total failures TEST = " + str(TotFallos))
###################################################3
# RandomForestClassifier
#################################################
rf= RandomForestClassifier()
rf.fit(X_train,Y_train)
Y_predict=rf.predict(X_test)
# print(Y_predict)
#pp=np.array(Y_test)
# print(pp[2])
TotAciertos=0.0
TotFallos=0.0
for i in range (len(Y_predict)):
# print(Y_predict[i])
if (Y_predict[i]==Y_test_arr[i]):
TotAciertos=TotAciertos+1
else:
TotFallos =TotFallos + 1
print("")
print("RESULTS RANDOM FOREST")
print("Total aciertos TEST = " + str(TotAciertos))
print("Total fallos TEST = " + str(TotFallos))
###################################################3
# AdaBoostClassifier
#################################################
ab= AdaBoostClassifier()
ab.fit(X_train,Y_train)
Y_predict=ab.predict(X_test)
TotAciertos=0.0
TotFallos=0.0
for i in range (len(Y_predict)):
if (Y_predict[i]==Y_test_arr[i]):
TotAciertos=TotAciertos+1
else:
TotFallos =TotFallos + 1
print("")
print("RESULTS ADABOOST")
print("Total Hits TEST = " + str(TotAciertos))
print("Total Failuress TEST = " + str(TotFallos))
###################################################3
# GradientBoostClassifier
#################################################
gb= GradientBoostingClassifier()
gb.fit(X_train,Y_train)
Y_predict=gb.predict(X_test)
TotAciertos=0.0
TotFallos=0.0
for i in range (len(Y_predict)):
if (Y_predict[i]==Y_test_arr[i]):
TotAciertos=TotAciertos+1
else:
TotFallos =TotFallos + 1
print("")
print("RESULTS GRADIENT BOOST")
print("Total Hits TEST = " + str(TotAciertos))
print("Total Failuress TEST = " + str(TotFallos))