コード例 #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
コード例 #2
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
コード例 #3
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
コード例 #4
0
ファイル: smpickle.py プロジェクト: locolucco209/MongoScraper
def load_pickle(fname):
    """
    Load a previously saved object from file

    Parameters
    ----------
    fname : str
        Filename to unpickle

    Notes
    -----
    This method can be used to load *both* models and results.
    """
    with get_file_obj(fname, 'rb') as fin:
        return cPickle.load(fin)
コード例 #5
0
ファイル: smpickle.py プロジェクト: haribharadwaj/statsmodels
def load_pickle(fname):
    """
    Load a previously saved object from file

    Parameters
    ----------
    fname : str
        Filename to unpickle

    Notes
    -----
    This method can be used to load *both* models and results.
    """
    with get_file_obj(fname, 'rb') as fin:
        return cPickle.load(fin)
コード例 #6
0
import numpy as np
import matplotlib.finance as fin
import matplotlib.pyplot as plt
import datetime as dt

import pandas as pa
from statsmodels.compat.python import cPickle

import statsmodels.api as sm
import statsmodels.sandbox as sb
import statsmodels.sandbox.tools as sbtools

from statsmodels.graphics.correlation import plot_corr, plot_corr_grid

try:
    rrdm = cPickle.load(file('dj30rr','rb'))
except Exception: #blanket for any unpickling error
    print("Error with unpickling, a new pickle file can be created with findow_1")
    raise

ticksym = rrdm.columns.tolist()
rr = rrdm.values[1:400]

rrcorr = np.corrcoef(rr, rowvar=0)


plot_corr(rrcorr, xnames=ticksym)
nvars = rrcorr.shape[0]
plt.figure()
plt.hist(rrcorr[np.triu_indices(nvars,1)])
plt.title('Correlation Coefficients')
コード例 #7
0
#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))

if shrinkit:
    results.remove_data()
コード例 #8
0
Author: josef-pktd
"""

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

from statsmodels.compat.python import cPickle

import statsmodels.sandbox.tools as sbtools

from statsmodels.graphics.correlation import plot_corr, plot_corr_grid

try:
    with open('dj30rr', 'rb') as fd:
        rrdm = cPickle.load(fd)
except Exception: #blanket for any unpickling error
    print("Error with unpickling, a new pickle file can be created with findow_1")
    raise

ticksym = rrdm.columns.tolist()
rr = rrdm.values[1:400]

rrcorr = np.corrcoef(rr, rowvar=0)


plot_corr(rrcorr, xnames=ticksym)
nvars = rrcorr.shape[0]
plt.figure()
plt.hist(rrcorr[np.triu_indices(nvars,1)])
plt.title('Correlation Coefficients')
コード例 #9
0
ファイル: ex_ratereturn.py プロジェクト: bashtage/statsmodels
Created on Sat Jan 30 16:30:18 2010
Author: josef-pktd
"""

import numpy as np
import matplotlib.pyplot as plt

from statsmodels.compat.python import cPickle

import statsmodels.sandbox.tools as sbtools

from statsmodels.graphics.correlation import plot_corr, plot_corr_grid

try:
    with open('dj30rr', 'rb') as fd:
        rrdm = cPickle.load(fd)
except Exception: #blanket for any unpickling error
    print("Error with unpickling, a new pickle file can be created with findow_1")
    raise

ticksym = rrdm.columns.tolist()
rr = rrdm.values[1:400]

rrcorr = np.corrcoef(rr, rowvar=0)


plot_corr(rrcorr, xnames=ticksym)
nvars = rrcorr.shape[0]
plt.figure()
plt.hist(rrcorr[np.triu_indices(nvars,1)])
plt.title('Correlation Coefficients')
コード例 #10
0
import numpy as np
import matplotlib.finance as fin
import matplotlib.pyplot as plt
import datetime as dt

import pandas as pa
from statsmodels.compat.python import cPickle

import statsmodels.api as sm
import statsmodels.sandbox as sb
import statsmodels.sandbox.tools as sbtools

from statsmodels.graphics.correlation import plot_corr, plot_corr_grid

try:
    rrdm = cPickle.load(file('dj30rr', 'rb'))
except Exception:  #blanket for any unpickling error
    print(
        "Error with unpickling, a new pickle file can be created with findow_1"
    )
    raise

ticksym = rrdm.columns.tolist()
rr = rrdm.values[1:400]

rrcorr = np.corrcoef(rr, rowvar=0)

plot_corr(rrcorr, xnames=ticksym)
nvars = rrcorr.shape[0]
plt.figure()
plt.hist(rrcorr[np.triu_indices(nvars, 1)])