-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ3Classification.py
48 lines (30 loc) · 1.17 KB
/
Q3Classification.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
import pandas as pd
from ast import literal_eval
from KNNDTW import KNN
nList = []
jList = []
neighbors = []
testSet = pd.read_csv('test_set_a2_t.csv', converters={"Trajectory": literal_eval},sep="\t")
trainSet = pd.read_csv('train_set.csv', converters={"Trajectory": literal_eval},index_col='tripId')
trainSetTemp = trainSet.values
for j in range(0, 5):
testSetTemp = testSet[j:j+1]
testSetTemp = testSetTemp.values
testSetTemp = testSetTemp[0][0]
neighbors = KNN(testSetTemp, trainSetTemp)
print "Nearest Neighbors:"
print "ROUND %d" % j
jList = [trainSetTemp[item][0] for item in neighbors]
#print neighbors
#print jList
#print "Max: ", max(set(jList), key=jList.count)
nList.append(max(set(jList), key=jList.count))
#for i in range(0, len(neighbors), 1):
#nList.append(neighbors[i])
#jList.append(trainSetTemp[neighbors[i]][0])
d = {'Test_Trip_ID': [i for i in range(1, len(testSet.values)+1, 1)]}
d['Predicted_JourneyPatternID'] = nList
#print d
df = pd.DataFrame(data=d)
dff = df[['Test_Trip_ID', 'Predicted_JourneyPatternID']]
dff.to_csv(path_or_buf="testSet_JourneyPatternIDs.csv", sep='\t', index=False)