Prophet是由Facebook开发的强大的时间序列预测工具,适合处理具有季节性节假日效应趋势的数据。以下是使用Prophet进行预测的核心步骤:


1. 环境准备

  • 安装Python库:

    pip install prophet
    
    Prophet_logo
  • 数据要求:
    需要包含ds(日期)和y(目标值)两列,示例格式:

    ds y
    2023-01-01 120
    2023-01-02 135

2. 核心流程

  1. 加载数据
    from pandas import read_csv
    df = read_csv("data.csv")
    
  2. 初始化模型
    from prophet import Prophet
    model = Prophet()
    
  3. 拟合训练
    model.fit(df)
    
  4. 未来预测
    future = model.make_future_dataframe(periods=365)
    forecast = model.predict(future)
    
  5. 可视化结果
    时间序列预测图表

3. 高级功能

  • 添加节假日
    model.add_country_holidays(country_code='CN')
    
  • 自定义趋势
    通过growth参数选择线性或分段线性趋势
  • 季节性调整
    使用seasonality_mode控制季节性强度(additive/multiplicative

4. 扩展学习

如需了解其他时间序列模型,可访问:
/ai_tutorials_machine_learning/time_series_prediction_arima_tutorial


5. 注意事项

✅ Prophet适合中短期预测(如周/月级)
⚠️ 需确保数据无缺失且时间戳连续
💡 可结合plot_components分析趋势/季节性分解

Prophet模型结构