本文整理汇总了Python中statsmodels.iolib.summary.Summary.add_extra_txt方法的典型用法代码示例。如果您正苦于以下问题:Python Summary.add_extra_txt方法的具体用法?Python Summary.add_extra_txt怎么用?Python Summary.add_extra_txt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.iolib.summary.Summary
的用法示例。
在下文中一共展示了Summary.add_extra_txt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
def summary(self, yname=None, xname=None, title=0, alpha=.05,
return_fmt='text'):
"""
This is for testing the new summary setup
"""
from statsmodels.iolib.summary import (summary_top,
summary_params, summary_return)
## left = [(i, None) for i in (
## 'Dependent Variable:',
## 'Model type:',
## 'Method:',
## 'Date:',
## 'Time:',
## 'Number of Obs:',
## 'df resid',
## 'df model',
## )]
top_left = [('Dep. Variable:', None),
('Model:', None),
('Method:', ['IRLS']),
('Norm:', [self.fit_options['norm']]),
('Scale Est.:', [self.fit_options['scale_est']]),
('Cov Type:', [self.fit_options['cov']]),
('Date:', None),
('Time:', None),
('No. Iterations:', ["%d" % self.fit_history['iteration']])
]
top_right = [('No. Observations:', None),
('Df Residuals:', None),
('Df Model:', None)
]
if not title is None:
title = "Robust linear Model Regression Results"
#boiler plate
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=.05,
use_t=False)
#diagnostic table is not used yet
# smry.add_table_2cols(self, gleft=diagn_left, gright=diagn_right,
# yname=yname, xname=xname,
# title="")
#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
示例2: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
def summary(self, yname=None, xname=None, title=0, alpha=0.05, return_fmt="text"):
"""
This is for testing the new summary setup
"""
from statsmodels.iolib.summary import summary_top, summary_params, summary_return
## left = [(i, None) for i in (
## 'Dependent Variable:',
## 'Model type:',
## 'Method:',
## 'Date:',
## 'Time:',
## 'Number of Obs:',
## 'df resid',
## 'df model',
## )]
top_left = [
("Dep. Variable:", None),
("Model:", None),
("Method:", ["IRLS"]),
("Norm:", [self.fit_options["norm"]]),
("Scale Est.:", [self.fit_options["scale_est"]]),
("Cov Type:", [self.fit_options["cov"]]),
("Date:", None),
("Time:", None),
("No. Iterations:", ["%d" % self.fit_history["iteration"]]),
]
top_right = [("No. Observations:", None), ("Df Residuals:", None), ("Df Model:", None)]
if not title is None:
title = "Robust linear Model Regression Results"
# boiler plate
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=self.use_t)
# diagnostic table is not used yet
# smry.add_table_2cols(self, gleft=diagn_left, gright=diagn_right,
# yname=yname, xname=xname,
# title="")
# 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
示例3: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
def summary(self, yname=None, xname=None, title=0, alpha=.05,
return_fmt='text'):
"""
This is for testing the new summary setup
"""
top_left = [('Dep. Variable:', None),
('Model:', None),
('Method:', ['IRLS']),
('Norm:', [self.fit_options['norm']]),
('Scale Est.:', [self.fit_options['scale_est']]),
('Cov Type:', [self.fit_options['cov']]),
('Date:', None),
('Time:', None),
('No. Iterations:', ["%d" % self.fit_history['iteration']])
]
top_right = [('No. Observations:', None),
('Df Residuals:', None),
('Df Model:', None)
]
if title is not None:
title = "Robust linear Model Regression Results"
# boiler plate
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=self.use_t)
# add warnings/notes, added to text format only
etext = []
wstr = ("If the model instance has been used for another fit "
"with different fit\n"
"parameters, then the fit options might not be the correct "
"ones anymore .")
etext.append(wstr)
if etext:
smry.add_extra_txt(etext)
return smry
示例4: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
def summary(self):
"""Summary of test, containing statistic, p-value and critical values
"""
table_data = [('Test Statistic', '{0:0.3f}'.format(self.stat)),
('P-value', '{0:0.3f}'.format(self.pvalue)),
('Lags', '{0:d}'.format(self.lags))]
title = self._title
if not title:
title = self._test_name + " Results"
table = SimpleTable(table_data, stubs=None, title=title, colwidths=18,
datatypes=[0, 1], data_aligns=("l", "r"))
smry = Summary()
smry.tables.append(table)
cv_string = 'Critical Values: '
cv = self._critical_values.keys()
g = lambda x: float(x.split('%')[0])
cv_numeric = array(lmap(g, cv))
cv_numeric = sort(cv_numeric)
for val in cv_numeric:
p = str(int(val)) + '%'
cv_string += '{0:0.2f}'.format(self._critical_values[p])
cv_string += ' (' + p + ')'
if val != cv_numeric[-1]:
cv_string += ', '
extra_text = ['Trend: ' + TREND_DESCRIPTION[self._trend],
cv_string,
'Null Hypothesis: ' + self.null_hypothesis,
'Alternative Hypothesis: ' + self.alternative_hypothesis]
smry.add_extra_txt(extra_text)
if self._summary_text:
smry.add_extra_txt(self._summary_text)
return smry
示例5: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
#.........这里部分代码省略.........
yname : string, optional
Default is `y`
xname : list of strings, optional
Default is `var_##` for ## in p the number of regressors
title : string, optional
Title for the top table. If not None, then this replaces the
default title
alpha : float
significance level for the confidence intervals
Returns
-------
smry : Summary instance
this holds the summary tables and text, which can be printed or
converted to various output formats.
See Also
--------
statsmodels.iolib.summary.Summary : class to hold summary
results
"""
# #TODO: import where we need it (for now), add as cached attributes
# from statsmodels.stats.stattools import (jarque_bera,
# omni_normtest, durbin_watson)
# jb, jbpv, skew, kurtosis = jarque_bera(self.wresid)
# omni, omnipv = omni_normtest(self.wresid)
#
eigvals = self.eigenvals
condno = self.condition_number
#
# self.diagn = dict(jb=jb, jbpv=jbpv, skew=skew, kurtosis=kurtosis,
# omni=omni, omnipv=omnipv, condno=condno,
# mineigval=eigvals[0])
top_left = [('Dep. Variable:', None),
('Model:', None),
('Method:', ['Least Squares']),
('Date:', None),
('Time:', None)
]
top_right = [('Pseudo R-squared:', ["%#8.4g" % self.prsquared]),
('Bandwidth:', ["%#8.4g" % self.bandwidth]),
('Sparsity:', ["%#8.4g" % self.sparsity]),
('No. Observations:', None),
('Df Residuals:', None), #[self.df_resid]), #TODO: spelling
('Df Model:', None) #[self.df_model])
]
# diagn_left = [('Omnibus:', ["%#6.3f" % omni]),
# ('Prob(Omnibus):', ["%#6.3f" % omnipv]),
# ('Skew:', ["%#6.3f" % skew]),
# ('Kurtosis:', ["%#6.3f" % kurtosis])
# ]
#
# diagn_right = [('Durbin-Watson:', ["%#8.3f" % durbin_watson(self.wresid)]),
# ('Jarque-Bera (JB):', ["%#8.3f" % jb]),
# ('Prob(JB):', ["%#8.3g" % jbpv]),
# ('Cond. No.', ["%#8.3g" % condno])
# ]
if title is None:
title = self.model.__class__.__name__ + ' ' + "Regression Results"
#create summary table instance
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=.05,
use_t=True)
# smry.add_table_2cols(self, gleft=diagn_left, gright=diagn_right,
#yname=yname, xname=xname,
#title="")
#add warnings/notes, added to text format only
etext = []
if eigvals[-1] < 1e-10:
wstr = "The smallest eigenvalue is %6.3g. This might indicate "
wstr += "that there are\n"
wstr += "strong multicollinearity problems or that the design "
wstr += "matrix is singular."
wstr = wstr % eigvals[-1]
etext.append(wstr)
elif condno > 1000: #TODO: what is recommended
wstr = "The condition number is large, %6.3g. This might "
wstr += "indicate that there are\n"
wstr += "strong multicollinearity or other numerical "
wstr += "problems."
wstr = wstr % condno
etext.append(wstr)
if etext:
smry.add_extra_txt(etext)
return smry
示例6: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
def summary(self, alpha=.05, start=None, model_name=None):
"""
Summarize the Model
Parameters
----------
alpha : float, optional
Significance level for the confidence intervals. Default is 0.05.
start : int, optional
Integer of the start observation. Default is 0.
model_name : string
The name of the model used. Default is to use model class name.
Returns
-------
summary : Summary instance
This holds the summary table and text, which can be printed or
converted to various output formats.
See Also
--------
statsmodels.iolib.summary.Summary
"""
from statsmodels.iolib.summary import Summary
model = self.model
title = 'Statespace Model Results'
if start is None:
start = 0
if self.data.dates is not None:
dates = self.data.dates
d = dates[start]
sample = ['%02d-%02d-%02d' % (d.month, d.day, d.year)]
d = dates[-1]
sample += ['- ' + '%02d-%02d-%02d' % (d.month, d.day, d.year)]
else:
sample = [str(start), ' - ' + str(self.model.nobs)]
if model_name is None:
model_name = model.__class__.__name__
top_left = [
('Dep. Variable:', None),
('Model:', [model_name]),
('Date:', None),
('Time:', None),
('Sample:', [sample[0]]),
('', [sample[1]])
]
top_right = [
('No. Observations:', [self.model.nobs]),
('Log Likelihood', ["%#5.3f" % self.llf]),
('AIC', ["%#5.3f" % self.aic]),
('BIC', ["%#5.3f" % self.bic]),
('HQIC', ["%#5.3f" % self.hqic])
]
if hasattr(self, 'cov_type'):
top_left.append(('Covariance Type:', [self.cov_type]))
summary = Summary()
summary.add_table_2cols(self, gleft=top_left, gright=top_right,
title=title)
summary.add_table_params(self, alpha=alpha,
xname=self.data.param_names, use_t=False)
# Add warnings/notes, added to text format only
etext = []
if hasattr(self, 'cov_type'):
etext.append(self.cov_kwds['description'])
if etext:
etext = ["[{0}] {1}".format(i + 1, text)
for i, text in enumerate(etext)]
etext.insert(0, "Warnings:")
summary.add_extra_txt(etext)
return summary
示例7: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
def summary(self, yname=None, xname=None, title=None, alpha=.05):
"""
Summarize the Regression Results
Parameters
-----------
yname : string, optional
Default is `y`
xname : list of strings, optional
Default is `var_##` for ## in p the number of regressors
title : string, optional
Title for the top table. If not None, then this replaces the
default title
alpha : float
significance level for the confidence intervals
Returns
-------
smry : Summary instance
this holds the summary tables and text, which can be printed or
converted to various output formats.
See Also
--------
statsmodels.iolib.summary.Summary : class to hold summary
results
"""
top_left = [('Dep. Variable:', None),
('Model:', None),
('Model Family:', [self.family.__class__.__name__]),
('Link Function:', [self.family.link.__class__.__name__]),
('Method:', ['IRLS']),
('Date:', None),
('Time:', None),
('No. Iterations:',
["%d" % self.fit_history['iteration']]),
]
top_right = [('No. Observations:', None),
('Df Residuals:', None),
('Df Model:', None),
('Scale:', [self.scale]),
('Log-Likelihood:', None),
('Deviance:', ["%#8.5g" % self.deviance]),
('Pearson chi2:', ["%#6.3g" % self.pearson_chi2])
]
if title is None:
title = "Generalized Linear Model Regression Results"
#create summary tables
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=self.use_t)
if hasattr(self, 'constraints'):
smry.add_extra_txt(['Model has been estimated subject to linear '
'equality constraints.'])
#diagnostic table is not used yet:
#smry.add_table_2cols(self, gleft=diagn_left, gright=diagn_right,
# yname=yname, xname=xname,
# title="")
return smry
示例8: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
#.........这里部分代码省略.........
Returns
-------
summary : Summary instance
Object that contains tables and facilitated export to text, html or
latex
"""
# Summary layout
# 1. Overall information
# 2. Mean parameters
# 3. Volatility parameters
# 4. Distribution parameters
# 5. Notes
model = self.model
model_name = model.name + ' - ' + model.volatility.name
# Summary Header
top_left = [('Dep. Variable:', self._dep_name),
('Mean Model:', model.name),
('Vol Model:', model.volatility.name),
('Distribution:', model.distribution.name),
('Method:', 'User-specified Parameters'),
('', ''),
('Date:', self._datetime.strftime('%a, %b %d %Y')),
('Time:', self._datetime.strftime('%H:%M:%S'))]
top_right = [('R-squared:', '--'),
('Adj. R-squared:', '--'),
('Log-Likelihood:', '%#10.6g' % self.loglikelihood),
('AIC:', '%#10.6g' % self.aic),
('BIC:', '%#10.6g' % self.bic),
('No. Observations:', self._nobs),
('', ''),
('', ''),]
title = model_name + ' Model Results'
stubs = []
vals = []
for stub, val in top_left:
stubs.append(stub)
vals.append([val])
table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)
# create summary table instance
smry = Summary()
# Top Table
# Parameter table
fmt = fmt_2cols
fmt['data_fmts'][1] = '%18s'
top_right = [('%-21s' % (' ' + k), v) for k, v in top_right]
stubs = []
vals = []
for stub, val in top_right:
stubs.append(stub)
vals.append([val])
table.extend_right(SimpleTable(vals, stubs=stubs))
smry.tables.append(table)
stubs = self._names
header = ['coef']
vals = (self.params,)
formats = [(10, 4)]
pos = 0
param_table_data = []
for _ in range(len(vals[0])):
row = []
for i, val in enumerate(vals):
if isinstance(val[pos], np.float64):
converted = format_float_fixed(val[pos], *formats[i])
else:
converted = val[pos]
row.append(converted)
pos += 1
param_table_data.append(row)
mc = self.model.num_params
vc = self.model.volatility.num_params
dc = self.model.distribution.num_params
counts = (mc, vc, dc)
titles = ('Mean Model', 'Volatility Model', 'Distribution')
total = 0
for title, count in zip(titles, counts):
if count == 0:
continue
table_data = param_table_data[total:total + count]
table_stubs = stubs[total:total + count]
total += count
table = SimpleTable(table_data,
stubs=table_stubs,
txt_fmt=fmt_params,
headers=header, title=title)
smry.tables.append(table)
extra_text = ('Results generated with user-specified parameters.',
'Since the model was not estimated, there are no std. '
'errors.')
smry.add_extra_txt(extra_text)
return smry
示例9: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
def summary(self, yname=None, xname=None, title=None, alpha=.05):
"""Summarize the Regression Results
Parameters
----------
yname : string, optional
Default is `y`
xname : list of strings, optional
Default is `var_##` for ## in p the number of regressors
title : string, optional
Title for the top table. If not None, then this replaces the
default title
alpha : float
significance level for the confidence intervals
Returns
-------
smry : Summary instance
this holds the summary tables and text, which can be printed or
converted to various output formats.
See Also
--------
statsmodels.iolib.summary.Summary : class to hold summary results
"""
eigvals = self.eigenvals
condno = self.condition_number
top_left = [('Dep. Variable:', None),
('Model:', None),
('Method:', ['Least Squares']),
('Date:', None),
('Time:', None)
]
top_right = [('Pseudo R-squared:', ["%#8.4g" % self.prsquared]),
('Bandwidth:', ["%#8.4g" % self.bandwidth]),
('Sparsity:', ["%#8.4g" % self.sparsity]),
('No. Observations:', None),
('Df Residuals:', None),
('Df Model:', None)
]
if title is None:
title = self.model.__class__.__name__ + ' ' + "Regression Results"
# create summary table instance
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=self.use_t)
# add warnings/notes, added to text format only
etext = []
if eigvals[-1] < 1e-10:
wstr = "The smallest eigenvalue is %6.3g. This might indicate "
wstr += "that there are\n"
wstr += "strong multicollinearity problems or that the design "
wstr += "matrix is singular."
wstr = wstr % eigvals[-1]
etext.append(wstr)
elif condno > 1000: # TODO: what is recommended
wstr = "The condition number is large, %6.3g. This might "
wstr += "indicate that there are\n"
wstr += "strong multicollinearity or other numerical "
wstr += "problems."
wstr = wstr % condno
etext.append(wstr)
if etext:
smry.add_extra_txt(etext)
return smry
示例10: summary
# 需要导入模块: from statsmodels.iolib.summary import Summary [as 别名]
# 或者: from statsmodels.iolib.summary.Summary import add_extra_txt [as 别名]
#.........这里部分代码省略.........
summary : Summary instance
Object that contains tables and facilitated export to text, html or
latex
"""
# Summary layout
# 1. Overall information
# 2. Mean parameters
# 3. Volatility parameters
# 4. Distribution parameters
# 5. Notes
model = self.model
model_name = model.name + " - " + model.volatility.name
# Summary Header
top_left = [
("Dep. Variable:", self._dep_name),
("Mean Model:", model.name),
("Vol Model:", model.volatility.name),
("Distribution:", model.distribution.name),
("Method:", "User-specified Parameters"),
("", ""),
("Date:", self._datetime.strftime("%a, %b %d %Y")),
("Time:", self._datetime.strftime("%H:%M:%S")),
]
top_right = [
("R-squared:", "--"),
("Adj. R-squared:", "--"),
("Log-Likelihood:", "%#10.6g" % self.loglikelihood),
("AIC:", "%#10.6g" % self.aic),
("BIC:", "%#10.6g" % self.bic),
("No. Observations:", self._nobs),
("", ""),
("", ""),
]
title = model_name + " Model Results"
stubs = []
vals = []
for stub, val in top_left:
stubs.append(stub)
vals.append([val])
table = SimpleTable(vals, txt_fmt=fmt_2cols, title=title, stubs=stubs)
# create summary table instance
smry = Summary()
# Top Table
# Parameter table
fmt = fmt_2cols
fmt["data_fmts"][1] = "%18s"
top_right = [("%-21s" % (" " + k), v) for k, v in top_right]
stubs = []
vals = []
for stub, val in top_right:
stubs.append(stub)
vals.append([val])
table.extend_right(SimpleTable(vals, stubs=stubs))
smry.tables.append(table)
stubs = self._names
header = ["coef"]
vals = (self.params,)
formats = [(10, 4)]
pos = 0
param_table_data = []
for _ in range(len(vals[0])):
row = []
for i, val in enumerate(vals):
if isinstance(val[pos], np.float64):
converted = format_float_fixed(val[pos], *formats[i])
else:
converted = val[pos]
row.append(converted)
pos += 1
param_table_data.append(row)
mc = self.model.num_params
vc = self.model.volatility.num_params
dc = self.model.distribution.num_params
counts = (mc, vc, dc)
titles = ("Mean Model", "Volatility Model", "Distribution")
total = 0
for title, count in zip(titles, counts):
if count == 0:
continue
table_data = param_table_data[total : total + count]
table_stubs = stubs[total : total + count]
total += count
table = SimpleTable(table_data, stubs=table_stubs, txt_fmt=fmt_params, headers=header, title=title)
smry.tables.append(table)
extra_text = (
"Results generated with user-specified parameters.",
"Since the model was not estimated, there are no std. " "errors.",
)
smry.add_extra_txt(extra_text)
return smry