def __init__(self): super(self.__class__, self).__init__() #initialize DGP nobs = self.nobs y_true, x, exog = self.y_true, self.x, self.exog np.random.seed(8765993) sigma_noise = 0.1 y = y_true + sigma_noise * np.random.randn(nobs) m = AdditiveModel(x) m.fit(y) res_gam = m.results #TODO: currently attached to class res_ols = OLS(y, exog).fit() #Note: there still are some naming inconsistencies self.res1 = res1 = Dummy() #for gam model #res2 = Dummy() #for benchmark self.res2 = res2 = res_ols #reuse existing ols results, will add additional res1.y_pred = res_gam.predict(x) res2.y_pred = res_ols.model.predict(res_ols.params, exog) res1.y_predshort = res_gam.predict(x[:10]) slopes = [i for ss in m.smoothers for i in ss.params[1:]] const = res_gam.alpha + sum([ss.params[1] for ss in m.smoothers]) #print const, slopes res1.params = np.array([const] + slopes)
x1.sort() x2 = R.standard_normal(500) x2.sort() y = R.standard_normal((500, )) f1 = lambda x1: (x1 + x1**2 - 3 - 1.5 * x1**3 + np.exp(-x1)) f2 = lambda x2: (x2 + x2**2 - np.exp(x2)) z = standardize(f1(x1)) + standardize(f2(x2)) z = standardize(z) * 0.1 y += z d = np.array([x1, x2]).T if example == 1: print "normal" m = AdditiveModel(d) m.fit(y) x = np.linspace(-2, 2, 50) print m import scipy.stats, time if example == 2: print "binomial" f = family.Binomial() b = np.asarray([scipy.stats.bernoulli.rvs(p) for p in f.link.inverse(y)]) b.shape = y.shape m = GAM(b, d, family=f) toc = time.time() m.fit(b)