sivakornchong commited on
Commit
ed2b5ab
1 Parent(s): 4dc774b
Files changed (3) hide show
  1. data/mrt_list.json +149 -0
  2. main.py +91 -0
  3. misc.py +48 -0
data/mrt_list.json ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"MRT": "Jurong East MRT Station", "location": ["1.33315281585758", "103.742286332403"]}
2
+ {"MRT": "Bukit Batok MRT Station", "location": ["1.34903331201636", "103.749566478309"]}
3
+ {"MRT": "Bukit Gombak MRT Station", "location": ["1.35861159094192", "103.751790910733"]}
4
+ {"MRT": "Choa Chu Kang MRT Station", "location": ["1.38536316540225", "103.744370779756"]}
5
+ {"MRT": "Yew Tee MRT Station", "location": ["1.39753506936297", "103.747405150236"]}
6
+ {"MRT": "Kranji MRT Station", "location": ["1.42508698073648", "103.762137459497"]}
7
+ {"MRT": "Marsiling MRT Station", "location": ["1.43252114855026", "103.774074641403"]}
8
+ {"MRT": "Woodlands MRT Station", "location": ["1.43605761708128", "103.787938777173"]}
9
+ {"MRT": "Admiralty MRT Station", "location": ["1.44058856161847", "103.800990519771"]}
10
+ {"MRT": "Sembawang MRT Station", "location": ["1.44905082158502", "103.820046140211"]}
11
+ {"MRT": "Canberra MRT Station", "location": ["1.44307664075699", "103.829702590959"]}
12
+ {"MRT": "Yishun MRT Station", "location": ["1.42944308477331", "103.835005047246"]}
13
+ {"MRT": "Khatib MRT Station", "location": ["1.41738337009565", "103.832979908243"]}
14
+ {"MRT": "Yio Chu Kang MRT Station", "location": ["1.38175587099132", "103.84494727118"]}
15
+ {"MRT": "Ang Mo Kio MRT Station", "location": ["1.36993284962264", "103.849558091776"]}
16
+ {"MRT": "Bishan MRT Station", "location": ["1.35131580146658", "103.84914026532"]}
17
+ {"MRT": "Braddell MRT Station", "location": ["1.3404690010277", "103.846799083148"]}
18
+ {"MRT": "Toa Payoh MRT Station", "location": ["1.33262928096888", "103.847502198048"]}
19
+ {"MRT": "Novena MRT Station", "location": ["1.32044079120154", "103.843825618748"]}
20
+ {"MRT": "Newton MRT Station", "location": ["1.3123189224097", "103.837984594021"]}
21
+ {"MRT": "Orchard MRT Station", "location": ["1.30242224836722", "103.823868523249"]}
22
+ {"MRT": "Somerset MRT Station", "location": ["1.30026416739006", "103.839085753124"]}
23
+ {"MRT": "Dhoby Ghaut MRT Station", "location": ["1.29891164362677", "103.84629250696"]}
24
+ {"MRT": "City Hall MRT Station", "location": ["1.29298990700923", "103.852542630339"]}
25
+ {"MRT": "Raffles Place MRT Station", "location": ["1.28393326234538", "103.851463066212"]}
26
+ {"MRT": "Marina Bay MRT Station", "location": ["1.27631114381584", "103.854604975361"]}
27
+ {"MRT": "Marina South Pier MRT Station", "location": ["1.27102703612006", "103.862447515736"]}
28
+ {"MRT": "Pasir Ris MRT Station", "location": ["1.37304331635804", "103.949284527763"]}
29
+ {"MRT": "Tampines MRT Station", "location": ["1.34551530560119", "103.938436971222"]}
30
+ {"MRT": "Simei MRT Station", "location": ["1.34319707851829", "103.953377214378"]}
31
+ {"MRT": "Tanah Merah MRT Station", "location": ["1.32718729074675", "103.946348600798"]}
32
+ {"MRT": "Bedok MRT Station", "location": ["1.32040148729112", "103.957183823478"]}
33
+ {"MRT": "Kembangan MRT Station", "location": ["1.3210381335934", "103.912947930851"]}
34
+ {"MRT": "Eunos MRT Station", "location": ["1.31978354916088", "103.903225807255"]}
35
+ {"MRT": "Paya Lebar MRT Station", "location": ["1.3172473854035", "103.892260753884"]}
36
+ {"MRT": "Aljunied MRT Station", "location": ["1.3164326118157", "103.882906044385"]}
37
+ {"MRT": "Kallang MRT Station", "location": ["1.31148890998818", "103.871386541754"]}
38
+ {"MRT": "Lavender MRT Station", "location": ["1.30737781747063", "103.862767633888"]}
39
+ {"MRT": "Bugis MRT Station", "location": ["1.30046508509717", "103.855706730933"]}
40
+ {"MRT": "City Hall MRT Station", "location": ["1.29298990700923", "103.852542630339"]}
41
+ {"MRT": "Raffles Place MRT Station", "location": ["1.28393326234538", "103.851463066212"]}
42
+ {"MRT": "Tanjong Pagar MRT Station", "location": ["1.27656131737246", "103.845725186759"]}
43
+ {"MRT": "Outram Park MRT Station", "location": ["1.2802415328084", "103.840052100136"]}
44
+ {"MRT": "Tiong Bahru MRT Station", "location": ["1.28619457890544", "103.826998939732"]}
45
+ {"MRT": "Redhill MRT Station", "location": ["1.28963453412887", "103.81674097205"]}
46
+ {"MRT": "Queenstown MRT Station", "location": ["1.29455085184931", "103.806077155982"]}
47
+ {"MRT": "Commonwealth MRT Station", "location": ["1.30250199924325", "103.798228523336"]}
48
+ {"MRT": "Buona Vista MRT Station", "location": ["1.30627534823257", "103.790363200126"]}
49
+ {"MRT": "Dover MRT Station", "location": ["1.31140529320963", "103.778637841909"]}
50
+ {"MRT": "Clementi MRT Station", "location": ["1.31511625277378", "103.765191452888"]}
51
+ {"MRT": "Jurong East MRT Station", "location": ["1.33315281585758", "103.742286332403"]}
52
+ {"MRT": "Chinese Garden MRT Station", "location": ["1.34235282081401", "103.732596738363"]}
53
+ {"MRT": "Lakeside MRT Station", "location": ["1.34425911493819", "103.720949087456"]}
54
+ {"MRT": "Boon Lay MRT Station", "location": ["1.33860405469845", "103.706064622772"]}
55
+ {"MRT": "Pioneer MRT Station", "location": ["1.33758701106708", "103.697321608474"]}
56
+ {"MRT": "Joo Koon MRT Station", "location": ["1.3277170408447", "103.678374996165"]}
57
+ {"MRT": "Gul Circle MRT Station", "location": ["1.31947090075208", "103.660530461345"]}
58
+ {"MRT": "Tuas Crescent MRT Station", "location": ["1.32102695598684", "103.649078235627"]}
59
+ {"MRT": "Tuas West Road MRT Station", "location": ["1.32998504653102", "103.639616648771"]}
60
+ {"MRT": "Tuas Link MRT Station", "location": ["1.34088242451105", "103.636991425128"]}
61
+ {"MRT": "Expo MRT Station", "location": ["1.33538252614956", "103.962374747451"]}
62
+ {"MRT": "Changi Airport MRT Station", "location": ["1.35747897447692", "103.98788356959"]}
63
+ {"MRT": "HarbourFront MRT Station", "location": ["1.26538938374901", "103.821530157095"]}
64
+ {"MRT": "Outram Park MRT Station", "location": ["1.2802415328084", "103.840052100136"]}
65
+ {"MRT": "Chinatown MRT Station", "location": ["1.28422391919085", "103.845143798953"]}
66
+ {"MRT": "Clarke Quay MRT Station", "location": ["1.28745211415803", "103.846119192727"]}
67
+ {"MRT": "Dhoby Ghaut MRT Station", "location": ["1.29891164362677", "103.84629250696"]}
68
+ {"MRT": "Little India MRT Station", "location": ["1.30724381608438", "103.849841614124"]}
69
+ {"MRT": "Farrer Park MRT Station", "location": ["1.31314029963164", "103.854754721344"]}
70
+ {"MRT": "Boon Keng MRT Station", "location": ["1.31993957653291", "103.862052698446"]}
71
+ {"MRT": "Potong Pasir MRT Station", "location": ["1.33137808528793", "103.869363547741"]}
72
+ {"MRT": "Woodleigh MRT Station", "location": ["1.33919004519388", "103.87081830915"]}
73
+ {"MRT": "Serangoon MRT Station", "location": ["1.35063361526525", "103.872771660431"]}
74
+ {"MRT": "Kovan MRT Station", "location": ["1.36017917065237", "103.885064856353"]}
75
+ {"MRT": "Hougang MRT Station", "location": ["1.37129226620797", "103.892380513029"]}
76
+ {"MRT": "Buangkok MRT Station", "location": ["1.38287001971672", "103.893122569706"]}
77
+ {"MRT": "Sengkang MRT Station", "location": ["1.39169462601522", "103.895484694279"]}
78
+ {"MRT": "Punggol MRT Station", "location": ["1.41492733388605", "103.910166388177"]}
79
+ {"MRT": "Dhoby Ghaut MRT Station", "location": ["1.29891164362677", "103.84629250696"]}
80
+ {"MRT": "Bras Basah MRT Station", "location": ["1.29686168649656", "103.850667371637"]}
81
+ {"MRT": "Esplanade MRT Station", "location": ["1.2936577245386", "103.855081226245"]}
82
+ {"MRT": "Promenade MRT Station", "location": ["1.29399798636232", "103.860350000188"]}
83
+ {"MRT": "Nicoll Highway MRT Station", "location": ["1.29976684675139", "103.86363696572"]}
84
+ {"MRT": "Stadium MRT Station", "location": ["1.3028124684707", "103.875337711089"]}
85
+ {"MRT": "Mountbatten MRT Station", "location": ["1.30620190525331", "103.882528081052"]}
86
+ {"MRT": "Dakota MRT Station", "location": ["1.30854798388121", "103.889064718377"]}
87
+ {"MRT": "Paya Lebar MRT Station", "location": ["1.3172473854035", "103.892260753884"]}
88
+ {"MRT": "MacPherson MRT Station", "location": ["1.32615024457361", "103.889298600376"]}
89
+ {"MRT": "Tai Seng MRT Station", "location": ["1.33514150139202", "103.888389300191"]}
90
+ {"MRT": "Bartley MRT Station", "location": ["1.34250117805245", "103.880177899184"]}
91
+ {"MRT": "Serangoon MRT Station", "location": ["1.35063361526525", "103.872771660431"]}
92
+ {"MRT": "Lorong Chuan MRT Station", "location": ["1.35153128621585", "103.864812169514"]}
93
+ {"MRT": "Bishan MRT Station", "location": ["1.35131580146658", "103.84914026532"]}
94
+ {"MRT": "Marymount MRT Station", "location": ["1.348707263451", "103.839423132332"]}
95
+ {"MRT": "Caldecott MRT Station", "location": ["1.33724561271722", "103.840161782075"]}
96
+ {"MRT": "Farrer Road MRT Station", "location": ["1.31743915158967", "103.807379214161"]}
97
+ {"MRT": "Holland Village MRT Station", "location": ["1.31224029631595", "103.796399122407"]}
98
+ {"MRT": "Buona Vista MRT Station", "location": ["1.30627534823257", "103.790363200126"]}
99
+ {"MRT": "one-north MRT Station", "location": ["1.29975987493555", "103.78745750525"]}
100
+ {"MRT": "Kent Ridge MRT Station", "location": ["1.29353349887123", "103.784572738173"]}
101
+ {"MRT": "Haw Par Villa MRT Station", "location": ["1.28195688684898", "103.781988990137"]}
102
+ {"MRT": "Pasir Panjang MRT Station", "location": ["1.27621352233766", "103.791350313288"]}
103
+ {"MRT": "Labrador Park MRT Station", "location": ["1.27236838626952", "103.803416232089"]}
104
+ {"MRT": "Telok Blangah MRT Station", "location": ["1.27070647717762", "103.809761611219"]}
105
+ {"MRT": "HarbourFront MRT Station", "location": ["1.26538938374901", "103.821530157095"]}
106
+ {"MRT": "Bayfront MRT Station", "location": ["1.28187378879209", "103.859079764874"]}
107
+ {"MRT": "Marina Bay MRT Station", "location": ["1.27631114381584", "103.854604975361"]}
108
+ {"MRT": "Bukit Panjang MRT Station", "location": ["1.37956121236613", "103.761188866252"]}
109
+ {"MRT": "Cashew MRT Station", "location": ["1.36981544925552", "103.76443921414"]}
110
+ {"MRT": "Hillview MRT Station", "location": ["1.36234486803558", "103.767418254007"]}
111
+ {"MRT": "Beauty World MRT Station", "location": ["1.34090149001429", "103.775746717778"]}
112
+ {"MRT": "King Albert Park MRT Station", "location": ["1.335893496278", "103.783235863233"]}
113
+ {"MRT": "Sixth Avenue MRT Station", "location": ["1.33085764536226", "103.796906838288"]}
114
+ {"MRT": "Tan Kah Kee MRT Station", "location": ["1.32639224146351", "103.806548201692"]}
115
+ {"MRT": "Stevens MRT Station", "location": ["1.32006555750626", "103.826024401924"]}
116
+ {"MRT": "Newton MRT Station", "location": ["1.3123189224097", "103.837984594021"]}
117
+ {"MRT": "Little India MRT Station", "location": ["1.30724381608438", "103.849841614124"]}
118
+ {"MRT": "Rochor MRT Station", "location": ["1.30385218527656", "103.852769428884"]}
119
+ {"MRT": "Bugis MRT Station", "location": ["1.30046508509717", "103.855706730933"]}
120
+ {"MRT": "Promenade MRT Station", "location": ["1.29399798636232", "103.860350000188"]}
121
+ {"MRT": "Bayfront MRT Station", "location": ["1.28187378879209", "103.859079764874"]}
122
+ {"MRT": "Downtown MRT Station", "location": ["1.27944638178916", "103.852840829581"]}
123
+ {"MRT": "Telok Ayer MRT Station", "location": ["1.28206894769394", "103.848648781083"]}
124
+ {"MRT": "Chinatown MRT Station", "location": ["1.28422391919085", "103.845143798953"]}
125
+ {"MRT": "Fort Canning MRT Station", "location": ["1.29248194822996", "103.844331362465"]}
126
+ {"MRT": "Bencoolen MRT Station", "location": ["1.29891843369422", "103.850353762717"]}
127
+ {"MRT": "Jalan Besar MRT Station", "location": ["1.3051713878069", "103.855295713435"]}
128
+ {"MRT": "Bendemeer MRT Station", "location": ["1.31367252847691", "103.862977620945"]}
129
+ {"MRT": "Geylang Bahru MRT Station", "location": ["1.32130110228321", "103.871622627142"]}
130
+ {"MRT": "Mattar MRT Station", "location": ["1.32687671501334", "103.883247509542"]}
131
+ {"MRT": "MacPherson MRT Station", "location": ["1.32615024457361", "103.889298600376"]}
132
+ {"MRT": "Ubi MRT Station", "location": ["1.32997425973974", "103.899226655439"]}
133
+ {"MRT": "Kaki Bukit MRT Station", "location": ["1.33496735995428", "103.908459338046"]}
134
+ {"MRT": "Bedok North MRT Station", "location": ["1.33474211664091", "103.91797832995"]}
135
+ {"MRT": "Bedok Reservoir MRT Station", "location": ["1.33660782955099", "103.932234623286"]}
136
+ {"MRT": "Tampines West MRT Station", "location": ["1.34551530560119", "103.938436971222"]}
137
+ {"MRT": "Tampines MRT Station", "location": ["1.34551530560119", "103.938436971222"]}
138
+ {"MRT": "Tampines East MRT Station", "location": ["1.35619148271544", "103.9546344625"]}
139
+ {"MRT": "Upper Changi MRT Station", "location": ["1.34173977444995", "103.961472788634"]}
140
+ {"MRT": "Expo MRT Station", "location": ["1.33538252614956", "103.962374747451"]}
141
+ {"MRT": "Woodlands North MRT Station", "location": ["1.44829245259621", "103.785692682441"]}
142
+ {"MRT": "Woodlands MRT Station", "location": ["1.43605761708128", "103.787938777173"]}
143
+ {"MRT": "Woodlands South MRT Station", "location": ["1.42739605281442", "103.79326432221"]}
144
+ {"MRT": "Springleaf MRT Station", "location": ["1.39758106126824", "103.817856949947"]}
145
+ {"MRT": "Lentor MRT Station", "location": ["1.38550657972169", "103.835743809669"]}
146
+ {"MRT": "Mayflower MRT Station", "location": ["1.37146318831015", "103.836567766945"]}
147
+ {"MRT": "Bright Hill MRT Station", "location": ["1.36328318545185", "103.832893619992"]}
148
+ {"MRT": "Upper Thomson MRT Station", "location": ["1.35441643365401", "103.832898468504"]}
149
+ {"MRT": "Caldecott MRT Station", "location": ["1.33724561271722", "103.840161782075"]}
main.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import requests
3
+ from misc import nearest_mrt
4
+ import time
5
+ import pickle
6
+ import os
7
+
8
+ ###This is to create MRT names and MRT locations
9
+ # def main(Postal_,age_,town_,storey_,room_):
10
+
11
+
12
+
13
+ ###Input structure into model is##
14
+ filename = 'finalized_model.sav'
15
+
16
+ if os.path.exists("./finalized_model.sav"):
17
+ model = pickle.load(open(filename, 'rb'))
18
+ print('loaded model')
19
+ else:
20
+ print('failed loading model')
21
+
22
+ #extract feature names#
23
+ feature_names = model.feature_names
24
+ input = [0]*len(feature_names)
25
+ print(feature_names)
26
+
27
+ #Set up mrt_list
28
+ mrt_name = []
29
+ mrt_loc = []
30
+ with open('data/mrt_list.json', 'r') as file:
31
+ for line in file:
32
+ item = json.loads(line)
33
+ mrt_name.append(item['MRT'])
34
+ loc = tuple([float(i) for i in item['location']])
35
+ mrt_loc.append(loc)
36
+
37
+ #Query for latitude and longitude
38
+
39
+
40
+ ##POSTAL
41
+ # Postal_input = Postal_
42
+ Postal_input = 680705
43
+ input[feature_names.index('Postal')] = int(Postal_input)
44
+
45
+ ##DISTANCE TO MRT
46
+ search_term = Postal_input #sample
47
+ query_string='https://developers.onemap.sg/commonapi/search?searchVal={}&returnGeom=Y&getAddrDetails=Y&pageNum=1'.format(search_term)
48
+ resp = requests.get(query_string)
49
+ data = json.loads(resp.content)
50
+ chosen_result = data['results'][0]
51
+
52
+ #Calculate the distance to nearest MRT
53
+ distance_km, nearest_mr = nearest_mrt(chosen_result['LATITUDE'], chosen_result['LONGITUDE'], mrt_name, mrt_loc)
54
+ input[feature_names.index('distance_mrt')] = distance_km
55
+ print(input)
56
+
57
+ ##STOREY
58
+ #Height is input, but then converted to the scale we used for iterating model
59
+ # height_input = storey_
60
+ height_input = 51
61
+ Height = (height_input+2)//3
62
+ input[feature_names.index('storey_height')] = Height
63
+ print(input)
64
+
65
+ ##TOWN
66
+ # town_input = town_
67
+ town_input = 'CHOA CHU KANG'
68
+ input[feature_names.index("town_"+town_input)] = 1
69
+ print(input)
70
+
71
+ ##ROOM
72
+ # room_input = room_
73
+ room_input = '4 ROOM'
74
+ input[feature_names.index("flat_num_"+room_input)] = 1
75
+ print(input)
76
+
77
+ ##AGE/ TRANSACTION YEAR [Current default to 2022]
78
+ # age_input = age_
79
+ age_input = 30
80
+ input[feature_names.index('age_transation')] = age_input
81
+ input[feature_names.index('transaction_yr')] = 2022 #Default to 2022 first
82
+ print(input)
83
+
84
+ #town is input
85
+ #distance to MRT is calculated
86
+ #age_transaction is age at transaction, which is input
87
+ #Postal is input
88
+
89
+
90
+
91
+ #reverse price adjustment is done with RPI
misc.py CHANGED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dateutil.parser import parse
2
+ import geopy.distance
3
+ import json
4
+ from datetime import datetime
5
+ import math
6
+
7
+
8
+
9
+ storey_dict = {'01 TO 03': 1, '04 TO 06': 2, '07 TO 09': 3, '10 TO 12': 4, '13 TO 15': 5, '16 TO 18': 6, '19 TO 21': 7, '22 TO 24': 8, '25 TO 27': 9, '28 TO 30': 10, '31 TO 33': 11, '34 TO 36': 12, '37 TO 39': 13, '40 TO 42': 14, '43 TO 45': 15, '46 TO 48': 16, '49 TO 51':17}
10
+ RPI_dict = {'2Q2022': 163.9, '1Q2022': 159.5, '4Q2021': 155.7, '3Q2021': 150.6, '2Q2021': 146.4, '1Q2021': 142.2, '4Q2020': 138.1, '3Q2020': 133.9, '2Q2020': 131.9, '1Q2020': 131.5, '4Q2019': 131.5, '3Q2019': 130.9, '2Q2019': 130.8, '1Q2019': 131, '4Q2018': 131.4, '3Q2018': 131.6, '2Q2018': 131.7, '1Q2018': 131.6, '4Q2017': 132.6, '3Q2017': 132.8, '2Q2017': 133.7, '1Q2017': 133.9}
11
+
12
+ def is_date(string, fuzzy=False):
13
+ """
14
+ Return whether the string can be interpreted as a date.
15
+
16
+ :param string: str, string to check for date
17
+ :param fuzzy: bool, ignore unknown tokens in string if True
18
+ """
19
+ try:
20
+ parse(string, fuzzy=fuzzy)
21
+ return True
22
+
23
+ except ValueError:
24
+ return False
25
+
26
+ def distance_to_mrt(lat, long, location):
27
+ coord_mrt = tuple(location)
28
+ coord_house = (lat, long)
29
+ distance_km = geopy.distance.distance(coord_mrt, coord_house).km
30
+ #print(distance_km)
31
+ return distance_km
32
+
33
+
34
+ def nearest_mrt(lat, long, mrt_name, mrt_loc):
35
+ count = 0
36
+ distance_km = 100
37
+ for mrt in mrt_name:
38
+ distance_cal = distance_to_mrt(lat, long, mrt_loc[count])
39
+ if distance_cal < distance_km:
40
+ nearest_mr = mrt
41
+ distance_km = distance_cal
42
+ count += 1
43
+ return distance_km, nearest_mr
44
+
45
+ def price_adj(price, qrtr_transaction):
46
+ RPI = float(RPI_dict[qrtr_transaction])
47
+ resale_price_adj = price*(133.9/RPI) #133.9 is the CPI at 1Q2017, which is our baseline
48
+ return resale_price_adj