def setup_class(cls):
        endog_bin = (endog > endog.mean()).astype(int)
        cls.cov_type = 'cluster'

        mod1 = GLM(endog_bin, exog, family=families.Binomial(link=links.probit()))
        cls.res1 = mod1.fit(method='newton',
                            cov_type='cluster', cov_kwds=dict(groups=group))

        mod1 = smd.Probit(endog_bin, exog)
        cls.res2 = mod1.fit(cov_type='cluster', cov_kwds=dict(groups=group))
        cls.rtol = 1e-6
Ejemplo n.º 2
0
from statsmodels.genmod.families import Binomial
from statsmodels.genmod.families.links import probit

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cur = conn.cursor()  # cursor needed to perform db ops

cur.execute("SELECT * FROM Iris;")
iris_df = pd.DataFrame(cur.fetchall())

X = np.array(iris_df.iloc[:, 0:4])
y = np.array(iris_df.iloc[:, 4] == 'virginica', dtype=int)

weight = np.ones(150)

probit_link = probit()
bin_family = Binomial(probit_link)
my_glm = GLM(y, X, freq_weights=weight, family=bin_family)
my_glm_fit = my_glm.fit()

theta = my_glm_fit.params
current_dt = datetime.datetime.now()

cur.execute("INSERT INTO scores VALUES (%s, %s, %s, %s, %s)",
            (str(current_dt), theta[0], theta[1], theta[2], theta[3]))

conn.commit()

cur.close()
conn.close()