在Python中为先知模型计算RMSE

时间:2018-06-27 12:51:35

标签: python time-series statsmodels facebook-prophet forecast

我不熟悉python,并且正在创建一个时间序列模型,该模型使用Prophet模型预测每月的总销售额。我需要获得我的模型的RMSE的帮助!谢谢!

from fbprophet import Prophet
#Creating Dataframe#
proph = train.groupby(['date_block_num'])[ 'item_cnt_day'].sum()
proph.index=pd.date_range(start='2013-01-01', end='2015-10-01', freq='MS')
proph = proph.to_frame().reset_index()
proph.columns = ['ds', 'y']
proph.head()
#Modelling#
model=Prophet(yearly_seasonality=True)
model.fit(proph)
model.head()
#Making future predictions
future_data = model.make_future_dataframe(periods=1, freq='MS')
forecast = model.predict(future_data)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()

1 个答案:

答案 0 :(得分:0)

我不知道它是否仍然有用。您将需要准备一个保存实际值的DataFrame,将其称为df_actual。然后,以下内容将为您计算RMSE:

se = np.square(forecast.loc[:, 'yhat'] - df_actual)
mse = np.mean(se)
rmse = np.sqrt(mse)

希望这会有所帮助。

相关问题