コード例 #1
0
    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)
コード例 #2
0
    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.assertAlmostEqual(np.floor(AICc), 367.0)
        self.assertAlmostEqual(np.floor(AIC), 361.0)
        self.assertAlmostEqual(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)