python prophet 预言家预知未来
fbprophet 必须安装在Python3.5以上,目前来讲是的
ubuntu16 安装如下:
- 安装anaconada
- 通过pip 安装各种库
conda install gcc
conda install -c conda-forge fbprophet.
import pandas as pd
import numpy as np
from fbprophet import Prophet
import matplotlib.pyplot as plt
# 数据文件请从github上的Prophet项目下载,并放在代码的对应目录
df = pd.read_csv('examples/example_wp_peyton_manning.csv')
df['y'] = np.log(df['y'])
print (df.tail())
# 定义模型
m = Prophet()
# 训练模型
m.fit(df)
# 构建预测集
future = m.make_future_dataframe(periods=365)
print (future.tail())
# 进行预测
forecast = m.predict(future)
print (forecast.tail(10))
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(10)
m.plot(forecast)
plt.show()

浙公网安备 33010602011771号