示例#1
0
 def __init__(self,
              coords,
              y,
              X,
              bw,
              family=Gaussian(),
              offset=None,
              sigma2_v1=False,
              kernel='bisquare',
              fixed=False,
              constant=True):
     """
     Initialize class
     """
     GLM.__init__(self, y, X, family, constant=constant)
     self.constant = constant
     self.sigma2_v1 = sigma2_v1
     self.coords = coords
     self.bw = bw
     self.kernel = kernel
     self.fixed = fixed
     if offset is None:
         self.offset = np.ones((self.n, 1))
     else:
         self.offset = offset * 1.0
     self.fit_params = {}
     self.W = self._build_W(fixed, kernel, coords, bw)
     self.points = None
     self.exog_scale = None
     self.exog_resid = None
     self.P = None
示例#2
0
 def __init__(self,
              coords,
              y,
              X,
              bws,
              XB,
              err,
              family=Gaussian(),
              offset=None,
              sigma2_v1=False,
              kernel='bisquare',
              fixed=False,
              constant=True):
     """
     Initialize class
     """
     self.coords = coords
     self.y = y
     self.X = X
     self.XB = XB
     self.err = err
     self.bws = bws
     self.family = family
     self.offset = offset
     self.sigma2_v1 = sigma2_v1
     self.kernel = kernel
     self.fixed = fixed
     self.constant = constant
     if constant:
         self.X = USER.check_constant(self.X)
 def __init__(self,
              coords,
              y,
              x_loc,
              x_glob=None,
              family=Gaussian(),
              offset=None,
              kernel='bisquare',
              fixed=False,
              fb=False,
              constant=True):
     self.coords = coords
     self.y = y
     self.x_loc = x_loc
     if x_glob is not None:
         self.x_glob = x_glob
     else:
         self.x_glob = []
     self.family = family
     self.fixed = fixed
     self.kernel = kernel
     if offset is None:
         self.offset = np.ones((len(y), 1))
     else:
         self.offset = offset * 1.0
     self.fb = fb
     self.constant = constant
示例#4
0
    def test_Prediction(self):
        coords = np.array(self.coords)
        index = np.arange(len(self.y))
        #train = index[0:-10]
        test = index[-10:]

        #y_train = self.y[train]
        #X_train = self.X[train]
        #coords_train = list(coords[train])

        #y_test = self.y[test]
        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)