main.py 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/07/03
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc :
  8. """
  9. import pandas as pd
  10. from prophet import Prophet
  11. import matplotlib.pyplot as plt
  12. # 创建示例数据
  13. data = {
  14. 'ds': pd.date_range(start='2022-01-01', periods=365, freq='D'),
  15. 'y': [x + (x * 0.1) for x in range(365)]
  16. }
  17. df = pd.DataFrame(data)
  18. # 创建 Prophet 模型实例
  19. model = Prophet()
  20. # 训练模型
  21. model.fit(df)
  22. # 创建未来日期数据框架
  23. future = model.make_future_dataframe(periods=30) # 预测未来 30 天
  24. # 进行预测
  25. forecast = model.predict(future)
  26. # 绘制预测结果
  27. fig1 = model.plot(forecast)
  28. plt.show()
  29. # 绘制预测成分(趋势、周效应、年效应等)
  30. fig2 = model.plot_components(forecast)
  31. plt.show()
  32. if __name__=='__main__':
  33. pass