如何用批处理规范化方法规范化Keras中的LSTM输入数据

2024-04-25 08:57:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我的神经网络构造如下:

tempIn = Input(shape = (None, 4))
tempModel = LSTM(data.xRnnLosFeatures)(tempIn)
tempModel = BatchNormalization()(tempModel)
tempModel = Activation('tanh')(tempModel)
tempModel = Dropout(0.5)(tempModel)
tempModel = Dense(1)(tempModel)
model = Model(inputs=tempIn, outputs=tempModel)

但是,如果我不在给这个网络输入数据之前手动规范化我的输入数据,就会一直得到一个非常大的错误。什么是正确规范输入数据的方法。我试图在LSTM层之前再加一个,但没用。谢谢!在


Tags: 数据noneinputdata神经网络activationdropoutdense
2条回答
from sklearn.preprocessing import MinMaxScaler

scalerx = MinMaxScaler( feature_range=(0, 1) )  # To normalize the inputs
scalery = MinMaxScaler( feature_range=(0, 1) )  # To normalize the outputs

datax = scalerx.fit_transform( data['inputs'] ) # Assuming a dictionary with inputs
datay = scalerx.fit_transform( data['outputs'] ) # and outputs

model.fit( datax, datay )

运行模型后,您将获得范围[0,1]的值,您需要恢复规范化以理解它们:

^{pr2}$

并且y_hat_denorm从一开始就有相同的单元,即来自data['outputs']的单元,用于创建scalery。在

您可以使用kerasnormalise函数,或者也可以使用scikit learnpreprocessing函数。在

相关问题 更多 >