Ejemplo n.º 1
0
def check_pickle(obj):
    fh = BytesIO()
    cPickle.dump(obj, fh, protocol=cPickle.HIGHEST_PROTOCOL)
    plen = fh.tell()
    fh.seek(0, 0)
    res = cPickle.load(fh)
    fh.close()
    return res, plen
Ejemplo n.º 2
0
def check_pickle(obj):
    fh = BytesIO()
    cPickle.dump(obj, fh, protocol=cPickle.HIGHEST_PROTOCOL)
    plen = fh.tell()
    fh.seek(0, 0)
    res = cPickle.load(fh)
    fh.close()
    return res, plen
Ejemplo n.º 3
0
def check_pickle(obj):
    fh =StringIO()
    cPickle.dump(obj, fh)
    plen = fh.pos
    fh.seek(0,0)
    res = cPickle.load(fh)
    fh.close()
    return res, plen
Ejemplo n.º 4
0
def save_pickle(obj, fname):
    """
    Save the object to file via pickling.

    Parameters
    ----------
    fname : str
        Filename to pickle to
    """
    with get_file_obj(fname, 'wb') as fout:
        cPickle.dump(obj, fout, protocol=-1)
Ejemplo n.º 5
0
def save_pickle(obj, fname):
    """
    Save the object to file via pickling.

    Parameters
    ----------
    fname : str
        Filename to pickle to
    """
    with get_file_obj(fname, 'wb') as fout:
        cPickle.dump(obj, fout, protocol=-1)
Ejemplo n.º 6
0
#model = sm.Poisson(y_count, x)#, exposure=np.ones(nobs), offset=np.zeros(nobs)) #bug with default
results = model.fit()


#print results.predict(xf)
print(results.model.predict(results.params, xf))
results.summary()

shrinkit = 1
if shrinkit:
    results.remove_data()

from statsmodels.compat.python import cPickle
fname = 'try_shrink%d_ols.pickle' % shrinkit
fh = open(fname, 'w')
cPickle.dump(results._results, fh)  #pickling wrapper doesn't work
fh.close()
fh = open(fname, 'r')
results2 = cPickle.load(fh)
fh.close()
print(results2.predict(xf))
print(results2.model.predict(results.params, xf))


y_count = np.random.poisson(np.exp(x.sum(1)-x.mean()))
model = sm.Poisson(y_count, x)#, exposure=np.ones(nobs), offset=np.zeros(nobs)) #bug with default
results = model.fit(method='bfgs')

results.summary()

print(results.model.predict(results.params, xf, exposure=1, offset=0))