gpt4 book ai didi

Python:不工作 StatsModels

转载 作者:行者123 更新时间:2023-12-01 05:40:29 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com