コード例 #1
0
ファイル: test_gwr.py プロジェクト: ljwolf/pysal
    def test_GS_NN(self):
        est_Int = self.GS_NN.by_col(' est_Intercept')
        se_Int = self.GS_NN.by_col(' se_Intercept')
        t_Int = self.GS_NN.by_col(' t_Intercept')
        est_elev = self.GS_NN.by_col(' est_Elev')
        se_elev = self.GS_NN.by_col(' se_Elev')
        t_elev = self.GS_NN.by_col(' t_Elev')
        est_slope = self.GS_NN.by_col(' est_Slope')
        se_slope = self.GS_NN.by_col(' se_Slope')
        t_slope = self.GS_NN.by_col(' t_Slope')
        est_sin = self.GS_NN.by_col(' est_SinAspct')
        se_sin = self.GS_NN.by_col(' se_SinAspct')
        t_sin = self.GS_NN.by_col(' t_SinAspct')
        est_cos = self.GS_NN.by_col(' est_CosAspct')
        se_cos = self.GS_NN.by_col(' se_CosAspct')
        t_cos = self.GS_NN.by_col(' t_CosAspct')
        est_south = self.GS_NN.by_col(' est_AbsSouth')
        se_south = self.GS_NN.by_col(' se_AbsSouth')
        t_south = self.GS_NN.by_col(' t_AbsSouth')
        est_strm = self.GS_NN.by_col(' est_DistStrm')
        se_strm = self.GS_NN.by_col(' se_DistStrm')
        t_strm = self.GS_NN.by_col(' t_DistStrm') 
        yhat = self.GS_NN.by_col(' yhat')
        pdev = self.GS_NN.by_col(' localpdev')
        
        model = GWR(self.coords, self.y, self.X, bw=64, family=Binomial(), 
                kernel='gaussian', fixed=False)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)
        
        self.assertAlmostEquals(np.floor(AICc), 276.0)
        self.assertAlmostEquals(np.floor(AIC), 273.0)
        self.assertAlmostEquals(np.floor(BIC), 331.0)
        np.testing.assert_allclose(est_Int, rslt.params[:,0], rtol=1e-00)
        np.testing.assert_allclose(se_Int, rslt.bse[:,0], rtol=1e-00)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:,0], rtol=1e-00)
        np.testing.assert_allclose(est_elev, rslt.params[:,1], rtol=1e-00)
        np.testing.assert_allclose(se_elev, rslt.bse[:,1], rtol=1e-00)
        np.testing.assert_allclose(t_elev, rslt.tvalues[:,1], rtol=1e-00)
        np.testing.assert_allclose(est_slope, rslt.params[:,2], rtol=1e-00)
        np.testing.assert_allclose(se_slope, rslt.bse[:,2], rtol=1e-00)
        np.testing.assert_allclose(t_slope, rslt.tvalues[:,2], rtol=1e-00)
        np.testing.assert_allclose(est_sin, rslt.params[:,3], rtol=1e01)
        np.testing.assert_allclose(se_sin, rslt.bse[:,3], rtol=1e01)
        np.testing.assert_allclose(t_sin, rslt.tvalues[:,3], rtol=1e01)
        np.testing.assert_allclose(est_cos, rslt.params[:,4], rtol=1e01)
        np.testing.assert_allclose(se_cos, rslt.bse[:,4], rtol=1e01)
        np.testing.assert_allclose(t_cos, rslt.tvalues[:,4], rtol=1e01)
        np.testing.assert_allclose(est_south, rslt.params[:,5], rtol=1e01)
        np.testing.assert_allclose(se_south, rslt.bse[:,5], rtol=1e01)
        np.testing.assert_allclose(t_south, rslt.tvalues[:,5], rtol=1e01)
        np.testing.assert_allclose(est_strm, rslt.params[:,6], rtol=1e02)
        np.testing.assert_allclose(se_strm, rslt.bse[:,6], rtol=1e01)
        np.testing.assert_allclose(t_strm, rslt.tvalues[:,6], rtol=1e02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-00)
コード例 #2
0
ファイル: test_gwr.py プロジェクト: ljwolf/pysal
    def test_BS_NN_Offset(self):
        est_Int = self.BS_NN_OFF.by_col(' est_Intercept')
        se_Int = self.BS_NN_OFF.by_col(' se_Intercept')
        t_Int = self.BS_NN_OFF.by_col(' t_Intercept')
        est_OCC = self.BS_NN_OFF.by_col(' est_OCC_TEC')
        se_OCC = self.BS_NN_OFF.by_col(' se_OCC_TEC')
        t_OCC = self.BS_NN_OFF.by_col(' t_OCC_TEC')
        est_OWN = self.BS_NN_OFF.by_col(' est_OWNH')
        se_OWN = self.BS_NN_OFF.by_col(' se_OWNH')
        t_OWN = self.BS_NN_OFF.by_col(' t_OWNH')
        est_POP = self.BS_NN_OFF.by_col(' est_POP65')
        se_POP = self.BS_NN_OFF.by_col(' se_POP65')
        t_POP = self.BS_NN_OFF.by_col(' t_POP65')
        est_UNEMP = self.BS_NN_OFF.by_col(' est_UNEMP')
        se_UNEMP = self.BS_NN_OFF.by_col(' se_UNEMP')
        t_UNEMP = self.BS_NN_OFF.by_col(' t_UNEMP')
        yhat = self.BS_NN_OFF.by_col(' yhat')
        pdev = np.array(self.BS_NN_OFF.by_col(' localpdev')).reshape((-1,1))

        model = GWR(self.coords, self.y, self.X, bw=100, offset=self.off, family=Poisson(), 
                kernel='bisquare', fixed=False)
        rslt = model.fit()
        
        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)
        
        self.assertAlmostEquals(np.floor(AICc), 367.0)
        self.assertAlmostEquals(np.floor(AIC), 361.0)
        self.assertAlmostEquals(np.floor(BIC), 451.0)
        np.testing.assert_allclose(est_Int, rslt.params[:,0], rtol=1e-02,
                atol=1e-02)
        np.testing.assert_allclose(se_Int, rslt.bse[:,0], rtol=1e-02, atol=1e-02)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:,0], rtol=1e-01,
                atol=1e-02)
        np.testing.assert_allclose(est_OCC, rslt.params[:,1], rtol=1e-03,
                atol=1e-02)
        np.testing.assert_allclose(se_OCC, rslt.bse[:,1], rtol=1e-02, atol=1e-02)
        np.testing.assert_allclose(t_OCC, rslt.tvalues[:,1], rtol=1e-01,
                atol=1e-02)
        np.testing.assert_allclose(est_OWN, rslt.params[:,2], rtol=1e-04,
                atol=1e-02)
        np.testing.assert_allclose(se_OWN, rslt.bse[:,2], rtol=1e-02, atol=1e-02)
        np.testing.assert_allclose(t_OWN, rslt.tvalues[:,2], rtol=1e-01,
                atol=1e-02)
        np.testing.assert_allclose(est_POP, rslt.params[:,3], rtol=1e-03,
                atol=1e-02)
        np.testing.assert_allclose(se_POP, rslt.bse[:,3], rtol=1e-02, atol=1e-02)
        np.testing.assert_allclose(t_POP, rslt.tvalues[:,3], rtol=1e-01,
                atol=1e-02)
        np.testing.assert_allclose(est_UNEMP, rslt.params[:,4], rtol=1e-04,
                atol=1e-02)
        np.testing.assert_allclose(se_UNEMP, rslt.bse[:,4], rtol=1e-02,
                atol=1e-02)
        np.testing.assert_allclose(t_UNEMP, rslt.tvalues[:,4], rtol=1e-01,
                atol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-03, atol=1e-02)
        np.testing.assert_allclose(pdev, rslt.pDev, rtol=1e-04, atol=1e-02)
コード例 #3
0
ファイル: test_gwr.py プロジェクト: ljwolf/pysal
    def test_BS_F(self):
        est_Int = self.BS_F.by_col(' est_Intercept')
        se_Int = self.BS_F.by_col(' se_Intercept')
        t_Int = self.BS_F.by_col(' t_Intercept')
        est_elev = self.BS_F.by_col(' est_Elev')
        se_elev = self.BS_F.by_col(' se_Elev')
        t_elev = self.BS_F.by_col(' t_Elev')
        est_slope = self.BS_F.by_col(' est_Slope')
        se_slope = self.BS_F.by_col(' se_Slope')
        t_slope = self.BS_F.by_col(' t_Slope')
        est_sin = self.BS_F.by_col(' est_SinAspct')
        se_sin = self.BS_F.by_col(' se_SinAspct')
        t_sin = self.BS_F.by_col(' t_SinAspct')
        est_cos = self.BS_F.by_col(' est_CosAspct')
        se_cos = self.BS_F.by_col(' se_CosAspct')
        t_cos = self.BS_F.by_col(' t_CosAspct')
        est_south = self.BS_F.by_col(' est_AbsSouth')
        se_south = self.BS_F.by_col(' se_AbsSouth')
        t_south = self.BS_F.by_col(' t_AbsSouth')
        est_strm = self.BS_F.by_col(' est_DistStrm')
        se_strm = self.BS_F.by_col(' se_DistStrm')
        t_strm = self.BS_F.by_col(' t_DistStrm') 
        yhat = self.BS_F.by_col(' yhat')
        pdev = np.array(self.BS_F.by_col(' localpdev')).reshape((-1,1))

        model = GWR(self.coords, self.y, self.X, bw=19642.170, family=Binomial(), 
                kernel='bisquare', fixed=True)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)
        
        self.assertAlmostEquals(np.floor(AICc), 275.0)
        self.assertAlmostEquals(np.floor(AIC), 271.0)
        self.assertAlmostEquals(np.floor(BIC), 349.0)
        np.testing.assert_allclose(est_Int, rslt.params[:,0], rtol=1e-00)
        np.testing.assert_allclose(se_Int, rslt.bse[:,0], rtol=1e-00)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:,0], rtol=1e-00)
        np.testing.assert_allclose(est_elev, rslt.params[:,1], rtol=1e-00)
        np.testing.assert_allclose(se_elev, rslt.bse[:,1], rtol=1e-00)
        np.testing.assert_allclose(t_elev, rslt.tvalues[:,1], rtol=1e-00)
        np.testing.assert_allclose(est_slope, rslt.params[:,2], rtol=1e-00)
        np.testing.assert_allclose(se_slope, rslt.bse[:,2], rtol=1e-00)
        np.testing.assert_allclose(t_slope, rslt.tvalues[:,2], rtol=1e-00)
        np.testing.assert_allclose(est_sin, rslt.params[:,3], rtol=1e01)
        np.testing.assert_allclose(se_sin, rslt.bse[:,3], rtol=1e01)
        np.testing.assert_allclose(t_sin, rslt.tvalues[:,3], rtol=1e01)
        np.testing.assert_allclose(est_cos, rslt.params[:,4], rtol=1e01)
        np.testing.assert_allclose(se_cos, rslt.bse[:,4], rtol=1e01)
        np.testing.assert_allclose(t_cos, rslt.tvalues[:,4], rtol=1e01)
        np.testing.assert_allclose(est_south, rslt.params[:,5], rtol=1e01)
        np.testing.assert_allclose(se_south, rslt.bse[:,5], rtol=1e01)
        np.testing.assert_allclose(t_south, rslt.tvalues[:,5], rtol=1e01)
        np.testing.assert_allclose(est_strm, rslt.params[:,6], rtol=1e02)
        np.testing.assert_allclose(se_strm, rslt.bse[:,6], rtol=1e01)
        np.testing.assert_allclose(t_strm, rslt.tvalues[:,6], rtol=1e02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-01)
コード例 #4
0
ファイル: test_gwr.py プロジェクト: youngpong/pysal
    def test_GS_NN(self):
        est_Int = self.GS_NN.by_col(' est_Intercept')
        se_Int = self.GS_NN.by_col(' se_Intercept')
        t_Int = self.GS_NN.by_col(' t_Intercept')
        est_rural = self.GS_NN.by_col(' est_PctRural')
        se_rural = self.GS_NN.by_col(' se_PctRural')
        t_rural = self.GS_NN.by_col(' t_PctRural')
        est_pov = self.GS_NN.by_col(' est_PctPov')
        se_pov = self.GS_NN.by_col(' se_PctPov')
        t_pov = self.GS_NN.by_col(' t_PctPov')
        est_black = self.GS_NN.by_col(' est_PctBlack')
        se_black = self.GS_NN.by_col(' se_PctBlack')
        t_black = self.GS_NN.by_col(' t_PctBlack')
        yhat = self.GS_NN.by_col(' yhat')
        res = np.array(self.GS_NN.by_col(' residual'))
        std_res = np.array(self.GS_NN.by_col(' std_residual')).reshape((-1, 1))
        localR2 = np.array(self.GS_NN.by_col(' localR2')).reshape((-1, 1))
        inf = np.array(self.GS_NN.by_col(' influence')).reshape((-1, 1))
        cooksD = np.array(self.GS_NN.by_col(' CooksD')).reshape((-1, 1))

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=49.000,
                    kernel='gaussian',
                    fixed=False)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)
        CV = get_CV(rslt)

        self.assertAlmostEquals(np.floor(AICc), 896)
        self.assertAlmostEquals(np.floor(AIC), 894.0)
        self.assertAlmostEquals(np.floor(BIC), 922.0)
        self.assertAlmostEquals(np.around(CV, 2), 17.91)
        np.testing.assert_allclose(est_Int, rslt.params[:, 0], rtol=1e-04)
        np.testing.assert_allclose(se_Int, rslt.bse[:, 0], rtol=1e-04)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:, 0], rtol=1e-04)
        np.testing.assert_allclose(est_rural, rslt.params[:, 1], rtol=1e-04)
        np.testing.assert_allclose(se_rural, rslt.bse[:, 1], rtol=1e-04)
        np.testing.assert_allclose(t_rural, rslt.tvalues[:, 1], rtol=1e-04)
        np.testing.assert_allclose(est_pov, rslt.params[:, 2], rtol=1e-04)
        np.testing.assert_allclose(se_pov, rslt.bse[:, 2], rtol=1e-04)
        np.testing.assert_allclose(t_pov, rslt.tvalues[:, 2], rtol=1e-04)
        np.testing.assert_allclose(est_black, rslt.params[:, 3], rtol=1e-02)
        np.testing.assert_allclose(se_black, rslt.bse[:, 3], rtol=1e-02)
        np.testing.assert_allclose(t_black, rslt.tvalues[:, 3], rtol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-05)
        np.testing.assert_allclose(res, rslt.resid_response, rtol=1e-04)
        np.testing.assert_allclose(std_res, rslt.std_res, rtol=1e-04)
        np.testing.assert_allclose(localR2, rslt.localR2, rtol=1e-05)
        np.testing.assert_allclose(inf, rslt.influ, rtol=1e-04)
        np.testing.assert_allclose(cooksD, rslt.cooksD, rtol=1e-00)
コード例 #5
0
ファイル: test_gwr.py プロジェクト: youngpong/pysal
    def test_GS_NN(self):
        est_Int = self.GS_NN.by_col(' est_Intercept')
        se_Int = self.GS_NN.by_col(' se_Intercept')
        t_Int = self.GS_NN.by_col(' t_Intercept')
        est_OCC = self.GS_NN.by_col(' est_OCC_TEC')
        se_OCC = self.GS_NN.by_col(' se_OCC_TEC')
        t_OCC = self.GS_NN.by_col(' t_OCC_TEC')
        est_OWN = self.GS_NN.by_col(' est_OWNH')
        se_OWN = self.GS_NN.by_col(' se_OWNH')
        t_OWN = self.GS_NN.by_col(' t_OWNH')
        est_POP = self.GS_NN.by_col(' est_POP65')
        se_POP = self.GS_NN.by_col(' se_POP65')
        t_POP = self.GS_NN.by_col(' t_POP65')
        est_UNEMP = self.GS_NN.by_col(' est_UNEMP')
        se_UNEMP = self.GS_NN.by_col(' se_UNEMP')
        t_UNEMP = self.GS_NN.by_col(' t_UNEMP')
        yhat = self.GS_NN.by_col(' yhat')
        pdev = np.array(self.GS_NN.by_col(' localpdev')).reshape((-1, 1))

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=50,
                    family=Poisson(),
                    kernel='gaussian',
                    fixed=False)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)

        self.assertAlmostEquals(np.floor(AICc), 21070.0)
        self.assertAlmostEquals(np.floor(AIC), 21069.0)
        self.assertAlmostEquals(np.floor(BIC), 21111.0)
        np.testing.assert_allclose(est_Int, rslt.params[:, 0], rtol=1e-04)
        np.testing.assert_allclose(se_Int, rslt.bse[:, 0], rtol=1e-02)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:, 0], rtol=1e-02)
        np.testing.assert_allclose(est_OCC, rslt.params[:, 1], rtol=1e-03)
        np.testing.assert_allclose(se_OCC, rslt.bse[:, 1], rtol=1e-02)
        np.testing.assert_allclose(t_OCC, rslt.tvalues[:, 1], rtol=1e-02)
        np.testing.assert_allclose(est_OWN, rslt.params[:, 2], rtol=1e-04)
        np.testing.assert_allclose(se_OWN, rslt.bse[:, 2], rtol=1e-02)
        np.testing.assert_allclose(t_OWN, rslt.tvalues[:, 2], rtol=1e-02)
        np.testing.assert_allclose(est_POP, rslt.params[:, 3], rtol=1e-02)
        np.testing.assert_allclose(se_POP, rslt.bse[:, 3], rtol=1e-02)
        np.testing.assert_allclose(t_POP, rslt.tvalues[:, 3], rtol=1e-02)
        np.testing.assert_allclose(est_UNEMP, rslt.params[:, 4], rtol=1e-02)
        np.testing.assert_allclose(se_UNEMP, rslt.bse[:, 4], rtol=1e-02)
        np.testing.assert_allclose(t_UNEMP, rslt.tvalues[:, 4], rtol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-04)
        np.testing.assert_allclose(pdev, rslt.pDev, rtol=1e-05)
コード例 #6
0
ファイル: test_gwr.py プロジェクト: youngpong/pysal
    def test_BS_F(self):
        est_Int = self.BS_F.by_col(' est_Intercept')
        se_Int = self.BS_F.by_col(' se_Intercept')
        t_Int = self.BS_F.by_col(' t_Intercept')
        est_OCC = self.BS_F.by_col(' est_OCC_TEC')
        se_OCC = self.BS_F.by_col(' se_OCC_TEC')
        t_OCC = self.BS_F.by_col(' t_OCC_TEC')
        est_OWN = self.BS_F.by_col(' est_OWNH')
        se_OWN = self.BS_F.by_col(' se_OWNH')
        t_OWN = self.BS_F.by_col(' t_OWNH')
        est_POP = self.BS_F.by_col(' est_POP65')
        se_POP = self.BS_F.by_col(' se_POP65')
        t_POP = self.BS_F.by_col(' t_POP65')
        est_UNEMP = self.BS_F.by_col(' est_UNEMP')
        se_UNEMP = self.BS_F.by_col(' se_UNEMP')
        t_UNEMP = self.BS_F.by_col(' t_UNEMP')
        yhat = self.BS_F.by_col(' yhat')
        pdev = np.array(self.BS_F.by_col(' localpdev')).reshape((-1, 1))

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=26029.625,
                    family=Poisson(),
                    kernel='bisquare',
                    fixed=True)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)

        self.assertAlmostEquals(np.floor(AICc), 13294.0)
        self.assertAlmostEquals(np.floor(AIC), 13247.0)
        self.assertAlmostEquals(np.floor(BIC), 13485.0)
        np.testing.assert_allclose(est_Int, rslt.params[:, 0], rtol=1e-05)
        np.testing.assert_allclose(se_Int, rslt.bse[:, 0], rtol=1e-03)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:, 0], rtol=1e-03)
        np.testing.assert_allclose(est_OCC, rslt.params[:, 1], rtol=1e-04)
        np.testing.assert_allclose(se_OCC, rslt.bse[:, 1], rtol=1e-02)
        np.testing.assert_allclose(t_OCC, rslt.tvalues[:, 1], rtol=1e-02)
        np.testing.assert_allclose(est_OWN, rslt.params[:, 2], rtol=1e-04)
        np.testing.assert_allclose(se_OWN, rslt.bse[:, 2], rtol=1e-03)
        np.testing.assert_allclose(t_OWN, rslt.tvalues[:, 2], rtol=1e-03)
        np.testing.assert_allclose(est_POP, rslt.params[:, 3], rtol=1e-04)
        np.testing.assert_allclose(se_POP, rslt.bse[:, 3], rtol=1e-02)
        np.testing.assert_allclose(t_POP, rslt.tvalues[:, 3], rtol=1e-02)
        np.testing.assert_allclose(est_UNEMP, rslt.params[:, 4], rtol=1e-04)
        np.testing.assert_allclose(se_UNEMP, rslt.bse[:, 4], rtol=1e-02)
        np.testing.assert_allclose(t_UNEMP, rslt.tvalues[:, 4], rtol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-05)
        np.testing.assert_allclose(pdev, rslt.pDev, rtol=1e-05)
コード例 #7
0
ファイル: test_gwr.py プロジェクト: ljwolf/pysal
    def test_GS_NN(self):
        est_Int = self.GS_NN.by_col(' est_Intercept')
        se_Int = self.GS_NN.by_col(' se_Intercept')
        t_Int = self.GS_NN.by_col(' t_Intercept')
        est_rural = self.GS_NN.by_col(' est_PctRural')
        se_rural = self.GS_NN.by_col(' se_PctRural')
        t_rural = self.GS_NN.by_col(' t_PctRural')
        est_pov = self.GS_NN.by_col(' est_PctPov')
        se_pov = self.GS_NN.by_col(' se_PctPov')
        t_pov = self.GS_NN.by_col(' t_PctPov')
        est_black = self.GS_NN.by_col(' est_PctBlack')
        se_black = self.GS_NN.by_col(' se_PctBlack')
        t_black = self.GS_NN.by_col(' t_PctBlack')
        yhat = self.GS_NN.by_col(' yhat')
        res = np.array(self.GS_NN.by_col(' residual'))
        std_res = np.array(self.GS_NN.by_col(' std_residual')).reshape((-1,1))
        localR2 = np.array(self.GS_NN.by_col(' localR2')).reshape((-1,1))
        inf = np.array(self.GS_NN.by_col(' influence')).reshape((-1,1))
        cooksD = np.array(self.GS_NN.by_col(' CooksD')).reshape((-1,1))

        model = GWR(self.coords, self.y, self.X, bw=49.000,
                kernel='gaussian', fixed=False)
        rslt = model.fit()
        
        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)
        CV = get_CV(rslt)
        
        self.assertAlmostEquals(np.floor(AICc),  896)
        self.assertAlmostEquals(np.floor(AIC), 894.0)
        self.assertAlmostEquals(np.floor(BIC), 922.0)
        self.assertAlmostEquals(np.around(CV, 2), 17.91)
        np.testing.assert_allclose(est_Int, rslt.params[:,0], rtol=1e-04)
        np.testing.assert_allclose(se_Int, rslt.bse[:,0], rtol=1e-04)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:,0], rtol=1e-04)
        np.testing.assert_allclose(est_rural, rslt.params[:,1], rtol=1e-04)
        np.testing.assert_allclose(se_rural, rslt.bse[:,1], rtol=1e-04)
        np.testing.assert_allclose(t_rural, rslt.tvalues[:,1], rtol=1e-04)
        np.testing.assert_allclose(est_pov, rslt.params[:,2], rtol=1e-04)
        np.testing.assert_allclose(se_pov, rslt.bse[:,2], rtol=1e-04)
        np.testing.assert_allclose(t_pov, rslt.tvalues[:,2], rtol=1e-04)
        np.testing.assert_allclose(est_black, rslt.params[:,3], rtol=1e-02)
        np.testing.assert_allclose(se_black, rslt.bse[:,3], rtol=1e-02)
        np.testing.assert_allclose(t_black, rslt.tvalues[:,3], rtol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-05)
        np.testing.assert_allclose(res, rslt.resid_response, rtol=1e-04)
        np.testing.assert_allclose(std_res, rslt.std_res, rtol=1e-04)
        np.testing.assert_allclose(localR2, rslt.localR2, rtol=1e-05)
        np.testing.assert_allclose(inf, rslt.influ, rtol=1e-04)
        np.testing.assert_allclose(cooksD, rslt.cooksD, rtol=1e-00)
コード例 #8
0
ファイル: test_gwr.py プロジェクト: ljwolf/pysal
 def test_GS_NN(self):
     est_Int = self.GS_NN.by_col(' est_Intercept')
     se_Int = self.GS_NN.by_col(' se_Intercept')
     t_Int = self.GS_NN.by_col(' t_Intercept')
     est_OCC = self.GS_NN.by_col(' est_OCC_TEC')
     se_OCC = self.GS_NN.by_col(' se_OCC_TEC')
     t_OCC = self.GS_NN.by_col(' t_OCC_TEC')
     est_OWN = self.GS_NN.by_col(' est_OWNH')
     se_OWN = self.GS_NN.by_col(' se_OWNH')
     t_OWN = self.GS_NN.by_col(' t_OWNH')
     est_POP = self.GS_NN.by_col(' est_POP65')
     se_POP = self.GS_NN.by_col(' se_POP65')
     t_POP = self.GS_NN.by_col(' t_POP65')
     est_UNEMP = self.GS_NN.by_col(' est_UNEMP')
     se_UNEMP = self.GS_NN.by_col(' se_UNEMP')
     t_UNEMP = self.GS_NN.by_col(' t_UNEMP')
     yhat = self.GS_NN.by_col(' yhat')
     pdev = np.array(self.GS_NN.by_col(' localpdev')).reshape((-1,1))
     
     model = GWR(self.coords, self.y, self.X, bw=50, family=Poisson(), 
             kernel='gaussian', fixed=False)
     rslt = model.fit()
     
     AICc = get_AICc(rslt)
     AIC = get_AIC(rslt)
     BIC = get_BIC(rslt)
     
     self.assertAlmostEquals(np.floor(AICc), 21070.0)
     self.assertAlmostEquals(np.floor(AIC), 21069.0)
     self.assertAlmostEquals(np.floor(BIC), 21111.0)
     np.testing.assert_allclose(est_Int, rslt.params[:,0], rtol=1e-04)
     np.testing.assert_allclose(se_Int, rslt.bse[:,0], rtol=1e-02)
     np.testing.assert_allclose(t_Int, rslt.tvalues[:,0], rtol=1e-02)
     np.testing.assert_allclose(est_OCC, rslt.params[:,1], rtol=1e-03)
     np.testing.assert_allclose(se_OCC, rslt.bse[:,1], rtol=1e-02)
     np.testing.assert_allclose(t_OCC, rslt.tvalues[:,1], rtol=1e-02)
     np.testing.assert_allclose(est_OWN, rslt.params[:,2], rtol=1e-04)
     np.testing.assert_allclose(se_OWN, rslt.bse[:,2], rtol=1e-02)
     np.testing.assert_allclose(t_OWN, rslt.tvalues[:,2], rtol=1e-02)
     np.testing.assert_allclose(est_POP, rslt.params[:,3], rtol=1e-02)
     np.testing.assert_allclose(se_POP, rslt.bse[:,3], rtol=1e-02)
     np.testing.assert_allclose(t_POP, rslt.tvalues[:,3], rtol=1e-02)
     np.testing.assert_allclose(est_UNEMP, rslt.params[:,4], rtol=1e-02)
     np.testing.assert_allclose(se_UNEMP, rslt.bse[:,4], rtol=1e-02)
     np.testing.assert_allclose(t_UNEMP, rslt.tvalues[:,4], rtol=1e-02)
     np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-04)
     np.testing.assert_allclose(pdev, rslt.pDev, rtol=1e-05)
コード例 #9
0
ファイル: test_gwr.py プロジェクト: youngpong/pysal
    def test_GS_NN(self):
        est_Int = self.GS_NN.by_col(' est_Intercept')
        se_Int = self.GS_NN.by_col(' se_Intercept')
        t_Int = self.GS_NN.by_col(' t_Intercept')
        est_elev = self.GS_NN.by_col(' est_Elev')
        se_elev = self.GS_NN.by_col(' se_Elev')
        t_elev = self.GS_NN.by_col(' t_Elev')
        est_slope = self.GS_NN.by_col(' est_Slope')
        se_slope = self.GS_NN.by_col(' se_Slope')
        t_slope = self.GS_NN.by_col(' t_Slope')
        est_sin = self.GS_NN.by_col(' est_SinAspct')
        se_sin = self.GS_NN.by_col(' se_SinAspct')
        t_sin = self.GS_NN.by_col(' t_SinAspct')
        est_cos = self.GS_NN.by_col(' est_CosAspct')
        se_cos = self.GS_NN.by_col(' se_CosAspct')
        t_cos = self.GS_NN.by_col(' t_CosAspct')
        est_south = self.GS_NN.by_col(' est_AbsSouth')
        se_south = self.GS_NN.by_col(' se_AbsSouth')
        t_south = self.GS_NN.by_col(' t_AbsSouth')
        est_strm = self.GS_NN.by_col(' est_DistStrm')
        se_strm = self.GS_NN.by_col(' se_DistStrm')
        t_strm = self.GS_NN.by_col(' t_DistStrm')
        yhat = self.GS_NN.by_col(' yhat')
        pdev = self.GS_NN.by_col(' localpdev')

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=64,
                    family=Binomial(),
                    kernel='gaussian',
                    fixed=False)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)

        self.assertAlmostEquals(np.floor(AICc), 276.0)
        self.assertAlmostEquals(np.floor(AIC), 273.0)
        self.assertAlmostEquals(np.floor(BIC), 331.0)
        np.testing.assert_allclose(est_Int, rslt.params[:, 0], rtol=1e-00)
        np.testing.assert_allclose(se_Int, rslt.bse[:, 0], rtol=1e-00)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:, 0], rtol=1e-00)
        np.testing.assert_allclose(est_elev, rslt.params[:, 1], rtol=1e-00)
        np.testing.assert_allclose(se_elev, rslt.bse[:, 1], rtol=1e-00)
        np.testing.assert_allclose(t_elev, rslt.tvalues[:, 1], rtol=1e-00)
        np.testing.assert_allclose(est_slope, rslt.params[:, 2], rtol=1e-00)
        np.testing.assert_allclose(se_slope, rslt.bse[:, 2], rtol=1e-00)
        np.testing.assert_allclose(t_slope, rslt.tvalues[:, 2], rtol=1e-00)
        np.testing.assert_allclose(est_sin, rslt.params[:, 3], rtol=1e01)
        np.testing.assert_allclose(se_sin, rslt.bse[:, 3], rtol=1e01)
        np.testing.assert_allclose(t_sin, rslt.tvalues[:, 3], rtol=1e01)
        np.testing.assert_allclose(est_cos, rslt.params[:, 4], rtol=1e01)
        np.testing.assert_allclose(se_cos, rslt.bse[:, 4], rtol=1e01)
        np.testing.assert_allclose(t_cos, rslt.tvalues[:, 4], rtol=1e01)
        np.testing.assert_allclose(est_south, rslt.params[:, 5], rtol=1e01)
        np.testing.assert_allclose(se_south, rslt.bse[:, 5], rtol=1e01)
        np.testing.assert_allclose(t_south, rslt.tvalues[:, 5], rtol=1e01)
        np.testing.assert_allclose(est_strm, rslt.params[:, 6], rtol=1e02)
        np.testing.assert_allclose(se_strm, rslt.bse[:, 6], rtol=1e01)
        np.testing.assert_allclose(t_strm, rslt.tvalues[:, 6], rtol=1e02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-00)
コード例 #10
0
ファイル: test_gwr.py プロジェクト: youngpong/pysal
    def test_BS_F(self):
        est_Int = self.BS_F.by_col(' est_Intercept')
        se_Int = self.BS_F.by_col(' se_Intercept')
        t_Int = self.BS_F.by_col(' t_Intercept')
        est_elev = self.BS_F.by_col(' est_Elev')
        se_elev = self.BS_F.by_col(' se_Elev')
        t_elev = self.BS_F.by_col(' t_Elev')
        est_slope = self.BS_F.by_col(' est_Slope')
        se_slope = self.BS_F.by_col(' se_Slope')
        t_slope = self.BS_F.by_col(' t_Slope')
        est_sin = self.BS_F.by_col(' est_SinAspct')
        se_sin = self.BS_F.by_col(' se_SinAspct')
        t_sin = self.BS_F.by_col(' t_SinAspct')
        est_cos = self.BS_F.by_col(' est_CosAspct')
        se_cos = self.BS_F.by_col(' se_CosAspct')
        t_cos = self.BS_F.by_col(' t_CosAspct')
        est_south = self.BS_F.by_col(' est_AbsSouth')
        se_south = self.BS_F.by_col(' se_AbsSouth')
        t_south = self.BS_F.by_col(' t_AbsSouth')
        est_strm = self.BS_F.by_col(' est_DistStrm')
        se_strm = self.BS_F.by_col(' se_DistStrm')
        t_strm = self.BS_F.by_col(' t_DistStrm')
        yhat = self.BS_F.by_col(' yhat')
        pdev = np.array(self.BS_F.by_col(' localpdev')).reshape((-1, 1))

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=19642.170,
                    family=Binomial(),
                    kernel='bisquare',
                    fixed=True)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)

        self.assertAlmostEquals(np.floor(AICc), 275.0)
        self.assertAlmostEquals(np.floor(AIC), 271.0)
        self.assertAlmostEquals(np.floor(BIC), 349.0)
        np.testing.assert_allclose(est_Int, rslt.params[:, 0], rtol=1e-00)
        np.testing.assert_allclose(se_Int, rslt.bse[:, 0], rtol=1e-00)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:, 0], rtol=1e-00)
        np.testing.assert_allclose(est_elev, rslt.params[:, 1], rtol=1e-00)
        np.testing.assert_allclose(se_elev, rslt.bse[:, 1], rtol=1e-00)
        np.testing.assert_allclose(t_elev, rslt.tvalues[:, 1], rtol=1e-00)
        np.testing.assert_allclose(est_slope, rslt.params[:, 2], rtol=1e-00)
        np.testing.assert_allclose(se_slope, rslt.bse[:, 2], rtol=1e-00)
        np.testing.assert_allclose(t_slope, rslt.tvalues[:, 2], rtol=1e-00)
        np.testing.assert_allclose(est_sin, rslt.params[:, 3], rtol=1e01)
        np.testing.assert_allclose(se_sin, rslt.bse[:, 3], rtol=1e01)
        np.testing.assert_allclose(t_sin, rslt.tvalues[:, 3], rtol=1e01)
        np.testing.assert_allclose(est_cos, rslt.params[:, 4], rtol=1e01)
        np.testing.assert_allclose(se_cos, rslt.bse[:, 4], rtol=1e01)
        np.testing.assert_allclose(t_cos, rslt.tvalues[:, 4], rtol=1e01)
        np.testing.assert_allclose(est_south, rslt.params[:, 5], rtol=1e01)
        np.testing.assert_allclose(se_south, rslt.bse[:, 5], rtol=1e01)
        np.testing.assert_allclose(t_south, rslt.tvalues[:, 5], rtol=1e01)
        np.testing.assert_allclose(est_strm, rslt.params[:, 6], rtol=1e02)
        np.testing.assert_allclose(se_strm, rslt.bse[:, 6], rtol=1e01)
        np.testing.assert_allclose(t_strm, rslt.tvalues[:, 6], rtol=1e02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-01)
コード例 #11
0
ファイル: test_gwr.py プロジェクト: youngpong/pysal
    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)
コード例 #12
0
ファイル: test_gwr.py プロジェクト: ljwolf/pysal
    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)
X_train, X_test, _, y_train, y_test, _, _, _, _, _ = data_pipeline(
    feature_engineering=True, feature_type='count')
print(X_train.shape[0])
print(X_train.shape[1])
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)
コード例 #14
0
    def runGWR(self):
        w = QtWidgets.QDialog()
        nd = Ui_runningDialog()
        nd.setupUi(w)
        w.show()
        if not self.preCheckEmptyFields():
            err_msg = QtWidgets.QMessageBox.critical(
                None, "Error", "Please fix inputs in red!")

            return

        if not self.loadDataModel():
            err_msg = QtWidgets.QMessageBox.critical(
                None, "Error",
                "Something wrong when loading variables to model. Please double check you data. No Missing values allowed."
            )
            return

        self.begin_t = datetime.now()

        if self.isGWR:
            self.GLMResult = GLM(self.y, self.X).fit()

            print("running GWR")

            self.bw = Sel_BW(self.coords,
                             self.y,
                             self.X,
                             kernel=self.kernel,
                             fixed=self.fixed,
                             constant=False)
            self.bw = self.bw.search(search=self.search,
                                     criterion=self.criterion)

            self.results = GWR(self.coords,
                               self.y,
                               self.X,
                               self.bw,
                               fixed=self.fixed,
                               kernel=self.kernel,
                               constant=False).fit()
            self.saveBetasToCSVGWR(self.results)
            self.end_t = datetime.now()
            summaryGWR(self)
            print("Done")
            msg = QtWidgets.QMessageBox.information(None, "Success",
                                                    "Running complete!")
            """
            try:
                '''
                __init__(self, coords, y, X_loc, X_glob=None, family=Gaussian(),
                offset=None, kernel='bisquare', fixed=False, multi=False, constant=True)
                '''
                bw = Sel_BW(self.coords, self.y, self.X, kernel=self.kernel, fixed=self.fixed, constant = False)
            
                '''
                search(self, search='golden_section', criterion='AICc', bw_min=0.0,
                bw_max=0.0, interval=0.0, tol=1.0e-6, max_iter=200, init_multi=True,
                tol_multi=1.0e-5, rss_score=False, max_iter_multi=200)
                    '''
                bw = bw.search(search=self.search, criterion=self.criterion)
            
                self.results = GWR(self.coords, self.y, self.X, bw, fixed=self.fixed, kernel=self.kernel, constant = False).fit()
                self.saveBetasToCSVGWR(self.results)
                self.end_t = datetime.now()
                summaryGWR(self)
            except:
                error_dialog = QtWidgets.QErrorMessage()
                error_dialog.showMessage('Something went wrong when running GWR Model. Please double check your settings and data.')
                error_dialog.exec_()
            """

        if self.isMGWR:
            if 1 == 1:
                print("running MGWR")
                self.bw = Sel_BW(self.coords,
                                 self.y,
                                 self.X,
                                 fixed=self.fixed,
                                 kernel=self.kernel,
                                 multi=True,
                                 constant=False)
                self.bws = self.bw.search(search='golden_section',
                                          criterion=self.criterion,
                                          tol_multi=self.tol_multi,
                                          init_multi=self.init_multi,
                                          rss_score=self.isRss_score)
                XB = self.bw.XB
                err = self.bw.err
                self.results = MGWR(self.coords,
                                    self.y,
                                    self.X,
                                    self.bws,
                                    XB,
                                    err,
                                    kernel=self.kernel,
                                    fixed=self.fixed,
                                    constant=False).fit()
                self.saveBetasToCSVMGWR(self.results)
                self.saveProcessToCSVMGWR()
                self.end_t = datetime.now()
                summaryMGWR(self)
                print("Done")
                msg = QtWidgets.QMessageBox.information(
                    None, "Success", "Running complete!")