-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrangerPovlitz_Combination.py
More file actions
45 lines (29 loc) · 954 Bytes
/
GrangerPovlitz_Combination.py
File metadata and controls
45 lines (29 loc) · 954 Bytes
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
import pandas as pd
import copy
def combine(data, attrs):
#create a list, to store and sort the combination
tmpList = []
data = data.sort_index(axis=0)
#finds the combination for each D sub i
for i in range(data.shape[0]):
average = 0.0
for N in attrs:
average += data.iloc[i, N]
average = average/len(attrs) # do not explicitly need to divide, beacuse it is a comparison
tmpList.append(average)
data = data.assign(f=tmpList).sort_values('f', ascending=False, kind='mergesort').drop('f',axis=1)
return data
def accList(data, precisionAt):
truthList =data.iloc[:, -1].tolist()
result = []
for precision in precisionAt:
accuracy = 0.0
for i in range(precision):
accuracy+=truthList[i]
result.append(round((accuracy/precision)*100,1))
return result
def accuracy(data, attrs, precisionAt):
dataCP = copy.deepcopy(data)
dataSet = combine(dataCP, attrs)
result = accList(dataSet, precisionAt)
return result