def test_Prediction(self): coords =np.array(self.coords) index = np.arange(len(self.y)) test = index[-10:] X_test = self.X[test] coords_test = list(coords[test]) model = GWR(self.coords, self.y, self.X, 93, family=Gaussian(), fixed=False, kernel='bisquare') results = model.predict(coords_test, X_test) params = np.array([22.77198, -0.10254, -0.215093, -0.01405, 19.10531, -0.094177, -0.232529, 0.071913, 19.743421, -0.080447, -0.30893, 0.083206, 17.505759, -0.078919, -0.187955, 0.051719, 27.747402, -0.165335, -0.208553, 0.004067, 26.210627, -0.138398, -0.360514, 0.072199, 18.034833, -0.077047, -0.260556, 0.084319, 28.452802, -0.163408, -0.14097, -0.063076, 22.353095, -0.103046, -0.226654, 0.002992, 18.220508, -0.074034, -0.309812, 0.108636]).reshape((10,4)) np.testing.assert_allclose(params, results.params, rtol=1e-03) bse = np.array([2.080166, 0.021462, 0.102954, 0.049627, 2.536355, 0.022111, 0.123857, 0.051917, 1.967813, 0.019716, 0.102562, 0.054918, 2.463219, 0.021745, 0.110297, 0.044189, 1.556056, 0.019513, 0.12764, 0.040315, 1.664108, 0.020114, 0.131208, 0.041613, 2.5835, 0.021481, 0.113158, 0.047243, 1.709483, 0.019752, 0.116944, 0.043636, 1.958233, 0.020947, 0.09974, 0.049821, 2.276849, 0.020122, 0.107867, 0.047842]).reshape((10,4)) np.testing.assert_allclose(bse, results.bse, rtol=1e-03) tvalues = np.array([10.947193, -4.777659, -2.089223, -0.283103, 7.532584, -4.259179, -1.877395, 1.385161, 10.033179, -4.080362, -3.012133, 1.515096, 7.106862, -3.629311, -1.704079, 1.17042, 17.831878, -8.473156, -1.633924, 0.100891, 15.750552, -6.880725, -2.74765, 1.734978, 6.980774, -3.586757, -2.302575, 1.784818, 16.644095, -8.273001, -1.205451, -1.445501, 11.414933, -4.919384, -2.272458, 0.060064, 8.00251, -3.679274, -2.872176, 2.270738]).reshape((10,4)) np.testing.assert_allclose(tvalues, results.tvalues, rtol=1e-03) localR2 = np.array([[ 0.53068693], [ 0.59582647], [ 0.59700925], [ 0.45769954], [ 0.54634509], [ 0.5494828 ], [ 0.55159604], [ 0.55634237], [ 0.53903842], [ 0.55884954]]) np.testing.assert_allclose(localR2, results.localR2, rtol=1e-05) predictions = np.array([[ 10.51695514], [ 9.93321992], [ 8.92473026], [ 5.47350219], [ 8.61756585], [ 12.8141851 ], [ 5.55619405], [ 12.63004172], [ 8.70638418], [ 8.17582599]]) np.testing.assert_allclose(predictions, results.predictions, rtol=1e-05)
def test_Prediction(self): coords = np.array(self.coords) index = np.arange(len(self.y)) test = index[-10:] X_test = self.X[test] coords_test = list(coords[test]) model = GWR(self.coords, self.y, self.X, 93, family=Gaussian(), fixed=False, kernel='bisquare') results = model.predict(coords_test, X_test) params = np.array([ 22.77198, -0.10254, -0.215093, -0.01405, 19.10531, -0.094177, -0.232529, 0.071913, 19.743421, -0.080447, -0.30893, 0.083206, 17.505759, -0.078919, -0.187955, 0.051719, 27.747402, -0.165335, -0.208553, 0.004067, 26.210627, -0.138398, -0.360514, 0.072199, 18.034833, -0.077047, -0.260556, 0.084319, 28.452802, -0.163408, -0.14097, -0.063076, 22.353095, -0.103046, -0.226654, 0.002992, 18.220508, -0.074034, -0.309812, 0.108636 ]).reshape((10, 4)) np.testing.assert_allclose(params, results.params, rtol=1e-03) bse = np.array([ 2.080166, 0.021462, 0.102954, 0.049627, 2.536355, 0.022111, 0.123857, 0.051917, 1.967813, 0.019716, 0.102562, 0.054918, 2.463219, 0.021745, 0.110297, 0.044189, 1.556056, 0.019513, 0.12764, 0.040315, 1.664108, 0.020114, 0.131208, 0.041613, 2.5835, 0.021481, 0.113158, 0.047243, 1.709483, 0.019752, 0.116944, 0.043636, 1.958233, 0.020947, 0.09974, 0.049821, 2.276849, 0.020122, 0.107867, 0.047842 ]).reshape((10, 4)) np.testing.assert_allclose(bse, results.bse, rtol=1e-03) tvalues = np.array([ 10.947193, -4.777659, -2.089223, -0.283103, 7.532584, -4.259179, -1.877395, 1.385161, 10.033179, -4.080362, -3.012133, 1.515096, 7.106862, -3.629311, -1.704079, 1.17042, 17.831878, -8.473156, -1.633924, 0.100891, 15.750552, -6.880725, -2.74765, 1.734978, 6.980774, -3.586757, -2.302575, 1.784818, 16.644095, -8.273001, -1.205451, -1.445501, 11.414933, -4.919384, -2.272458, 0.060064, 8.00251, -3.679274, -2.872176, 2.270738 ]).reshape((10, 4)) np.testing.assert_allclose(tvalues, results.tvalues, rtol=1e-03) localR2 = np.array([[0.53068693], [0.59582647], [0.59700925], [0.45769954], [0.54634509], [0.5494828], [0.55159604], [0.55634237], [0.53903842], [0.55884954]]) np.testing.assert_allclose(localR2, results.localR2, rtol=1e-05) predictions = np.array([[10.51695514], [9.93321992], [8.92473026], [5.47350219], [8.61756585], [12.8141851], [5.55619405], [12.63004172], [8.70638418], [8.17582599]]) np.testing.assert_allclose(predictions, results.predictions, rtol=1e-05)
p = X_train.shape[1] coords_train = X_train[:, 0:2] X_train = X_train[:, 2:p + 2] coords_test = X_test[:, 0:2] X_test = X_test[:, 2:p + 2] model_oos = GWR(coords_train, y_train, X_train, 12, family=Gaussian(), fixed=False, kernel='gaussian') results_oos = model_oos.predict(coords_test, X_test) var_os = np.var(y_test - results_oos.predictions) model_is = GWR(coords_train, y_train, X_train, 12, family=Gaussian(), fixed=False, kernel='gaussian') results_is = model_is.predict(coords_train, X_train) var_is = np.var(y_train - results_is.predictions) rmse_is = np.sqrt(np.mean((y_train - results_is.predictions)**2)) lik_is = np.sum(gaussian(y_train, results_is.predictions, var_is)) rmse_oos = np.sqrt(np.mean((y_test - results_oos.predictions)**2))