- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我安装 statsmodels:
apt-get install python python-dev python-setuptools python-numpy python-scipy
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
pip install pandas
pip install cython
pip install patsy
pip install statsmodels
一切安装顺利完成。pip 安装包的位置是/usr/local/lib/python2.7/dist-packages,这样可以吗?因为其他Python包安装在/usr/lib/python2.7/dist-packages中。
当我在 Ipython Qt 控制台中运行此脚本时:
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
from statsmodels.stats.outliers_influence import summary_table
x = np.linspace(0, 10, 100);
e = np.random.normal(size=100)
y = 1 + 0.5*x + 2*e
X = sm.add_constant(x)
re = sm.OLS(y, X).fit()
print re.summary()
st, data, ss2 = summary_table(re, alpha=0.05)
fittedvalues = data[:,2]
predict_mean_se = data[:,3]
predict_mean_ci_low, predict_mean_ci_upp = data[:,4:6].T
predict_ci_low, predict_ci_upp = data[:,6:8].T
我收到此错误:
NameError Traceback (most recent call last)
<ipython-input-9-cee9c1b1867d> in <module>()
12 print re.summary()
13
---> 14 st, data, ss2 = summary_table(re, alpha=0.05)
15
16 fittedvalues = data[:,2]
/usr/local/lib/python2.7/dist-packages/statsmodels/stats/outliers_influence.pyc in summary_table(res, alpha)
689 from statsmodels.sandbox.regression.predstd import wls_prediction_std
690
--> 691 infl = Influence(res)
692
693 #standard error for predicted mean
NameError: global name 'Influence' is not defined
我使用 Linux Mint Mate 15
最佳答案
我不是 100% 确定问题是什么,但我确实知道示例中有问题的代码行在当前版本的 statsmodels 中是不同的:
infl = OLSInfluence(res)
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/outliers_influence.py#L689
statsmodels 0.5.0
的候选版本即将发布,并且 github master 相当稳定,因此我建议从 github 安装新版本:
https://github.com/statsmodels/statsmodels
我在我的机器上运行了你的示例,一切正常。
关于Python:不工作 StatsModels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17663966/
是否有 statsmodels API 可以从 statsmodels 时间序列模型中检索预测区间? 目前,我正在使用以下方法手动计算预测区间: 这是我的代码。首先,获取一些示例数据... ! pyt
我有:statsmodels 0.5.0(正式名称为 scikits.statsmodels) Pandas 0.12.0。(全部从源安装) 我收到这个错误: File "/home/userna
所有内容的格式都与 Statsmodels 网站上的一样,但是 Spyder 以某种方式返回了这个: TypeError: ztest_ind() got multiple values for ar
所有内容的格式都与 Statsmodels 网站上的一样,但是 Spyder 以某种方式返回了这个: TypeError: ztest_ind() got multiple values for ar
谁能给我解释一下 statsmodel.formula.api 中的 ols 和 statsmodel.api 中的 ols 之间的区别? 使用 ISLR 文本中的广告数据,我使用两者运行了一个 ol
我用python处理一个线性回归模型,json数据如下: {"Y":[1,2,3,4,5],"X":[[1,43,23],[2,3,43],[3,23,334],[4,43,23],[232,234,
我正在使用 Python 中的 statsmodels MixedLM 包估计一个混合线性模型。拟合模型后,我现在想进行预测,但很难理解“预测”方法。 statsmodels 文档 (http://w
使用状态模型的逻辑回归模型: log_reg = st.logit(formula = 'label ~ pregnant + glucose + bp + insulin + bmi + pedig
我有一个包含 3 列的数据框 ['X', 'Y', 'Z'] 我想研究一下 X 和 Y影响Z的分布。为此,我想使用 nadaraya watson 的非参数回归器。在 statsmodels 中有一个
我正在尝试使用 statsmodel 中的 statsmodels.discrete.conditional_models.ConditionalLogit 类。 在jupyter笔记本中导入模块时,
我安装 statsmodels: apt-get install python python-dev python-setuptools python-numpy python-scipy curl
import statsmodels.formula.api as sm import numpy as np import pandas url = "http://vincentarelbundo
我正在尝试在 x-y 数据的简单测试集上使用 statsmodels 中的稳健线性模型。然而,作为 model.params 的返回值,我只得到一个值。如何获得拟合的斜率和截距?最小示例(其中我试图从
我正在使用库statsmodels.tsa.stattools.grangercausalitytests来测试两个时间序列之间的相似性。我知道列表 a 和 b 都是合法列表,没有任何 None 或
以下代码使用 statsmodels 拟合了一个过度简化的广义线性模型 model = smf.glm('Y ~ 1', family=sm.families.NegativeBinomial(),
在Python库Statsmodels中,可以用print(results.summary())打印出回归结果,如何打印出超过的摘要一张表中的一个回归,以便更好地比较? 线性回归,代码取自 stats
我有一个 pandas DataFrame,其行包含多种类型的数据。我想使用 statsmodels.formula.api 根据这些数据拟合一个模型,然后做出一些预测。对于我的应用程序,我想一次预测
我正在尝试使用 statsmodels 中的 logit 模块对包含 bool 值(“默认”)目标变量和两个特征(“fico_interp”、“home_ownership_int”)的数据集执行逻辑
这个问题类似于confidence and prediction intervals with StatsModels但有一个额外的细微差别: 我的数据是异方差的,我想使用 statsmodels 提
我正在使用 Pandas 的混合物和 StatsModels绘制时间序列分解图。我关注了this answer但是当我调用 plot() 时,它似乎在绘制一个副本。 我的 DataFrame 看起来像
我是一名优秀的程序员,十分优秀!