Skip to content
This repository was archived by the owner on Dec 28, 2018. It is now read-only.

Commit db48c7e

Browse files
committed
Feature 2 results finalised
1 parent 5edfb62 commit db48c7e

File tree

8 files changed

+12540
-6074
lines changed

8 files changed

+12540
-6074
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import numpy as np
2+
import csv
3+
from sklearn.model_selection import train_test_split
4+
from sklearn.preprocessing import OneHotEncoder
5+
from sklearn.naive_bayes import GaussianNB
6+
7+
x = []
8+
y = []
9+
10+
with open('feature2.csv') as csvfile:
11+
reader = csv.reader(csvfile, delimiter = ' ')
12+
for row in reader:
13+
x.append(row[0: (len(row))])
14+
15+
for i in x:
16+
i[0] = i[0].split(',')
17+
y.append(i[0][-1])
18+
del i[0][-1]
19+
20+
X = []
21+
for i in x:
22+
X.append(i[0])
23+
Y = []
24+
for i in y:
25+
Y.append(i)
26+
27+
#print(str(x[0]) + "\n")
28+
#print(str(x[0]) + " " + str(y[4000]) + "\n")
29+
30+
#X = np.asarray(X)
31+
#Y = np.asarray(Y)
32+
33+
x = []
34+
y = []
35+
36+
for i in X:
37+
temp = []
38+
for j in i:
39+
temp.append(float(j))
40+
x.append(temp)
41+
42+
for i in Y:
43+
temp = []
44+
for j in i:
45+
temp.append(float(j))
46+
y.append(temp)
47+
48+
#print(y[0])
49+
50+
x = np.asarray(x)
51+
y = np.asarray(y)
52+
#print(x[0])
53+
54+
#Naive Bayes Classifier
55+
56+
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.1, random_state = 42)
57+
58+
clfnb = GaussianNB()
59+
clfnb.fit(x_train, y_train)
60+
61+
print("Naive Bayes classifier")
62+
print(clfnb.score(x_test, y_test))
63+
print("\n")
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import numpy as np
2+
import csv
3+
from sklearn.model_selection import train_test_split
4+
from sklearn.preprocessing import OneHotEncoder
5+
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, BaggingClassifier, ExtraTreesClassifier, GradientBoostingClassifier
6+
from sklearn.neighbors import KNeighborsClassifier
7+
8+
x = []
9+
y = []
10+
11+
with open('feature2.csv') as csvfile:
12+
reader = csv.reader(csvfile, delimiter = ' ')
13+
for row in reader:
14+
x.append(row[0: (len(row))])
15+
16+
for i in x:
17+
i[0] = i[0].split(',')
18+
y.append(i[0][-1])
19+
del i[0][-1]
20+
21+
X = []
22+
for i in x:
23+
X.append(i[0])
24+
Y = []
25+
for i in y:
26+
Y.append(i)
27+
28+
#print(str(X[0]) + "\n")
29+
#print(str(X[0]) + " " + str(Y[4000]) + "\n")
30+
31+
X = np.asarray(X)
32+
Y = np.asarray(Y)
33+
34+
#Random Forest Classifier
35+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
36+
37+
clf = RandomForestClassifier()
38+
clf.fit(x_train, y_train)
39+
40+
print("Random Forest classifier")
41+
print(clf.score(x_test, y_test))
42+
print("\n")
43+
44+
#Adaboost Classifier
45+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
46+
47+
clf = AdaBoostClassifier()
48+
clf.fit(x_train, y_train)
49+
50+
print("AdaBoost classifier")
51+
print(clf.score(x_test, y_test))
52+
print("\n")
53+
54+
#BaggingClassifier
55+
56+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
57+
58+
clf = BaggingClassifier()
59+
clf.fit(x_train, y_train)
60+
61+
print("Bagging classifier")
62+
print(clf.score(x_test, y_test))
63+
print("\n")
64+
65+
#ExtraTreesClassifier
66+
67+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
68+
69+
clf = ExtraTreesClassifier()
70+
clf.fit(x_train, y_train)
71+
72+
print("ExtraTrees classifier")
73+
print(clf.score(x_test, y_test))
74+
print("\n")
75+
76+
#GradientBoostingClassifier
77+
78+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
79+
80+
clf = GradientBoostingClassifier()
81+
clf.fit(x_train, y_train)
82+
83+
print("GradientBoostingClassifier")
84+
print(clf.score(x_test, y_test))
85+
print("\n")
86+
87+
#Just Something
88+
89+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
90+
91+
bagging = BaggingClassifier(KNeighborsClassifier(), max_samples=0.5, max_features=0.5)
92+
bagging.fit(x_train, y_train)
93+
94+
print("Just trying something")
95+
print(bagging.score(x_test, y_test))
96+
print("\n")
97+
98+
#KneighboursClassifier
99+
100+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
101+
102+
clf = KNeighborsClassifier()
103+
clf.fit(x_train, y_train)
104+
105+
print("KNeighborsClassifier")
106+
print(clf.score(x_test, y_test))
107+
print("\n")
16.9 KB
Binary file not shown.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import numpy as np
2+
import pandas as pd
3+
import csv
4+
from sklearn import svm
5+
from sklearn.model_selection import train_test_split
6+
from sklearn.preprocessing import OneHotEncoder
7+
from sklearn import tree
8+
from sklearn.linear_model import LogisticRegression
9+
from sklearn.naive_bayes import GaussianNB
10+
11+
x = []
12+
y = []
13+
14+
with open('feature2.csv') as csvfile:
15+
reader = csv.reader(csvfile, delimiter = ' ')
16+
for row in reader:
17+
x.append(row[0: (len(row))])
18+
19+
for i in x:
20+
i[0] = i[0].split(',')
21+
y.append(i[0][-1])
22+
del i[0][-1]
23+
24+
X = []
25+
for i in x:
26+
X.append(i[0])
27+
Y = []
28+
for i in y:
29+
Y.append(i)
30+
31+
#print(str(X[0]) + "\n")
32+
#print(str(X[0]) + " " + str(Y[4000]) + "\n")
33+
34+
X = np.asarray(X)
35+
Y = np.asarray(Y)
36+
37+
x = []
38+
y = []
39+
40+
for i in X:
41+
temp = []
42+
for j in i:
43+
temp.append(float(j))
44+
x.append(temp)
45+
46+
for i in Y:
47+
temp = []
48+
for j in i:
49+
temp.append(float(j))
50+
y.append(temp)
51+
52+
#print(y[0])
53+
54+
x = np.asarray(x)
55+
y = np.asarray(y)
56+
57+
#Logistic Regression l1 classifier
58+
59+
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.5, random_state = 42)
60+
61+
clfl1 = LogisticRegression(penalty = 'l1')
62+
clfl1.fit(x_train, y_train)
63+
64+
print("Logistic Regression l1 type classifier")
65+
print(clfl1.score(x_test, y_test))
66+
print("\n")
67+
68+
#Logistic Regression l2 classifier
69+
70+
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.5, random_state = 42)
71+
72+
clfl2 = LogisticRegression(penalty = 'l2')
73+
clfl2.fit(x_train, y_train)
74+
75+
print("Logistic Regression l2 type classifier")
76+
print(clfl2.score(x_test, y_test))
77+
print("\n")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import numpy as np
2+
import csv
3+
from sklearn.model_selection import train_test_split
4+
from sklearn.preprocessing import OneHotEncoder
5+
from sklearn.linear_model import SGDClassifier
6+
7+
x = []
8+
y = []
9+
10+
with open('feature2.csv') as csvfile:
11+
reader = csv.reader(csvfile, delimiter = ' ')
12+
for row in reader:
13+
x.append(row[0: (len(row))])
14+
15+
for i in x:
16+
i[0] = i[0].split(',')
17+
y.append(i[0][-1])
18+
del i[0][-1]
19+
20+
X = []
21+
for i in x:
22+
X.append(i[0])
23+
Y = []
24+
for i in y:
25+
Y.append(i)
26+
27+
#print(str(X[0]) + "\n")
28+
#print(str(X[0]) + " " + str(Y[4000]) + "\n")
29+
30+
X = np.asarray(X)
31+
Y = np.asarray(Y)
32+
33+
x = []
34+
y = []
35+
36+
for i in X:
37+
temp = []
38+
for j in i:
39+
temp.append(float(j))
40+
x.append(temp)
41+
42+
for i in Y:
43+
temp = []
44+
for j in i:
45+
temp.append(float(j))
46+
y.append(temp)
47+
48+
print(y[0])
49+
50+
x = np.asarray(x)
51+
y = np.asarray(y)
52+
53+
#SGDClassifier
54+
55+
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.5, random_state = 42)
56+
57+
clf = SGDClassifier()
58+
clf.fit(x_train, y_train)
59+
60+
print("SGDClassifier")
61+
print(clf.score(x_test, y_test))
62+
print("\n")

Feature2_Testing/classify.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import numpy as np
2+
import csv
3+
from sklearn import svm
4+
from sklearn.model_selection import train_test_split
5+
from sklearn.preprocessing import OneHotEncoder
6+
from sklearn import tree
7+
import random
8+
9+
x = []
10+
y = []
11+
12+
with open('feature2.csv') as csvfile:
13+
reader = csv.reader(csvfile, delimiter = ' ')
14+
for row in reader:
15+
x.append(row[0: (len(row))])
16+
17+
for i in x:
18+
i[0] = i[0].split(',')
19+
y.append(i[0][-1])
20+
del i[0][-1]
21+
22+
X = []
23+
for i in x:
24+
X.append(i[0])
25+
Y = []
26+
for i in y:
27+
Y.append(i)
28+
29+
#print(str(X[0]) + "\n")
30+
#print(str(X[0]) + " " + str(Y[4000]) + "\n")
31+
32+
X = np.asarray(X)
33+
Y = np.asarray(Y)
34+
35+
for i in X:
36+
for j in i:
37+
j = float(j)
38+
39+
for i in Y:
40+
for j in i:
41+
j = float(j)
42+
43+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
44+
45+
#SVM classifier
46+
clf = svm.SVC()
47+
clf.fit(x_train, y_train)
48+
49+
print("SVM rbf kernel Classifier")
50+
print(clf.score(x_test, y_test))
51+
print("\n")
52+
53+
#Decision Tree Classifier
54+
55+
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.1, random_state = 42)
56+
57+
clftree = tree.DecisionTreeClassifier()
58+
clftree.fit(x_train, y_train)
59+
60+
print("Decision Tree Classifier")
61+
print(clftree.score(x_test, y_test))
62+
print("\n")
63+
64+
'''x = []
65+
y = []
66+
67+
for i in range(0, len(X)):
68+
a = random.uniform(0, 100)
69+
if a <= 1:
70+
x.append(X[i])
71+
y.append(Y[i])
72+
print('random sampling')
73+
74+
#SVM polynomial classifier
75+
76+
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.5, random_state = 42)
77+
78+
clf = svm.SVC(kernel = 'poly')
79+
clf.fit(x_train, y_train)
80+
81+
print("SVM polynomial kernel Classifier")
82+
print(clf.score(x_test, y_test))
83+
print("\n")'''

0 commit comments

Comments
 (0)