未完待續
from fbprophet import Prophet
model_fbp = Prophet()
for feature in features:
model_fbp.add_regressor(feature)
model_fbp.fit(df_train[["date", "y"] + features].rename(columns={"date": "ds", "y": "y"}))
forecast = model_fbp.predict(df_valid[["date", "y"] + features].rename(columns={"date": "ds"}))
df_valid["Forecast_Prophet"] = forecast.yhat.values
from sklearn.metrics import mean_absolute_error, mean_squared_error
fig = go.Figure()
fig.add_trace(go.Scatter(x=df_valid.date, y=df_valid.y, name='close'))
fig.add_trace(go.Scatter(x=df_valid.date, y=df_valid.Forecast_ARIMAX, name='Forecast_ARIMAX'))
fig.add_trace(go.Scatter(x=df_valid.date, y=df_valid.Forecast_Prophet, name='Forecast_Prophet'))
fig.show()
print("RMSE of Auto ARIMAX:", np.sqrt(mean_squared_error(df_valid.y, df_valid.Forecast_ARIMAX)))
print("RMSE of Prophet:", np.sqrt(mean_squared_error(df_valid.y, df_valid.Forecast_Prophet)))
print("\nMAE of Auto ARIMAX:", mean_absolute_error(df_valid.y, df_valid.Forecast_ARIMAX))
print("MAE of Prophet:", mean_absolute_error(df_valid.y, df_valid.Forecast_Prophet))