From 87890926adc012afe7578d1fa201950c53c94789 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Mon, 9 Jan 2017 14:12:22 +0000 Subject: [PATCH] adding back filter t-vals lost in commit squash --- src/pg/sql/21_gwr.sql | 10 ++++++---- src/py/crankshaft/crankshaft/regression/gwr_cs.py | 7 ++++++- src/py/crankshaft/test/test_regression_gwr.py | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pg/sql/21_gwr.sql b/src/pg/sql/21_gwr.sql index fd22cea..e28bfb2 100644 --- a/src/pg/sql/21_gwr.sql +++ b/src/pg/sql/21_gwr.sql @@ -1,17 +1,19 @@ CREATE OR REPLACE FUNCTION CDB_GWR(subquery text, dep_var text, ind_vars text[], bw numeric default null, fixed boolean default False, - kernel text default 'bisquare') + kernel text default 'bisquare', geom_col text default 'the_geom', + id_col text default 'cartodb_id') RETURNS table(coeffs JSON, stand_errs JSON, t_vals JSON, - predicted numeric, residuals numeric, r_squared numeric, - bandwidth numeric, rowid bigint) + filtered_t_vals JSON, predicted numeric, + residuals numeric, r_squared numeric, bandwidth numeric, + rowid bigint) AS $$ from crankshaft.regression import GWR gwr = GWR() -return gwr.gwr(subquery, dep_var, ind_vars, bw, fixed, kernel) +return gwr.gwr(subquery, dep_var, ind_vars, bw, fixed, kernel, geom_col, id_col) $$ LANGUAGE plpythonu; diff --git a/src/py/crankshaft/crankshaft/regression/gwr_cs.py b/src/py/crankshaft/crankshaft/regression/gwr_cs.py index 8d75608..ad7e1d6 100644 --- a/src/py/crankshaft/crankshaft/regression/gwr_cs.py +++ b/src/py/crankshaft/crankshaft/regression/gwr_cs.py @@ -77,8 +77,11 @@ class GWR: coeffs = [] stand_errs = [] t_vals = [] + filtered_t_vals = [] # extracted model information + c_alpha = model.adj_alpha + filtered_t = model.filter_tvals(c_alpha[1]) predicted = model.predy.flatten() residuals = model.resid_response r_squared = model.localR2.flatten() @@ -92,8 +95,10 @@ class GWR: for k, var in enumerate(ind_vars)})) t_vals.append(json.dumps({var: model.tvalues[idx, k] for k, var in enumerate(ind_vars)})) + filtered_t_vals.append(json.dumps({var: filtered_t[idx, k] + for k, var in enumerate(ind_vars)})) - return zip(coeffs, stand_errs, t_vals, + return zip(coeffs, stand_errs, t_vals, filtered_t_vals, predicted, residuals, r_squared, bw, rowid) def gwr_predict(self, subquery, dep_var, ind_vars, diff --git a/src/py/crankshaft/test/test_regression_gwr.py b/src/py/crankshaft/test/test_regression_gwr.py index 6d3400e..3ee9668 100644 --- a/src/py/crankshaft/test/test_regression_gwr.py +++ b/src/py/crankshaft/test/test_regression_gwr.py @@ -58,7 +58,7 @@ class GWRTest(unittest.TestCase): fixed=self.params['fixed']) # unpack response - coeffs, stand_errs, t_vals, predicteds, residuals, r_squareds, bws, rowids = zip(*gwr_resp) + coeffs, stand_errs, t_vals, t_vals_filtered, predicteds, residuals, r_squareds, bws, rowids = zip(*gwr_resp) # known_coeffs = self.knowns['coeffs'] # data packed from https://github.com/TaylorOshan/pysal/blob/a44c5541e2e0d10a99ff05edc1b7f81b70f5a82f/pysal/examples/georgia/georgia_BS_NN_listwise.csv