zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python prophet 预言家预知未来

Python 未来
2023-09-14 09:09:29 时间

fbprophet 必须安装在Python3.5以上,目前来讲是的
ubuntu16 安装如下:

  1. 安装anaconada
  2. 通过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()

这里写图片描述
代码下载