1

我安装 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

一切安装完成OK。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

4

3 回答 3

2

我不是 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

我在我的机器上运行了你的示例,一切正常。

于 2013-07-16T02:02:52.337 回答
0

我能找到的只是存储库上的这个github 问题statsmodels。也许您下载的版本pip比补丁旧?

于 2013-07-15T21:39:45.747 回答
0

以下安装适用于 Windows 上的 32 位 Python2.7

首先,您在此处安装并下载包含该模块的 zip 文件并将其解压缩。

接下来,在命令行中,将目录更改为 statsmodule 目录,然后键入: D:\path\statsmodels-0.8.0rc1> py setup.py install

您可能需要下载并安装Visual C++ 2015,然后才能正常工作。

于 2016-10-18T07:00:22.250 回答