1

我正在建立一个 sarimax 模型来预测从 2021 年 4 月起的乘客数量。目前我正在使用 2021 年 1 月 1 日至 2021 年 1 月 31 日的数据,如下所示

如何编写代码以便预测 2021 年 4 月 1 日以后的未来数据?谢谢

#Code 1


date_forecast = "2021-3-21" #between Mar 16 - 31 (## User will key in the date)
holiday = 1

weekend = int(((pd.to_datetime(date_forecast).dayofweek)//5==1))
print('Weekend:',weekend)
print('Holiday:',holiday)

#Code 2

ridership_df2 = get_busstops_guests_hourly(ridership_df)
ridership_df2['Date'] = ridership_df2['Open Timestamp'].dt.date
ridership_df2['Date'] = pd.to_datetime(ridership_df2['Date'])
ridership_df2 = pd.merge(ridership_df2,df_holiday,how='inner',on='Date')

#Code 3

estimated_guest = pred_sarimax[date_forecast]
bus_forecast = get_busstops_guests_hourly_distribution (ridership_df2,bus_route,weekend,holiday)
print('On',date_forecast,'the Total Estimated Guest for',bus_route,':',round(estimated_guest))

#Code 4

bus_forecast = bus_forecast.reset_index()
bus_forecast['Weight'] = bus_forecast['Upper_bound'].div(bus_forecast['Upper_bound'].sum())
bus_forecast['Prediction'] = (bus_forecast['Weight']*estimated_guest).round(0)

#Code 5

bus_forecast.loc[bus_forecast ['Prediction']>50]

This will give you the output as shown in this image

#This is output在此处输入图像描述

4

0 回答 0