【发布时间】:2017-11-26 08:18:57
【问题描述】:
我想运行一个滚动 1000 个窗口 OLS regression estimation 的数据集,以便在以下 URL 找到我的评估:
https://drive.google.com/open?id=0B2Iv8dfU4fTUa3dPYW5tejA0bzg
我尝试使用以下Python 脚本和pandas 版本0.20.2。
# /usr/bin/python -tt
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from statsmodels.formula.api import ols
df = pd.read_csv('estimated.csv', names=('x','y'))
model = pd.stats.ols.MovingOLS(y=df.Y, x=df[['y']],
window_type='rolling', window=1000, intercept=True)
df['Y_hat'] = model.y_predict
但是,当我运行 Python 脚本时,我收到此错误:AttributeError: module 'pandas.stats' has no attribute 'ols'。我发现这个错误的原因是因为它在Pandas版本0.20.0之后被删除,我们可以从以下链接中看到它。
https://github.com/pandas-dev/pandas/pull/11898
我们如何使用最新版本的 Pandas 做OLS Regression?
【问题讨论】:
标签: python python-3.x pandas numpy linear-regression