我尝试使用ANN使用不同的输入和参数预测未来10分钟的功耗。数据库每10分钟记录26000多个样本。下图是数据库的一部分
Date_time Consumption
0 2016-10-01 00:00:00 2781
1 2016-10-01 00:10:00 3729
2 2016-10-01 00:20:00 3357
3 2016-10-01 00:30:00 2609
4 2016-10-01 00:40:00 3025
为了预测“t”,我将其用作输入:
我使用pandas shift函数创建带有滞后特征的新列,然后删除NaN值。我将20%的数据设置为测试集,然后应用MinMaxScaler转换特性
对于每个输入配置,我都进行了网格搜索,以找到最佳参数。下面的代码显示了用于安装模型的功能
def model_fit(train_x, train_y, model_config):
# reset keras
clear_session()
# model_config contains the parameters of the model
n_layers, n_nodes, activation, n_batch = model_config
model = Sequential()
# the shape of the input layer is given by the number of features
model.add(InputLayer(input_shape=(train_x.shape[1], )))
# model.add(Dropout(0.2))
for layers in range(n_layers):
model.add(Dense(n_nodes,
activation=activation
)
)
model.add(Dense(1))
model.compile(loss='mse', optimizer=Adam(0.01), metrics=['mse', 'mae'])
model.summary()
earlystop = EarlyStopping(monitor='val_mse')
# 15% of the training set will be used to validate the model
model.fit(train_x,
train_y,
validation_split=0.15,
callbacks = [earlystop],
epochs=1500,
batch_size=n_batch,
shuffle=False,
verbose=1
)
return model
在尝试了几个参数组合后,我发现配置3的效果最好
MODEL CONFIGURATION: (n_layers=1, n_nodes=48, activation='relu', n_batch=50)
Training RMSE: 429.3599853515625
Validation RMSE: 223.30999755859375
Training MAE: 271.6600036621094
Validation MAE: 159.44000244140625
Test RMSE: 227.69
Test MAE: 167.88
上述结果表明,人工神经网络只是利用“t-1”来预测“t”。然而,通过查看第一个图中的模式,在我看来,该模型可以做得更好。我发现了一些类似的问题,我已经尝试了一些建议。使用辍学时,移位/延迟预测问题似乎消失了(下图)。我还尝试使用时间(用余弦和正弦转换为周期)作为输入。然而,结果更糟,现在我真的不知道还能做什么
===================================================================================================
在使用整个数据库之前,我尝试用一个较小的数据库开发一个模型,该数据库每小时都有测量数据,而且运行得非常好。输入为时间(用余弦和正弦转换)、最后一个周期(t-1)和最后一天的消耗量(t-24)。下图显示了结果
MODEL CONFIGURATION: (n_layers=1, n_nodes=48, activation='tanh', n_batch=50)
MODEL RMSE: 354.76
MODEL MAE: 283.97
目前没有回答
相关问题 更多 >
编程相关推荐