python fbprophet 初级 使用
发布日期:2021-05-07 10:27:24 浏览次数:13 分类:精选文章

本文共 1580 字,大约阅读时间需要 5 分钟。

"""# 1 安装Prophet# python: 3.7.9# pystan: 2.19.0.0# pandas# fbprophet: 0.6.0# anaconda方式:# conda install pystan=2.19.0.0# conda install -c conda-forge fbprophet=0.6.0# 3 Prophet介绍# https://www.cnblogs.com/bonelee/p/9577432.html# https://facebook.github.io/prophet/docs/quick_start.html# 可以预测数据,也可以给出趋势。时间序列预测上,充满专家经验:周期趋势、离群点、突变点、突变。# 4 时间跨度# make_future_dataframe中的fre是Offset aliases形式的,用的pandas时间跨度# https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases# 比如1hour1min可以表示时间跨度是61分钟"""import datetimefrom fbprophet import Prophetimport pandas as pdimport matplotlib.pyplot as pltimport mathdef get_all_time_stamp(num):    """    :return:    """    starttime = datetime.datetime(2020, 1, 1, 0, 0, 0)    deltatime = datetime.timedelta(hours=1)    time_list = []    cnt = 0    while 1:        if cnt >= num:            break        else:            time_list.append(starttime)            starttime += deltatime            cnt += 1    return time_listts = get_all_time_stamp(1000)value_list = [100 * math.sin(i) for i in range(1000)]data_df = pd.DataFrame({   'date_time': ts, 'value': value_list})data_df.columns = ['ds', 'y']data_df['ds'] = data_df['ds'].astype('datetime64[ns]')m = Prophet()m.fit(data_df)  # 训练模型mfuture = m.make_future_dataframe(periods=50, freq='H')  # 预测的设置 还没预测forecast = m.predict(future)  # 开始预测print(forecast.to_string())  # 预测结果显示# fig1 = m.plot(forecast)  #预测结果绘图plt.plot(forecast['ds'][950:1000], forecast['yhat'][950:1000], color='b')plt.plot(forecast['ds'][1000:], forecast['yhat'][1000:], color='r')plt.show()
上一篇:collections.defaultdict() dict 区别 使用 dict.get() python 使用场景
下一篇:python 数据挖掘 关联规则挖掘 实践 Apriori FP-Tree mlxtend

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年04月12日 01时08分05秒