finishes python tests for regression
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -25,7 +25,7 @@ class GWRTest(unittest.TestCase):
|
||||
fixture packed from canonical GWR georgia dataset using the
|
||||
following query:
|
||||
SELECT array_agg(x) As x,
|
||||
array_agg(x) As y,
|
||||
array_agg(y) As y,
|
||||
array_agg(pctbach) As dep_var,
|
||||
array_agg(pctrural) As attr1,
|
||||
array_agg(pctpov) As attr2,
|
||||
@@ -33,8 +33,8 @@ class GWRTest(unittest.TestCase):
|
||||
array_agg(areakey) As rowid
|
||||
FROM g_utm
|
||||
WHERE pctbach is not NULL AND
|
||||
pctpov IS NOT NULL AND
|
||||
pctrural IS NOT NULL AND
|
||||
pctpov IS NOT NULL AND
|
||||
pctblack IS NOT NULL
|
||||
"""
|
||||
self.data = json.loads(
|
||||
@@ -46,12 +46,13 @@ class GWRTest(unittest.TestCase):
|
||||
'dep_var': 'pctbach',
|
||||
'ind_vars': ['pctrural', 'pctpov', 'pctblack'],
|
||||
'bw': 90.000,
|
||||
'fixed': False}
|
||||
'fixed': False,
|
||||
'geom_col': 'the_geom',
|
||||
'id_col': 'areakey'}
|
||||
|
||||
def test_gwr(self):
|
||||
"""
|
||||
"""
|
||||
|
||||
gwr = GWR(FakeDataProvider(self.data))
|
||||
gwr_resp = gwr.gwr(self.params['subquery'], self.params['dep_var'],
|
||||
self.params['ind_vars'], bw=self.params['bw'],
|
||||
@@ -62,11 +63,8 @@ class GWRTest(unittest.TestCase):
|
||||
|
||||
# known_coeffs = self.knowns['coeffs']
|
||||
# data packed from https://github.com/TaylorOshan/pysal/blob/a44c5541e2e0d10a99ff05edc1b7f81b70f5a82f/pysal/examples/georgia/georgia_BS_NN_listwise.csv
|
||||
coeff_known_inter = self.knowns['est_intercept']
|
||||
coeff_known_pctpov = self.knowns['est_pctpov']
|
||||
coeff_known_pctrural = self.knowns['est_pctrural']
|
||||
coeff_known_pctblack = self.knowns['est_pctblack']
|
||||
# coeff_known_pcteld = self.knowns['est_pcteld']
|
||||
tval_known_pctblack = self.knowns['t_pctrural']
|
||||
pctpov_se = self.knowns['se_pctpov']
|
||||
ids = self.knowns['area_key']
|
||||
resp_idx = None
|
||||
@@ -78,30 +76,16 @@ class GWRTest(unittest.TestCase):
|
||||
with open('gwr_test_data.json', 'w') as f:
|
||||
print("writing to file")
|
||||
f.write(str(zip(rowids, coeffs)))
|
||||
|
||||
# test pctpov coefficient estimates
|
||||
for idx, val in enumerate(coeff_known_pctpov):
|
||||
# print idx, val, ids[idx], rowids[rowids.index(ids[idx])]
|
||||
resp_idx = rowids.index(ids[idx])
|
||||
if resp_idx is None:
|
||||
print('missed lookup on {0}'.format(ids[idx]))
|
||||
print('comparison: %d: %f, %f' % (
|
||||
rowids[resp_idx],
|
||||
val,
|
||||
json.loads(coeffs[resp_idx])['pctpov']))
|
||||
# print('comparison: %f, %f, %f, %f, | Intercepts: (%f, %f)' % (
|
||||
# val,
|
||||
# json.loads(coeffs[resp_idx])['pctpov'],
|
||||
# json.loads(coeffs[resp_idx])['pctrural'],
|
||||
# json.loads(coeffs[resp_idx])['pctblack'],
|
||||
# coeff_known_inter[idx],
|
||||
# json.loads(coeffs[resp_idx])['intercept']))
|
||||
# self.assertAlmostEquals(val, coeffs[resp_idx])
|
||||
|
||||
assert False
|
||||
|
||||
# labels = [a[1] for a in clusters]
|
||||
# c1 = [a for a in clusters if a[1] == 0]
|
||||
# c2 = [a for a in clusters if a[1] == 1]
|
||||
#
|
||||
# self.assertEqual(len(np.unique(labels)), 2)
|
||||
# self.assertEqual(len(c1), 20)
|
||||
# self.assertEqual(len(c2), 20)
|
||||
self.assertAlmostEquals(val,
|
||||
json.loads(coeffs[resp_idx])['pctpov'],
|
||||
places=4)
|
||||
# test pctrural tvals
|
||||
for idx, val in enumerate(tval_known_pctblack):
|
||||
resp_idx = rowids.index(ids[idx])
|
||||
self.assertAlmostEquals(val,
|
||||
json.loads(t_vals[resp_idx])['pctrural'],
|
||||
places=4)
|
||||
|
||||
Reference in New Issue
Block a user