1

我一直在尝试 facebook 的预测包,名为先知。即使我设置了代码、示例数据和包,结果似乎也失败了。这是代码和数据。

import pandas as pd
from fbprophet import Prophet

# Python
df = pd.read_csv('./test.csv')
df.head()

m = Prophet(yearly_seasonality=True, daily_seasonality=True)
m.fit(df)

future = m.make_future_dataframe(periods=365)
future.tail()

forecast = m.predict(future)
forecast.head()
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()

数据(test.csv)

,ds,y
0,2021-12-10,1
1,2021-12-11,0
2,2021-12-12,0
3,2021-12-13,1
4,2021-12-14,1
5,2021-12-15,2
6,2021-12-16,5
7,2021-12-17,0
8,2021-12-18,0
9,2021-12-19,0
10,2021-12-20,1

当我运行时,结果是这样的。

$ python3 predict.py
INFO:fbprophet:Disabling weekly seasonality. Run prophet with weekly_seasonality=True to override this.
INFO:fbprophet:n_changepoints greater than number of observations. Using 7.

Initial log joint probability = -91.9162
Iteration  1. Log joint probability =  -0.202158. Improved by 91.7141.
Iteration  2. Log joint probability =    4.48295. Improved by 4.68511.
Iteration  3. Log joint probability =    4.69649. Improved by 0.213543.
Iteration  4. Log joint probability =    4.77003. Improved by 0.0735347.
Iteration  5. Log joint probability =    4.81532. Improved by 0.0452924.
Iteration  6. Log joint probability =    4.92782. Improved by 0.1125.
Iteration  7. Log joint probability =    5.00881. Improved by 0.0809877.
Iteration  8. Log joint probability =    8.77698. Improved by 3.76817.
Iteration  9. Log joint probability =    8.85044. Improved by 0.0734641.
Iteration 10. Log joint probability =     8.9742. Improved by 0.12376.
Iteration 11. Log joint probability =    9.02056. Improved by 0.0463593.

似乎失败了,不是吗?你能告诉我缺少什么吗?

4

1 回答 1

0

我能弄清楚。这些脚本应该在 python 解释器中输入。

$ python3
Python 3.9.9 (main, Nov 21 2021, 03:23:42)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> from fbprophet import Prophet
>>> df = pd.read_csv('./test.csv')
>>> df.head()
...
>>> forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
            ds       yhat  yhat_lower  yhat_upper
0   2021-12-10   0.200457   -1.452398    1.883558
1   2021-12-11   0.522619   -1.137424    2.186004
2   2021-12-12   0.866330   -0.762460    2.496505
3   2021-12-13   1.188542   -0.469879    2.844547
4   2021-12-14   1.448604   -0.222080    3.037287
..         ...        ...         ...         ...
371 2022-12-16 -44.990770  -46.734865  -43.275772
372 2022-12-17 -45.076070  -46.733491  -43.470552
373 2022-12-18 -45.332832  -47.009323  -43.766616
374 2022-12-19 -45.774216  -47.393267  -44.189831
375 2022-12-20 -46.405457  -48.097744  -44.738676

[376 rows x 4 columns]

有用。

于 2022-01-08T11:59:54.020 回答