我使用facebook prophet预测库来模拟未来的价格,我可以得到明年的所有数据,但明天的价格会被卡住。
这是预测代码:
m = Prophet(
seasonality_mode="multiplicative",
yearly_seasonality=True
)
m.fit(df_crypto_market_chart_exploded)
future = m.make_future_dataframe(periods = 365)
forecast = m.predict(future)
forecast_result_tail = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
# print('\n--- selected: FORECAST RESULT TAIL ---')
# print(forecast_result_tail)
forecast_result_head = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].head()
print('\n--- selected: FORECAST RESULT HEAD ---')
print(forecast_result_head)
next_day = (datetime.today() + timedelta(days=3)).strftime('%Y-%m-%d')
print('\n--- selected: FORECAST DS TYPE ---')
print(forecast['ds'].dtype)
tomorrow_result = forecast['ds'].dt.date == datetime.today() + timedelta(days=1)
print('\n--- selected: TOMORROW RESULTS ---')
print(tomorrow_result.head())
forecast[tomorrow_result]['yhat'].item()
**编辑-**我根据建议的解决方案修改了代码,但仍然遇到下面列出的numpy错误
--- selected: FORECAST RESULT HEAD ---
ds yhat yhat_lower yhat_upper
0 2017-06-02 00:00:00.000 2359.464229 605.624033 4037.385324
1 2017-06-03 00:00:00.000 2371.962255 661.690821 4155.470592
2 2017-06-04 00:00:00.000 2382.640816 683.686292 4249.680911
3 2017-06-05 00:00:00.000 2387.433948 570.835239 4240.934785
4 2017-06-06 23:29:55.701 2226.178108 344.391258 4062.279165
--- selected: FORECAST DS TYPE ---
datetime64[ns]
--- selected: TOMORROW RESULTS ---
0 False
1 False
2 False
3 False
4 False
Name: ds, dtype: bool
Traceback (most recent call last):
File "d:/Projects/price_prediction.py", line 69, in <module>
forecast[tomorrow_result]['yhat'].item()
File "C:\Users\abc\anaconda3\envs\venv\lib\site-packages\pandas\core\base.py", line 331, in item
raise ValueError("can only convert an array of size 1 to a Python scalar")
ValueError: can only convert an array of size 1 to a Python scalar
1条答案
按热度按时间vyu0f0g11#
pandas.dataframe
可以保持ds
作为datetime
对象,也可以进行比较hours, minutes, seconds
.使用
.strftime()
也不会起作用,因为它可能不会比较datetime
具有string
-但如果它能够比较它们,那么它仍然会使用hours, minutes, seconds
对于中的值ds
.您可能需要使用
.dt.date
对于dataframe
及.date()
单身datetime
只比较日期。最小示例
结果:
编辑:
其他例子