简体   繁体   中英

Python: Don't work StatsModels

I install 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

All the installation finish ok. The location of packages to install wich pip is /usr/local/lib/python2.7/dist-packages, this is ok? because the other python packages are installed in /usr/lib/python2.7/dist-packages.

When I run this scrip in Ipython Qt console:

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

I get this error:

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

I use Linux Mint Mate 15

I'm not 100% sure what the problem is, but I do know that the problematic line of code in your example is different in the current version of statsmodels:

infl = OLSInfluence(res)

https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/outliers_influence.py#L689

The release candidate of statsmodels 0.5.0 is about to be released and github master is quite stable, so I recommend installing the new version from github:

https://github.com/statsmodels/statsmodels

I ran your example on my machine and everything worked fine.

All I could find was this github issue on the statsmodels repository. Perhaps the version you downloaded with pip is older than the patch?

The following installation worked for a 32-bit Python2.7 on Windows

First, you install and download the zip-file containing the module here and unpack it.

Following, in command line, change directory to the statsmodule directory, and then type: D:\\path\\statsmodels-0.8.0rc1> py setup.py install

You may need to download and install Visual C++ 2015 , before it works though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM