【发布时间】:2019-04-10 20:20:50
【问题描述】:
我正在尝试预测第二天的现货价格的时间序列数据。我的数据看起来像:
我在 f_area 上进行了 groupby,最终得到了 multiindex。现在我正在尝试使用 RandomForestRegressor 进行预测。
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
y = area3['y'].values
X = area3[['f_price', 'day_of_week', 'day_of_month']]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
model = RandomForestRegressor()
model = model.fit(X_train, y_train)
y_pred = model.predict(X_test)
现在,当我尝试绘制 y_test(实际值)和 y_pred(预测值)时
fig, ax = plt.subplots()
ax.plot(y_test)
ax.plot(y_pred)
我想要的是在 X 轴上有日期,但由于多索引,我无法这样做。我该如何执行此操作或删除多索引?我试图通过 reset_index 删除多索引,但在我的情况下它不起作用谢谢
【问题讨论】:
标签: python pandas matplotlib time-series pandas-groupby