欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > python:prophet 趋势检测

python:prophet 趋势检测

2025/5/16 18:38:23 来源:https://blog.csdn.net/belldeep/article/details/140758953  浏览:    关键词:python:prophet 趋势检测

参考官方文档:趋势变化点

 prophet 是由 Facebook 开发的针对时间序列数据进行快速预测和分析的开源 Python 库。它适用于具有季节性、节假日效应等特征的时间序列数据。

pip install prophet
  prophet-1.1.5-py3-none-win_amd64.whl (13.3 MB)

pip install plotly
    plotly-5.22.0-py3-none-any.whl 

1. 趋势检验案例

根据官方示例改编的: test_prophet.py

# -*- coding: utf-8 -*-
""" 1. 趋势检验案例 依赖 plotly """
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from prophet import Prophet
from datetime import datetime
# 构造数据集
start = datetime(2021, 10, 1)
end = datetime(2022, 10, 1)
rng = pd.date_range(start, end, freq='W')
data = pd.Series(np.random.randn(len(rng)), index=rng)
data = data.reset_index()
data.columns = ['ds','y']# model
m = Prophet(changepoint_prior_scale=5,yearly_seasonality=False)
# 兼顾异常值,0.8,兼顾80%的异常值;越大兼顾的越多,波动性越大
# 越小越平滑
# Proportion of history in which trend changepoints will be estimated
m.fit(data)
forecast = m.predict(data)# Python
from prophet.plot import add_changepoints_to_plot
fig = m.plot(forecast)
a = add_changepoints_to_plot(fig.gca(), m, forecast)# 找到突变时间线
threshold = 0.01
signif_changepoints = m.changepoints[np.abs(np.nanmean(m.params['delta'], axis=0)) >= threshold] if len(m.changepoints) > 0 else []print(signif_changepoints)

运行 python test_prophet.py 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词