-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetResult.py
64 lines (53 loc) · 1.74 KB
/
getResult.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
from sklearn.ensemble import ExtraTreesClassifier
import numpy as np
#get all data
#devide features and label
trainingData = open("training.csv")
trainingLabels = []
trainingFeatures = []
for line in trainingData.readlines():
features = line.strip().split(',')
print features
trainingLabels.append(int(features.pop()))
trainingFeatures.append([float(i) for i in features])
print "hello"
testingData = open("test.csv")
testingLabels = []
testingFeatures = []
for line in testingData.readlines():
features = line.strip().split(',')
print features
testingLabels.append(0)
features.pop()
testingFeatures.append([float(i) if i!='' else 0 for i in features])
print testingFeatures
print testingLabels
print "training extra trees forest"
clf = ExtraTreesClassifier(n_estimators=1000, n_jobs=8, min_samples_split=10)
clf.fit(trainingFeatures, trainingLabels)
pred_label_test = clf.predict(testingFeatures)
np.reshape(pred_label_test,(-1,1))
testingStandardData = open("testStandard.csv")
true = 0
false = 0
fp = 0
fn = 0
tp = 0
tn = 0
n = 0
for line in testingStandardData.readlines():
#print pred_label_test[n], line
if pred_label_test[n]==0 and int(line.strip().split(',')[-1])==1:
fp+=1
if pred_label_test[n]==1 and int(line.strip().split(',')[-1])==0:
fn+=1
if pred_label_test[n]==0 and int(line.strip().split(',')[-1])==0:
tn+=1
if pred_label_test[n]==1 and int(line.strip().split(',')[-1])==1:
tp+=1
if pred_label_test[n]==int(line.strip().split(',')[-1]):
true += 1
else:
false += 1
n += 1
print "true"+str(true)+";false"+str(false)+"ratio:"+str(float(true)/(false+true))+' '+"fp"+' '+str(fp)+' '+str(float(fp)/n)+' '+'fn'+' '+str(fn)+' '+str(float(fn)/n)+' '+'tn'+' '+str(tn)+' '+str(float(tn)/n)+' '+'tp'+' '+str(tp)+' '+str(float(tp)/n)