Esempio n. 1
0
 def test_proflogit_patsy_demo_data(self):
     X_train, y_train = load_data("../data/patsy_demo_train.dat", "y")
     X_test, y_test = load_data("../data/patsy_demo_test.dat", 0)
     pfl = ProfLogit(rga_kws={"niter": 5, "random_state": 42}, )
     pfl.fit(X_train, y_train)
     self.assertEqual(pfl.formula, "c + standardize(x)")
     self.assertTrue("Intercept" in pfl.design_info.column_names)
     self.assertTrue(pfl.intercept)
     empc = pfl.score(X_test, y_test)
     self.assertAlmostEqual(empc, 25.5035418741)
Esempio n. 2
0
 def test_proflogit_access_fit_method_directly(self):
     X_train, y_train = load_data("../data/patsy_demo_train.dat", "y")
     X_test, y_test = load_data("../data/patsy_demo_test.dat", 0)
     pfl = ProfLogit(rga_kws={
         "niter_diff": 3,
         "disp": False,
         "random_state": 42
     }, ).fit(X_train, y_train)
     self.assertEqual(pfl.formula, "c + standardize(x)")
     self.assertTrue("Intercept" in pfl.design_info.column_names)
     self.assertTrue(pfl.intercept)
     empc = pfl.score(X_test, y_test)
     self.assertAlmostEqual(empc, 25.0827084152)
Esempio n. 3
0
 def test_proflogit_no_intercept_through_formula(self):
     ynm = "y"
     X_train, y_train = load_data("../data/patsy_demo_train.dat", ynm)
     X_test, y_test = load_data("../data/patsy_demo_test.dat", 0)
     pfl = ProfLogit(
         formula_like="c + standardize(x) - 1",
         rga_kws={
             "niter": 5,
             "disp": False,
             "random_state": 42
         },
     )
     pfl.fit(X_train, y_train)
     self.assertEqual(pfl.formula, "c + standardize(x) - 1")
     self.assertFalse("Intercept" in pfl.design_info.column_names)
     self.assertFalse(pfl.intercept)
     empc = pfl.score(X_test, y_test)
     self.assertAlmostEqual(empc, 25.5035418741)
Esempio n. 4
0
 def test_load_data(self):
     ynm = "y"
     yix = 0
     X0, _ = load_data("../data/patsy_demo_train.dat")
     y0 = X0[ynm]
     del X0[ynm]
     X1, y1 = load_data("../data/patsy_demo_train.dat", ynm)
     X2, y2 = load_data("../data/patsy_demo_train.dat", yix)
     d = [X0, X1, X2]
     for dix, d0 in enumerate(d):
         for d1 in d[dix + 1:]:
             for (k0, v0), (k1, v1) in zip(d0.items(), d1.items()):
                 self.assertEqual(k0, k1)
                 if isinstance(v0, list) and isinstance(v1, list):
                     self.assertListEqual(v0, v1)
                 else:
                     npt.assert_array_almost_equal(v0, v1)
     npt.assert_array_equal(y0, y1)
     npt.assert_array_equal(y0, y2)
     npt.assert_array_equal(y1, y2)
Esempio n. 5
0
 def test_proflogit_nfev_correct_large(self):
     X, y = load_data("../data/patsy_demo_train.dat", "y")
     n_fev = 43
     pfl = ProfLogit(rga_kws={
         "nfev": n_fev,
         "disp": False,
         "random_state": 42
     }, )
     pfl.fit(X, y)
     self.assertEqual(pfl.rga.res.nfev, n_fev)
     self.assertEqual(pfl.formula, "c + standardize(x)")
     self.assertTrue("Intercept" in pfl.design_info.column_names)
     self.assertTrue(pfl.intercept)
Esempio n. 6
0
 def test_proflogit_patsy(self):
     yix = 0
     X, y = load_data("../data/two-predictors.dat", yix, False)
     form = " + ".join([
         "standardize(f{})".format(cix) for cix in range(len(X) + 1)
         if cix != yix
     ])
     pfl = ProfLogit(rga_kws={
         "niter": 5,
         "disp": False,
         "random_state": 42
     }, )
     pfl.fit(X, y)
     self.assertEqual(pfl.formula, form)
     self.assertTrue("Intercept" in pfl.design_info.column_names)
     self.assertTrue(pfl.intercept)
     y_score = pfl.predict_proba(X)
     empc1 = EMPChurn(y, y_score).empc()
     empc2 = pfl.score(X, y)
     self.assertAlmostEqual(empc1, empc2)
Esempio n. 7
0
 def test_raise_error_variable_not_in_formula(self):
     X, y = load_data("../data/patsy_demo_train.dat", "y")
     with self.assertRaises(patsy.PatsyError):
         ProfLogit("b + standardize(x)").fit(X, y)  # 'b' not in X