# 参数设置
LSTM_train_days = 900  # 预测的输出从 LSTM_train_days+30 开始
LSTM_learn_days = 30  # 学习的天数
LSTM_pred_days = 15  # 预测的天数,一旦修改,需对应修改series_to_supervised()结果删除的列数
LSTM_test_days = 801  # 测试集从此开始
# 设置plt格式
sns.set_style("white")
# 读取数据集导入数据
df = pd.read_excel('.\\data\\gas_load.xlsx')
# 异常数据直接剔除
df.gas_use[601] = (df.gas_use[600] + df.gas_use[602]) / 2
df.gas_use[614] = (df.gas_use[613] + df.gas_use[615]) / 2
# 节假日数据生成
holidays = holidays_generate()
date_property = date_property_generate(holidays)
# date_property数据处理,并加入休息日
date_property.ix[date_property.is_holiday == 1, 'is_holiday'] = 15
date_property.ix[df.is_holiday == 1, 'is_holiday'] = 1
############################################### BP神经网络回归 #####################################################
# 训练数据归一化
train_X = df.ave_temp
train_X = pd.concat((train_X, date_property.is_holiday), axis=1)
train_y = df.gas_use
train_data = pd.concat((train_X, train_y), axis=1)
scaler1 = MinMaxScaler(feature_range=(0, 1))
train_scaled = scaler1.fit_transform(train_data)
train_scaled = pd.DataFrame(train_scaled)  # 转换为 DataFrame 格式
# 预测数据归一化
test_X = df.ave_temp
Beispiel #2
0
result_hg = pd.DataFrame(columns=('ds', 'is_holiday', 'ave_temp', 'y', 'y_hg', 'err_hg', 'err_rate_hg', 'tmp_err_hg'))
result_hg.ds = df.date_time
result_hg.is_holiday = df.is_holiday
result_hg.ave_temp = df.ave_temp
result_hg.y = df.gas_use
result_hg.y_hg = (y_pred_all[:, 0] - 0.15)/0.7 * (y_data_max-y_data_min) + y_data_min
result_hg.err_hg = result_hg.y_hg - result_hg.y    # 预测-实际
result_hg.err_rate_hg = abs(result_hg.err_hg / result_hg.y)
result_hg.tmp_err_hg = result_hg.err_hg / 500000
hg_err_mean = result_hg.err_rate_hg.mean()


# prophet预测部分
result_fb = pd.DataFrame(columns=('ds', 'err_hg_input', 'err_hg_fb_output', 'err_fb', 'err_rate_fb', 'is_holiday', 'ave_temp', 'y', 'y_zh', 'err_zh', 'err_rate_zh'))
# 节假日生成
holidays = holiday_def.holidays_generate()

# 一次预测30天,循环预测验证7轮
for i in range(1):
    new_method1 = pd.DataFrame(columns=('ds', 'y'))
    tmp_method1 = result_hg[0:752+15*i]
    new_method1.ds = tmp_method1.ds
    new_method1.y = tmp_method1.tmp_err_hg
    prophet = Prophet(holidays=holidays)
    prophet.fit(new_method1)
    future = prophet.make_future_dataframe(freq='D', periods=15)
    forecasts = prophet.predict(future)
    # forecasts[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
    # prophet.plot(forecasts)
    # prophet.plot_components(forecasts)