tensorflow - TF CuDNNLSTM 最小值始终高于 0,即使在训练数据为 0 时...就像它被移位了 + 5
问题描述
基本上我已经尝试过这段代码
np.random.seed(7)
dataframe = read_csv('c:/data/suicides.csv', usecols=[1], engine='python')
dataset = dataframe.values
dataset = dataset.astype('float32')
# normalize the dataset
scaler = MinMaxScaler(feature_range=(0, 1))
dataset = scaler.fit_transform(dataset)
# split into train and test sets
train_size = int(len(dataset) * 0.67)
test_size = len(dataset) - train_size
train, test = dataset[0:train_size,:], dataset[train_size:len(dataset),:]
# reshape into X=t and Y=t+1
look_back = 1
trainX, trainY = create_dataset(train, look_back)
testX, testY = create_dataset(test, look_back)
# reshape input to be [samples, time steps, features]
trainX = np.reshape(trainX, (trainX.shape[0], trainX.shape[1], 1))
testX = np.reshape(testX, (testX.shape[0], testX.shape[1], 1))
# Initialising the RNN
#regressor = Sequential()
model = Sequential()
# # In[25]:
# # Adding the first LSTM layer and some Dropout regularisation
model.add(CuDNNLSTM(units = 10, return_sequences = True, input_shape = (trainX.shape[1], 1)))
model.add(Dropout(0.1))
# # In[26]:
# # Adding a second LSTM layer and some Dropout regularisation
model.add(CuDNNLSTM(units = 5, return_sequences = True))
model.add(Dropout(0.1))
# # In[27]:
# # Adding a third LSTM layer and some Dropout regularisation
model.add(CuDNNLSTM(units = 4, return_sequences = True))
model.add(Dropout(0.1))
# # In[28]:
# ## Adding a fourth LSTM layer and some Dropout regularisation
model.add(CuDNNLSTM(units = 2))
model.add(Dropout(0.2))
# # In[29]:
# # Adding the output layer
model.add(Dense(units = 1))
# # In[30]:
# # Compiling the RNN
model.compile(optimizer = 'adam', loss = 'mean_squared_error')
# # In[33]:
# #epoch = [10, 15, 20, 25, 30, 35, 40, 45, 50]
# # Fitting the RNN to the Training set
model.fit(trainX, trainY, epochs = _epoch, batch_size = _batch)
# make predictions
trainPredict = model.predict(trainX)
testPredict = model.predict(testX)
不幸的是,由于某种原因,虽然有很长的时间序列 0,但它不会预测为零。
曾经。训练/测试数据的最小值/最大值从 0 开始,但预测数据的最小值始终为 5-6。价值。
训练/测试数据从 0 - ~ 40
我尝试了不同的设置、时期数、激活、优化器、损失,但总是最小。预测数据的值 > ~ 最大训练值的 15%....
解决方案
由于某种原因,时间序列中大于 1 的批次会产生过高的最小预测。
通过修改批量设置+模型训练设置来解决。
因此,如果您的预测 > 0,则可能是训练设置有问题。
推荐阅读
- javascript - 包不应包含任何带有私钥的 .pem 文件,但包根目录中的 key.pem 文件除外
- assembly - 当您缺少 8086 缺少跳转操作数时会发生什么?
- python - 在进行 pandas 数据透视表操作时没有要聚合的数字类型
- javascript - 在新窗口中单击按钮后执行功能
- mysql - 临时表和行的事件调度程序及其名称
- reactjs - 确保我们没有过度连接的组件
- php - 在其他 php 文件中执行函数
- string - 是否有更有效的方法来搜索数据框的列?
- reactjs - 将日期和时间从一个组件解析到另一个组件
- sql-server - 使用通配符仅选择字符串的一部分(SQL Server)