【发布时间】:2017-11-29 06:28:04
【问题描述】:
对于我的评估,我在this link (https://drive.google.com/drive/folders/0B2Iv8dfU4fTUMVFyYTEtWXlzYkk) 中有一个数据集,格式如下。我数据集中的第三列 (Y) 是我的真实值 - 这就是我想要预测(估计)的值。
time X Y
0.000543 0 10
0.000575 0 10
0.041324 1 10
0.041331 2 10
0.041336 3 10
0.04134 4 10
...
9.987735 55 239
9.987739 56 239
9.987744 57 239
9.987749 58 239
9.987938 59 239
我想运行例如 5 个窗口 OLS regression estimation 的滚动,我已经使用以下脚本进行了尝试。
# /usr/bin/python -tt
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('estimated_pred.csv')
model = pd.stats.ols.MovingOLS(y=df.Y, x=df[['X']],
window_type='rolling', window=5, intercept=True)
df['Y_hat'] = model.y_predict
print(df['Y_hat'])
print (model.summary)
df.plot.scatter(x='X', y='Y', s=0.1)
回归分析总结如下。
-------------------------Summary of Regression Analysis-------------------------
Formula: Y ~ <X> + <intercept>
Number of Observations: 5
Number of Degrees of Freedom: 2
R-squared: -inf
Adj R-squared: -inf
Rmse: 0.0000
F-stat (1, 3): nan, p-value: nan
Degrees of Freedom: model 1, resid 3
-----------------------Summary of Estimated Coefficients------------------------
Variable Coef Std Err t-stat p-value CI 2.5% CI 97.5%
--------------------------------------------------------------------------------
X 0.0000 0.0000 1.97 0.1429 0.0000 0.0000
intercept 239.0000 0.0000 14567091934632472.00 0.0000 239.0000 239.0000
---------------------------------End of Summary---------------------------------
我想在t+1 处对Y 进行反向预测(即根据前一个值预测Y 的下一个值,即通过包括均方误差(MSE)来预测p(Y)t+1 - 对于例如,如果我们查看第 5 行,X 的值为 2,Y 的值为 10。假设预测值 (p(Y)t+1) 为 6,因此 mse 将为 (10-6)^2 . 我们如何使用statsmodels 或scikit-learn 来做到这一点,因为pd.stats.ols.MovingOLS 在Pandas 版本0.20.0 中被删除,因为我找不到任何参考?
【问题讨论】:
标签: python pandas numpy scikit-learn statsmodels