本文整理汇总了Python中statsmodels.base.wrapper.populate_wrapper函数的典型用法代码示例。如果您正苦于以下问题:Python populate_wrapper函数的具体用法?Python populate_wrapper怎么用?Python populate_wrapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了populate_wrapper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RLMResultsWrapper
See Also
--------
statsmodels.iolib.summary2.Summary : class to hold summary results
"""
from statsmodels.iolib import summary2
smry = summary2.Summary()
smry.add_base(results=self, alpha=alpha, float_format=float_format,
xname=xname, yname=yname, title=title)
return smry
class RLMResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(RLMResultsWrapper, RLMResults) # noqa:E305
if __name__=="__main__":
#NOTE: This is to be removed
#Delivery Time Data is taken from Montgomery and Peck
import statsmodels.api as sm
#delivery time(minutes)
endog = np.array([16.68, 11.50, 12.03, 14.88, 13.75, 18.11, 8.00, 17.83,
79.24, 21.50, 40.33, 21.00, 13.50, 19.75, 24.00, 29.00, 15.35, 19.00,
9.50, 35.10, 17.90, 52.32, 18.75, 19.83, 10.75])
#number of cases, distance (Feet)
exog = np.array([[7, 3, 3, 4, 6, 7, 2, 7, 30, 5, 16, 10, 4, 6, 9, 10, 6,
7, 3, 17, 10, 26, 9, 8, 4], [560, 220, 340, 80, 150, 330, 110, 210, 1460,
示例2: GLMResultsWrapper
xname=xname, yname=yname, title=title)
return smry
class GLMResultsWrapper(lm.RegressionResultsWrapper):
_attrs = {
'resid_anscombe' : 'rows',
'resid_deviance' : 'rows',
'resid_pearson' : 'rows',
'resid_response' : 'rows',
'resid_working' : 'rows'
}
_wrap_attrs = wrap.union_dicts(lm.RegressionResultsWrapper._wrap_attrs,
_attrs)
wrap.populate_wrapper(GLMResultsWrapper, GLMResults)
if __name__ == "__main__":
import statsmodels.api as sm
data = sm.datasets.longley.load()
#data.exog = add_constant(data.exog)
GLMmod = GLM(data.endog, data.exog).fit()
GLMT = GLMmod.summary(returns='tables')
## GLMT[0].extend_right(GLMT[1])
## print(GLMT[0])
## print(GLMT[2])
GLMTp = GLMmod.summary(title='Test GLM')
"""
From Stata
示例3: TimeSeriesModelResults
self.data.predict_dates = dates
class TimeSeriesModelResults(base.LikelihoodModelResults):
def __init__(self, model, params, normalized_cov_params, scale=1.):
self.data = model.data
super(TimeSeriesModelResults,
self).__init__(model, params, normalized_cov_params, scale)
class TimeSeriesResultsWrapper(wrap.ResultsWrapper):
_attrs = {}
_wrap_attrs = wrap.union_dicts(base.LikelihoodResultsWrapper._wrap_attrs,
_attrs)
_methods = {'predict' : 'dates'}
_wrap_methods = wrap.union_dicts(base.LikelihoodResultsWrapper._wrap_methods,
_methods)
wrap.populate_wrapper(TimeSeriesResultsWrapper,
TimeSeriesModelResults)
if __name__ == "__main__":
import statsmodels.api as sm
import datetime
import pandas
data = sm.datasets.macrodata.load()
#make a DataFrame
#TODO: attach a DataFrame to some of the datasets, for quicker use
dates = [str(int(x[0])) +':'+ str(int(x[1])) \
for x in data.data[['year','quarter']]]
df = pandas.DataFrame(data.data[['realgdp','realinv','realcons']], index=dates)
ex_mod = TimeSeriesModel(df)
示例4: func
return x + h
f1 = func(x + h, model) + L1_wt*np.abs(x + h)
if f1 <= f + L1_wt*np.abs(x) + 1e-10:
return x + h
# Fallback for models where the loss is not quadratic
from scipy.optimize import brent
x_opt = brent(func, args=(model,), brack=(x-1, x+1), tol=tol)
return x_opt
class RegularizedResults(Results):
def __init__(self, model, params):
super(RegularizedResults, self).__init__(model, params)
@cache_readonly
def fittedvalues(self):
return self.model.predict(self.params)
class RegularizedResultsWrapper(wrap.ResultsWrapper):
_attrs = {
'params': 'columns',
'resid': 'rows',
'fittedvalues': 'rows',
}
_wrap_attrs = _attrs
wrap.populate_wrapper(RegularizedResultsWrapper, # noqa:E305
RegularizedResults)
示例5: get_margeff
def get_margeff(self, at='overall', method='dydx', atexog=None,
dummy=False, count=False):
"""Get marginal effects of the fitted model.
Not yet implemented for Zero Inflated Models
"""
raise NotImplementedError("not yet implemented for zero inflation")
class L1ZeroInflatedPoissonResults(L1CountResults, ZeroInflatedPoissonResults):
pass
class ZeroInflatedPoissonResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(ZeroInflatedPoissonResultsWrapper,
ZeroInflatedPoissonResults)
class L1ZeroInflatedPoissonResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(L1ZeroInflatedPoissonResultsWrapper,
L1ZeroInflatedPoissonResults)
class ZeroInflatedGeneralizedPoissonResults(CountResults):
__doc__ = _discrete_results_docs % {
"one_line_description" : "A results class for Zero Inflated Generalized Poisson",
"extra_attr" : ""}
@cache_readonly
def _dispersion_factor(self):
示例6: RLMResultsWrapper
#add warnings/notes, added to text format only
etext =[]
wstr = \
'''If the model instance has been used for another fit with different fit
parameters, then the fit options might not be the correct ones anymore .'''
etext.append(wstr)
if etext:
smry.add_extra_txt(etext)
return smry
class RLMResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(RLMResultsWrapper, RLMResults)
if __name__=="__main__":
#NOTE: This is to be removed
#Delivery Time Data is taken from Montgomery and Peck
import statsmodels.api as sm
#delivery time(minutes)
endog = np.array([16.68, 11.50, 12.03, 14.88, 13.75, 18.11, 8.00, 17.83,
79.24, 21.50, 40.33, 21.00, 13.50, 19.75, 24.00, 29.00, 15.35, 19.00,
9.50, 35.10, 17.90, 52.32, 18.75, 19.83, 10.75])
#number of cases, distance (Feet)
exog = np.array([[7, 3, 3, 4, 6, 7, 2, 7, 30, 5, 16, 10, 4, 6, 9, 10, 6,
7, 3, 17, 10, 26, 9, 8, 4], [560, 220, 340, 80, 150, 330, 110, 210, 1460,
605, 688, 215, 255, 462, 448, 776, 200, 132, 36, 770, 140, 810, 450, 635,
示例7: HoltWintersResultsWrapper
return smry
class HoltWintersResultsWrapper(ResultsWrapper):
_attrs = {'fittedvalues': 'rows',
'level': 'rows',
'resid': 'rows',
'season': 'rows',
'slope': 'rows'}
_wrap_attrs = union_dicts(ResultsWrapper._wrap_attrs, _attrs)
_methods = {'predict': 'dates',
'forecast': 'dates'}
_wrap_methods = union_dicts(ResultsWrapper._wrap_methods, _methods)
populate_wrapper(HoltWintersResultsWrapper, HoltWintersResults)
class ExponentialSmoothing(TimeSeriesModel):
"""
Holt Winter's Exponential Smoothing
Parameters
----------
endog : array-like
Time series
trend : {"add", "mul", "additive", "multiplicative", None}, optional
Type of trend component.
damped : bool, optional
Should the trend component be damped.
seasonal : {"add", "mul", "additive", "multiplicative", None}, optional
示例8: TimeSeriesModelResults
class TimeSeriesModelResults(base.LikelihoodModelResults):
def __init__(self, model, params, normalized_cov_params, scale=1.):
self.data = model.data
super(TimeSeriesModelResults,
self).__init__(model, params, normalized_cov_params, scale)
class TimeSeriesResultsWrapper(wrap.ResultsWrapper):
_attrs = {}
_wrap_attrs = wrap.union_dicts(base.LikelihoodResultsWrapper._wrap_attrs,
_attrs)
_methods = {'predict' : 'dates'}
_wrap_methods = wrap.union_dicts(base.LikelihoodResultsWrapper._wrap_methods,
_methods)
wrap.populate_wrapper(TimeSeriesResultsWrapper, # noqa:E305
TimeSeriesModelResults)
if __name__ == "__main__":
import statsmodels.api as sm
import pandas
data = sm.datasets.macrodata.load(as_pandas=False)
#make a DataFrame
#TODO: attach a DataFrame to some of the datasets, for quicker use
dates = [str(int(x[0])) +':'+ str(int(x[1])) \
for x in data.data[['year','quarter']]]
df = pandas.DataFrame(data.data[['realgdp','realinv','realcons']], index=dates)
ex_mod = TimeSeriesModel(df)
示例9: sum
av2 = k1 * av - k2 * vn
vm = np.eye(p) - 2 * sum(cv) / len(cv) + av2
a, b = np.linalg.eigh(vm)
jj = np.argsort(-a)
a = a[jj]
b = b[:, jj]
params = np.linalg.solve(self._covxr.T, b)
results = DimReductionResults(self, params, eigs=a)
return DimReductionResultsWrapper(results)
class DimReductionResults(model.Results):
def __init__(self, model, params, eigs):
super(DimReductionResults, self).__init__(
model, params)
self.eigs = eigs
class DimReductionResultsWrapper(wrap.ResultsWrapper):
_attrs = {
'params': 'columns',
}
_wrap_attrs = _attrs
wrap.populate_wrapper(DimReductionResultsWrapper,
DimReductionResults)
示例10: hasattr
if hasattr(self.data, 'dates') and self.data.dates is not None:
dates = self.data.dates._mpl_repr()
else:
dates = np.arange(self.nobs)
llb = self.loglikelihood_burn
# Plot cusum series and reference line
ax.plot(dates[llb:], self.cusum_squares, label='CUSUM of squares')
ref_line = (np.arange(llb, self.nobs) - llb) / (self.nobs - llb)
ax.plot(dates[llb:], ref_line, 'k', alpha=0.3)
# Plot significance bounds
lower_line, upper_line = self._cusum_squares_significance_bounds(alpha)
ax.plot([dates[llb], dates[-1]], upper_line, 'k--',
label='%d%% significance' % (alpha * 100))
ax.plot([dates[llb], dates[-1]], lower_line, 'k--')
ax.legend(loc=legend_loc)
return fig
class RecursiveLSResultsWrapper(MLEResultsWrapper):
_attrs = {}
_wrap_attrs = wrap.union_dicts(MLEResultsWrapper._wrap_attrs,
_attrs)
_methods = {}
_wrap_methods = wrap.union_dicts(MLEResultsWrapper._wrap_methods,
_methods)
wrap.populate_wrapper(RecursiveLSResultsWrapper, RecursiveLSResults)
示例11: DynamicFactorResultsWrapper
model : DynamicFactor instance
The fitted model instance
Attributes
----------
specification : dictionary
Dictionary including all attributes from the DynamicFactor model
instance.
coefficient_matrices_var : array
Array containing autoregressive lag polynomial coefficient matrices,
ordered from lowest degree to highest.
See Also
--------
dismalpy.ssm.mlemodel.MLEResults
dismalpy.ssm.kalman_smoother.SmootherResults
dismalpy.ssm.kalman_filter.FilterResults
dismalpy.ssm.representation.FrozenRepresentation
"""
pass
class DynamicFactorResultsWrapper(mlemodel.MLEResultsWrapper):
_attrs = {}
_wrap_attrs = wrap.union_dicts(
mlemodel.MLEResultsWrapper._wrap_attrs, _attrs)
_methods = {}
_wrap_methods = wrap.union_dicts(
mlemodel.MLEResultsWrapper._wrap_methods, _methods)
wrap.populate_wrapper(DynamicFactorResultsWrapper, DynamicFactorResults)
示例12: UnobservedComponentsResultsWrapper
----------
model : UnobservedComponents instance
The fitted model instance
Attributes
----------
specification : dictionary
Dictionary including all attributes from the unobserved components
model instance.
See Also
--------
dismalpy.ssm.mlemodel.MLEResults
dismalpy.ssm.kalman_smoother.SmootherResults
dismalpy.ssm.kalman_filter.FilterResults
dismalpy.ssm.representation.FrozenRepresentation
"""
pass
class UnobservedComponentsResultsWrapper(
mlemodel.MLEResultsWrapper):
_attrs = {}
_wrap_attrs = wrap.union_dicts(
mlemodel.MLEResultsWrapper._wrap_attrs, _attrs)
_methods = {}
_wrap_methods = wrap.union_dicts(
mlemodel.MLEResultsWrapper._wrap_methods, _methods)
wrap.populate_wrapper(UnobservedComponentsResultsWrapper,
UnobservedComponentsResults)
示例13: Summary
if not title is None:
title = "Nonlinear Quantile Regression Results"
from statsmodels.iolib.summary import Summary
smry = Summary()
smry.add_table_2cols(self, gleft=top_left, gright=top_right, yname=yname, xname=xname, title=title)
smry.add_table_params(self, yname=yname, xname=xname, alpha=alpha, use_t=False)
return smry
class NLRQResultsWrapper(lm.RegressionResultsWrapper):
pass
wrap.populate_wrapper(NLRQResultsWrapper, NLRQResults)
def Polynomial1(x, x0, par):
K = x.shape[1]-1
mu0 = par[0]
mu1 = par[1:K+1].reshape(K, 1)
return (mu0 + np.dot(x-x0, mu1)).reshape(x.shape[0])
def DPolynomial1(x, x0, par):
return np.concatenate([np.ones((x.shape[0], 1)), x-x0], axis=1), True
def Polynomial2(x, x0, par):
K = int(1/2+np.sqrt(x.shape[1]-3/4))
mu0 = par[0]
mu1 = par[1:K+1].reshape(K, 1)
mu2 = par[K+1:].reshape(K, K)
示例14: MarkovAutoregressionResultsWrapper
params : array
Fitted parameters
filter_results : HamiltonFilterResults or KimSmootherResults instance
The underlying filter and, optionally, smoother output
cov_type : string
The type of covariance matrix estimator to use. Can be one of 'approx',
'opg', 'robust', or 'none'.
Attributes
----------
model : Model instance
A reference to the model that was fit.
filter_results : HamiltonFilterResults or KimSmootherResults instance
The underlying filter and, optionally, smoother output
nobs : float
The number of observations used to fit the model.
params : array
The parameters of the model.
scale : float
This is currently set to 1.0 and not used by the model or its results.
"""
pass
class MarkovAutoregressionResultsWrapper(
markov_regression.MarkovRegressionResultsWrapper):
pass
wrap.populate_wrapper(MarkovAutoregressionResultsWrapper,
MarkovAutoregressionResults)
示例15: max
dates = self.data.dates._mpl_repr()
else:
dates = np.arange(self.nobs)
d = max(self.nobs_diffuse, self.loglikelihood_burn)
# Plot cusum series and reference line
ax.plot(dates[d:], self.cusum_squares, label='CUSUM of squares')
ref_line = (np.arange(d, self.nobs) - d) / (self.nobs - d)
ax.plot(dates[d:], ref_line, 'k', alpha=0.3)
# Plot significance bounds
lower_line, upper_line = self._cusum_squares_significance_bounds(alpha)
ax.plot([dates[d], dates[-1]], upper_line, 'k--',
label='%d%% significance' % (alpha * 100))
ax.plot([dates[d], dates[-1]], lower_line, 'k--')
ax.legend(loc=legend_loc)
return fig
class RecursiveLSResultsWrapper(MLEResultsWrapper):
_attrs = {}
_wrap_attrs = wrap.union_dicts(MLEResultsWrapper._wrap_attrs,
_attrs)
_methods = {}
_wrap_methods = wrap.union_dicts(MLEResultsWrapper._wrap_methods,
_methods)
wrap.populate_wrapper(RecursiveLSResultsWrapper, # noqa:E305
RecursiveLSResults)