1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- """
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2024/07/03
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc :
- """
- import pandas as pd
- from prophet import Prophet
- import matplotlib.pyplot as plt
- # 创建示例数据
- data = {
- 'ds': pd.date_range(start='2022-01-01', periods=365, freq='D'),
- 'y': [x + (x * 0.1) for x in range(365)]
- }
- df = pd.DataFrame(data)
- # 创建 Prophet 模型实例
- model = Prophet()
- # 训练模型
- model.fit(df)
- # 创建未来日期数据框架
- future = model.make_future_dataframe(periods=30) # 预测未来 30 天
- # 进行预测
- forecast = model.predict(future)
- # 绘制预测结果
- fig1 = model.plot(forecast)
- plt.show()
- # 绘制预测成分(趋势、周效应、年效应等)
- fig2 = model.plot_components(forecast)
- plt.show()
- if __name__=='__main__':
- pass
|